
プロセス(およびすべての潜在的なサブプロセス)が私のユーザープロファイルに基づいてファイルシステムを読み取ることができるようにしたいのですが、そのプロセスの書き込み権限を事前に選択されたフォルダのセット(おそらく1つのフォルダ)に制限したいと思います。 )。
chroot
アクションが広すぎるようです。プロセスをファイルシステムの特定の部分に制限すると、/bin
フォルダなどをマウントする必要性がはるかに簡単になります。私のプロセスは、私が起動する一般的なプロセスのようにファイルシステムの内容を読み取ることができるはずです。
Dockerコンテナを使用してボリュームをマウントすることはできますが、これは過度のようです。ドッカーのインストール、イメージの作成、コンテナの起動などの作業が必要です。
似たようなことをする方法はありますか? :
restricted-exec --read-all --write-to /a/particular/path --write-to /another/particular/path my-executable -- --option-to-the-executable
一部unveil
ただし、呼び出しプロセスによって制御され、書き込みアクセスにのみ使用されます。
答え1
を使用することもできます。これには、systemd
などのファイルシステムへのアクセスを制御するためのさまざまな設定があります。ReadOnlyPaths
ReadWritePaths
systemd-run
以下は、書き込み権限のみを使用してコマンドを実行する簡単な例です/var/lib
。この例はtouch
複数のディレクトリにファイルを作成するために使用されますが、書き込み可能なパスのみが成功します。
root@ubuntu:~# systemd-run --wait -p ProtectSystem=strict -p ProtectHome=read-only -p ReadWritePaths=/var/lib bash -c
'touch /etc/myfile /var/lib/myfile /var/cache/myfile /root/myfile /home/ubuntu/myfile'
Running as unit: run-u1008.service
Finished with result: exit-code
Main processes terminated with: code=exited/status=1
Service runtime: 44ms
root@ubuntu:~# ls -l {/etc/,/var/lib/,/var/cache/,/root/,/home/ubuntu/}myfile
ls: cannot access '/etc/myfile': No such file or directory
ls: cannot access '/var/cache/myfile': No such file or directory
ls: cannot access '/root/myfile': No such file or directory
ls: cannot access '/home/ubuntu/myfile': No such file or directory
-rw-r--r-- 1 root root 0 Mar 3 23:17 /var/lib/myfile
編集する
オプションを使用してユーザーとしてコマンドを実行できます-p User
。残念ながら、私の提案を使用するにはrootアクセス権が必要です。いいえファイルシステム保護の使用--user
(基準:systemd-run --user
このような制限が実装されていないのはなぜですかProtectSystem
?)。
ここに別の簡単な例があります。今回は、コマンドがubuntu
ユーザーとして実行されます。
root@ubuntu:~# install -o ubuntu -g ubuntu -d /tmp/{test,test2}
root@ubuntu:~# systemd-run --wait -p User=ubuntu -p ProtectSystem=strict -p ProtectHome=read-only -p ReadWritePaths=/tmp/test bash -c 'touch /tmp/test/myfile /tmp/test2/myfile /home/ubuntu/myfile'
Running as unit: run-u1043.service
Finished with result: exit-code
Main processes terminated with: code=exited/status=1
Service runtime: 55ms
root@ubuntu:~# ls -l /tmp/{test,test2}/myfile /home/ubuntu/myfile
ls: cannot access '/tmp/test2/myfile': No such file or directory
ls: cannot access '/home/ubuntu/myfile': No such file or directory
-rw-r--r-- 1 ubuntu ubuntu 0 Mar 5 17:37 /tmp/test/myfile
保護に興味がある場合は、systemdの機能を/tmp
検討してください。PrivateTmp
これはサンドボックスプロセスで使用できるシステム設定の1つにすぎません。
答え2
firejail
実行した作業:
mkdir -p ~/test && firejail --read-only=/tmp --read-only=~/ --read-write=~/test/ touch ~/test/OK ~/KO /tmp/KO