パーミッションの削除: 読み取り専用ファイルシステムで、権限のないプロセスにファイルへの読み取り専用アクセスを許可する

パーミッションの削除: 読み取り専用ファイルシステムで、権限のないプロセスにファイルへの読み取り専用アクセスを許可する

以上最小権限プロセスはファイルシステムのデータに対して読み取り専用アクセス権を持つことができ、ファイルシステム自体は読み取り専用です。だから状況はこうです

root@linux# ###(1) filesystem is untrusted + readonly
root@linux# grep untrusted_ro_fs /proc/mounts       
/dev/sdb1 /mnt/untrusted_ro_fs ext4 ro 0 0

root@linux# ###(2) no read permissions for (o)thers for /mnt/untrusted_ro_fs/root
root@linux# ls -ld /mnt/untrusted_ro_fs/root
drwxr-x--- 1 root root 1138 Jul  3 21:13 /mnt/untrusted_ro_fs/root

root@linux# ###(3a) unpriviledge process ls (run with uid=9999 and gid=9999) no read access
root@linux# setpriv --reuid=9999 --regid=9999 --clear-groups ls /mnt/untrusted_ro_fs/root
ls: cannot open directory '/root': Permission denied

root@linux# ###(3b) unpriviledge process cat (run with uid=9999 and gid=9999) no read access
root@linux# setpriv --reuid=9999 --regid=9999 --clear-groups cat /mnt/untrusted_ro_fs/root/file
cat: /mtn/untrusted_ro_fs/root/file: Permission denied

root@linux# ###(4) file permission change fails on ro filesystem
root@linux# chmod a+rx /mnt/untrusted_ro_fs/root/
chmod: changing permissions of '/mnt/untrusted_ro_fs/root/': Read-only file system

上記の読み取りアクセス(3a + 3b)を実行する方法に対する回答を探しています。これが私が思いついたアプローチです。理想的な答えは、a) 代替ソリューションを提供するか、b) 提供されたソリューションについて詳しく説明することです。

  • a) 「デーモンスタイル権限の削除」: root でファイル記述子を開き、setuidプロセス内でファイル記述子を開きます。

  • b)「FIFOを使う」、これは(3b)にのみ役立つようです。
    root@linux# mkfifo /access_to_root_file.fifo
    root@linux# chown root:9999 /access_to_root_file.fifo
    root@linux# chmod 0640 /access_to_root_file.fifo
    root@linux# cat /mnt/untrusted_ro_fs/root/file > /access_to_root_file.fifo & root@linux# setpriv --reuid=9999 --regid=9999 --clear-groups cat /access_to_root_file.fifo

  • c) 「カバー」
    root@linux# mkdir /mnt/upper /mnt/work /mnt/merged
    root@linux# mount -t overlay overlay -o lowerdir=/mnt/untrusted_ro_fs,upperdir=/mnt/upper,workdir=/mnt/work /mnt/merged root@linux# chmod a+rx /mnt/merged/root root@linux# setpriv --reuid=9999 --regid=9999 --clear-groups ls /mnt/merged/root &>/dev/null && echo SUCCESS-ls
    SUCCESS
    root@linux# chmod a+rx /mnt/merged/root/file root@linux# setpriv --reuid=9999 --regid=9999 --clear-groups cat /mnt/merged/root/file &>/dev/null && echo SUCCESS-cat
    SUCCESS

  • d)「仮想化」(例:kvv + qemu)。仮想マシンは、信頼できないファイルシステムのブロックデバイスへの読み取り専用アクセスに設定されます。

ベストアンサー1

私にとって最も自然な方法は、次のようにさまざまなアクセス規則を使用してファイルシステムの別のビューを作成することです。特定のユーザーの読み取り/書き込みアクセス権でデバイスをマウントする。そしてファイルシステムバインディング:

mkdir -m 700 /mnt/permissive_view
chown 9999:9999 /mnt/permissive_view
bindfs -r -M 9999 /mnt/untrusted_ro_fs /mnt/permissive_view

その後、以下に9999のアクセスファイルがあります/mnt/permissive_view

このオプションを-M 9999使用すると、ユーザー9999は自分自身をすべてのファイルの所有者と見なします。特定のユースケースに応じて、-u 9999(すべてのユーザーに9999を所有者としてマークする)や--map=0/9999(9999をルートが所有するファイルのサーフェス所有者としてのみ設定)などの他のマッピングが必要になる場合があります。

おすすめ記事