| 827行目: | 827行目: | ||
allow apm_t console_device_t:chr_file { getattr read write }; | allow apm_t console_device_t:chr_file { getattr read write }; | ||
allow apm_t tty_device_t:chr_file { getattr read write }; | allow apm_t tty_device_t:chr_file { getattr read write }; | ||
<br><br> | |||
== 設定例 == | |||
以下に示すようなアプリケーションがあるとする。<br> | |||
<br> | |||
* ホームディレクトリ内のファイルを作成、編集、削除 | |||
* D-BusおよびPolkitを使用して、/etcディレクトリ内のファイルを作成、編集、削除 | |||
* TCP/IP通信を使用して外部ネットワークに接続し、ファイルをダウンロード・アップロード | |||
<br> | |||
このアプリケーションのTEファイルでは、以下に示す設定を行う必要がある。<br> | |||
* ホームディレクトリアクセス | |||
*: <アプリケーション名>_home_tタイプでホームディレクトリ内のファイル管理を許可する。 | |||
* D-Bus / Polkit統合 | |||
*: システムバスへの接続とPolkit認証を通じた権限昇格をサポート | |||
* ネットワークアクセス | |||
*: TCP/IPによる外部接続、HTTP/HTTPS通信、DNS解決を許可 | |||
* セキュリティ分離 | |||
*: 各リソース(ホーム、/etc、一時ファイル、ログ) に個別のタイプを定義して適切に分離 | |||
* ブール値によるカスタマイズ | |||
*: 管理者が動作を調整できるようにチューナブルブール値を提供する。 | |||
* オプショナルポリシー | |||
*: 利用可能な場合のみ適用される追加機能 (X11、GNOME等) | |||
<br> | |||
<syntaxhighlight lang="text"> | |||
policy_module(<アプリケーション名>, 1.0.0) | |||
### 宣言 | |||
# プロセスドメインと実行ファイルタイプ | |||
type <アプリケーション名>_t; | |||
type <アプリケーション名>_exec_t; | |||
domain_type(<アプリケーション名>_t) | |||
domain_entry_file(<アプリケーション名>_t, <アプリケーション名>_exec_t) | |||
# ホームディレクトリ内のアプリケーションデータ | |||
type <アプリケーション名>_home_t; | |||
userdom_user_home_content(<アプリケーション名>_home_t) | |||
# 一時ファイル用タイプ | |||
type <アプリケーション名>_tmp_t; | |||
files_tmp_file(<アプリケーション名>_tmp_t) | |||
# /etcディレクトリ内の設定ファイル用タイプ | |||
type <アプリケーション名>_etc_t; | |||
files_config_file(<アプリケーション名>_etc_t) | |||
# ダウンロード/アップロード用の一時保存領域 | |||
type <アプリケーション名>_var_lib_t; | |||
files_type(<アプリケーション名>_var_lib_t) | |||
# ログファイル用タイプ | |||
type <アプリケーション名>_log_t; | |||
logging_log_file(<アプリケーション名>_log_t) | |||
### <アプリケーション名> ローカルポリシー | |||
# 基本的なプロセス権限 | |||
allow <アプリケーション名>_t self:process { signal_perms getsched setsched }; | |||
allow <アプリケーション名>_t self:fifo_file rw_fifo_file_perms; | |||
allow <アプリケーション名>_t self:unix_stream_socket create_stream_socket_perms; | |||
### ホームディレクトリへのアクセス (一般ユーザ権限) | |||
# ホームディレクトリの検索と読み取り | |||
userdom_search_user_home_dirs(<アプリケーション名>_t) | |||
userdom_list_user_home_dirs(<アプリケーション名>_t) | |||
# アプリケーションデータディレクトリの管理 | |||
allow <アプリケーション名>_t <アプリケーション名>_home_t:dir manage_dir_perms; | |||
allow <アプリケーション名>_t <アプリケーション名>_home_t:file manage_file_perms; | |||
allow <アプリケーション名>_t <アプリケーション名>_home_t:lnk_file manage_lnk_file_perms; | |||
# ホームディレクトリからの遷移 | |||
userdom_user_home_dir_filetrans(<アプリケーション名>_t, <アプリケーション名>_home_t, dir, ".<アプリケーション名>") | |||
userdom_user_home_dir_filetrans(<アプリケーション名>_t, <アプリケーション名>_home_t, file, ".<アプリケーション名>rc") | |||
# 一般的なユーザファイルへの読み取りアクセス (必要に応じて) | |||
userdom_read_user_home_content_files(<アプリケーション名>_t) | |||
userdom_write_user_tmp_files(<アプリケーション名>_t) | |||
### /etcディレクトリへのアクセス (D-Bus / Polkit経由) | |||
# D-Busへの接続 | |||
dbus_system_bus_client(<アプリケーション名>_t) | |||
dbus_connect_system_bus(<アプリケーション名>_t) | |||
# Polkitとの通信 | |||
optional_policy(` | |||
polkit_dbus_chat(<アプリケーション名>_t) | |||
polkit_domtrans_auth(<アプリケーション名>_t) | |||
') | |||
# /etcディレクトリ内のファイル管理 | |||
# 注意 : 実際にはPolkit経由で権限昇格されたプロセスが操作を行うため、直接的なアクセス権限は最小限に抑える | |||
files_search_etc(<アプリケーション名>_t) | |||
allow <アプリケーション名>_t <アプリケーション名>_etc_t:dir manage_dir_perms; | |||
allow <アプリケーション名>_t <アプリケーション名>_etc_t:file manage_file_perms; | |||
# /etc内での新規ファイル作成時の遷移 | |||
files_etc_filetrans(<アプリケーション名>_t, <アプリケーション名>_etc_t, file) | |||
files_etc_filetrans(<アプリケーション名>_t, <アプリケーション名>_etc_t, dir) | |||
# Polkit認証のための必要な権限 | |||
auth_use_nsswitch(<アプリケーション名>_t) | |||
auth_read_passwd(<アプリケーション名>_t) | |||
# sudo/pkexec経由での実行をサポート | |||
optional_policy(` | |||
sudo_role_template(<アプリケーション名>, <アプリケーション名>_r, <アプリケーション名>_t) | |||
') | |||
### ネットワークアクセス (TCP/IP) | |||
# 基本的なネットワークソケット権限 | |||
allow <アプリケーション名>_t self:tcp_socket create_stream_socket_perms; | |||
allow <アプリケーション名>_t self:udp_socket create_socket_perms; | |||
# ネットワークへの接続 | |||
corenet_tcp_sendrecv_generic_if(<アプリケーション名>_t) | |||
corenet_tcp_sendrecv_generic_node(<アプリケーション名>_t) | |||
corenet_tcp_connect_all_ports(<アプリケーション名>_t) | |||
corenet_tcp_bind_generic_node(<アプリケーション名>_t) | |||
# HTTP / HTTPS通信 (ダウンロード/アップロード) | |||
corenet_tcp_connect_http_port(<アプリケーション名>_t) | |||
corenet_tcp_connect_http_cache_port(<アプリケーション名>_t) | |||
# DNS解決 | |||
sysnet_dns_name_resolve(<アプリケーション名>_t) | |||
# SSLライブラリへのアクセス | |||
miscfiles_read_generic_certs(<アプリケーション名>_t) | |||
miscfiles_read_localization(<アプリケーション名>_t) | |||
### 一時ファイルの管理 | |||
# /tmpディレクトリ内の一時ファイル | |||
files_tmp_filetrans(<アプリケーション名>_t, <アプリケーション名>_tmp_t, { file dir }) | |||
allow <アプリケーション名>_t <アプリケーション名>_tmp_t:dir manage_dir_perms; | |||
allow <アプリケーション名>_t <アプリケーション名>_tmp_t:file manage_file_perms; | |||
# /var/lib内のデータ保存領域 | |||
files_search_var_lib(<アプリケーション名>_t) | |||
allow <アプリケーション名>_t <アプリケーション名>_var_lib_t:dir manage_dir_perms; | |||
allow <アプリケーション名>_t <アプリケーション名>_var_lib_t:file manage_file_perms; | |||
### ログ記録 | |||
# ログファイルへの書き込み | |||
logging_search_logs(<アプリケーション名>_t) | |||
allow <アプリケーション名>_t <アプリケーション名>_log_t:dir { add_name write search }; | |||
allow <アプリケーション名>_t <アプリケーション名>_log_t:file { create write append setattr }; | |||
# システムログへの記録 | |||
logging_send_syslog_msg(<アプリケーション名>_t) | |||
### 共通システムリソースへのアクセス | |||
# カーネル情報の読み取り | |||
kernel_read_system_state(<アプリケーション名>_t) | |||
kernel_read_network_state(<アプリケーション名>_t) | |||
# /procファイルシステムの読み取り | |||
dev_read_urand(<アプリケーション名>_t) | |||
dev_read_rand(<アプリケーション名>_t) | |||
# 基本的なコマンドの実行 | |||
corecmd_exec_bin(<アプリケーション名>_t) | |||
corecmd_exec_shell(<アプリケーション名>_t) | |||
# 共有ライブラリの読み取り | |||
libs_use_ld_so(<アプリケーション名>_t) | |||
libs_use_shared_libs(<アプリケーション名>_t) | |||
# ローカライゼーションファイルの読み取り | |||
miscfiles_read_localization(<アプリケーション名>_t) | |||
# /usr内のファイルの読み取り | |||
files_read_usr_files(<アプリケーション名>_t) | |||
### デスクトップ環境との統合 (DEの使用時) | |||
optional_policy(` | |||
# X11との通信 | |||
xserver_user_x_domain_template(<アプリケーション名>, <アプリケーション名>_t, <アプリケーション名>_tmpfs_t) | |||
') | |||
optional_policy(` | |||
# GNOMEキーリングへのアクセス | |||
gnome_stream_connect_gkeyringd(<アプリケーション名>_t) | |||
') | |||
### ブール値によるオプション機能 | |||
## <desc> | |||
## <p> | |||
## <アプリケーション名>が全てのユーザファイルへの読み書きを許可する | |||
## </p> | |||
## </desc> | |||
gen_tunable(<アプリケーション名>_manage_all_user_content, false) | |||
if (<アプリケーション名>_manage_all_user_content) { | |||
userdom_manage_user_home_content_files(<アプリケーション名>_t) | |||
userdom_manage_user_home_content_dirs(<アプリケーション名>_t) | |||
} | |||
## <desc> | |||
## <p> | |||
## <アプリケーション名>がroot権限でのファイル操作を実行することを許可する | |||
## </p> | |||
## </desc> | |||
gen_tunable(<アプリケーション名>_allow_privileged_operations, true) | |||
if (<アプリケーション名>_allow_privileged_operations) { | |||
# Polkit経由での権限昇格を許可 | |||
optional_policy(` | |||
polkit_domtrans_auth(<アプリケーション名>_t) | |||
') | |||
} | |||
### オプション : ユーザドメインからの起動を許可 | |||
optional_policy(` | |||
# unconfined_tドメインからの起動 | |||
unconfined_domain(<アプリケーション名>_t) | |||
') | |||
# 一般ユーザドメインからのドメイン遷移 | |||
userdom_use_user_terminals(<アプリケーション名>_t) | |||
# ユーザプロセスからの起動を許可 | |||
allow unconfined_t <アプリケーション名>_exec_t:file { execute execute_no_trans }; | |||
domtrans_pattern(unconfined_t, <アプリケーション名>_exec_t, <アプリケーション名>_t) | |||
### セキュリティ強化オプション | |||
# メモリ実行保護 (必要な場合のみコメント解除) | |||
# allow <アプリケーション名>_t self:process { execmem execstack }; | |||
# ファイルディスクリプタの継承制限 | |||
dontaudit <アプリケーション名>_t domain:process { noatsecure siginh rlimitinh }; | |||
# 監査を無効化する一般的な拒否 | |||
dontaudit <アプリケーション名>_t self:capability { sys_resource sys_nice }; | |||
</syntaxhighlight> | |||
<br><br> | <br><br> | ||