SELinux:カスタムタイプunconfined_tプロセスへのアクセスが拒否されました。

SELinux:カスタムタイプunconfined_tプロセスへのアクセスが拒否されました。

SELinux、debian 11、デフォルトポリシー(apt経由でインストール)。独自のファイル形式を作成しました。私はこれらのファイルが他のunconfined_tアプリケーション(ルートを含む)ではなく特定のアプリケーションからのみアクセスできるようにしたいと思います。これを達成する最も簡単で信頼性の高い方法は何ですか?複雑な設定を行わずに、できるだけデフォルトのポリシーに近づけることをお勧めします。

ベストアンサー1

私はいくつかの試みの終わりに仕事をするためにTEファイルを作成しました。

もしかしたら誰かに役立つかと思ってここに残しておきます。

主な問題は、私たちが使用すると、制限されてfiles_type (< our type >)いないすべてのプロセスが自動的にこれらのファイルにアクセスできることです。したがって、マクロを使用せずにfiles_type()十分です。

policy_module(mytest,1.0)

require {
    type kernel_t;
    type init_t;
    type initrc_t;
    type user_home_dir_t;
    role unconfined_r;
    type unconfined_t;
    attribute exec_type;
}

type mytest_file_t;
type mytest_app_t;

allow mytest_app_t mytest_file_t:file { manage_file_perms relabel_file_perms exec_file_perms quotaon mounton watch };

# mark mytest_app_t as unconfined application
unconfined_domain(mytest_app_t);
application_exec_all(mytest_app_t);
application_signal(mytest_app_t);
files_unconfined(mytest_app_t);

# files
fs_associate(mytest_file_t);
type_transition mytest_app_t user_home_dir_t: file mytest_file_t;

# add to unconfined role
role unconfined_r types { mytest_app_t mytest_file_t};

# allow transition to mytest_app_t only from unconfined, kernel and init
allow {unconfined_t kernel_t init_t initrc_t} mytest_app_t : process {transition siginh rlimitinh noatsecure};

# allow kernel and init apps to work with my files
allow {kernel_t init_t initrc_t} mytest_file_t:file { manage_file_perms relabel_file_perms quotaon mounton watch };

# allow any exec file to be entrypoint to mytest_app (only for demo and test reasons)
allow mytest_app_t exec_type : file {read_file_perms exec_file_perms entrypoint};

この構成には、mytest_app_t2つのタイプが導入されましたmytest_file_tmytest_app_tプロセスがフォルダにファイルを作成すると、user_home_dir_tファイルタイプはmytest_file_t制限されていないルートプロセスでもこのファイルへのアクセスを拒否します。また、configにはカーネルお​​よび初期化例外も導入されます。

この概念をテストするには、コマンドを実行し、/home/cp/file1.txt の nano アプリケーションからファイルを生成し、プロセスタイプを手動で設定できます。

runcon -t mytest_app_t /usr/bin/nano /home/cp/file1.txt

ここに画像の説明を入力してください。

ここに画像の説明を入力してください。

mytest_file_tファイルは、プロセスによって作成された場合にのみ表示および変更できますmytest_app_t。ルートでさえ、これらのファイルのプロパティを見ることはできません。

おすすめ記事