권한 삭제: 읽기 전용 파일 시스템에서 권한 없는 프로세스에게 파일에 대한 읽기 전용 액세스 허용

권한 삭제: 읽기 전용 파일 시스템에서 권한 없는 프로세스에게 파일에 대한 읽기 전용 액세스 허용

이상최소 권한프로세스는 파일 시스템의 데이터에 대해 읽기 전용 액세스 권한을 가질 수 있어야 하며 파일 시스템 자체는 읽기 전용입니다. 그래서 상황은 이렇습니다

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) "데몬 스타일 권한 삭제": 루트로 파일 설명자를 연 다음 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를 루트가 소유한 파일의 표면 소유자로만 설정)와 같은 다른 매핑이 필요할 수 있습니다.

관련 정보