
在我的 Linux 機器上,我(我的使用者)有一個主群組和多個其他群組(注意我屬於群組 150):
$ id -u; id -g; id -G
1000
1000
1000 6 21 91 97 150 190 465 996 1003
我需要將命令隔離到使用者命名空間。我用unshare --user
它:
$ unshare --user --map-user=4000 --map-group=4000 bash -c 'id -u; id -g; id -G'
4000
4000
4000 65534
(請注意,我所屬的所有群組都被保留,但由於其中大多數群組未映射到新的使用者命名空間中,因此它們被溢出群組、65534、「nobody」或「nogroup」取代。getgroups
透過呼叫來確認這一點返回清單「1000 65534 65534 65534 65534 65534 65534 65534 65534 65534」 id
會刪除該清單的重複項目。
作為用戶,我不允許映射除父名稱空間(1000)中的有效群組之外的任何群組。但在這裡,我確實需要使用我的補充組之一來運行具有升級權限的可執行檔(請注意,/usr/bin/dumpcap
僅當其中一個組位於組150 中時才可以執行,我在該組中位於外部命名空間中):
$ ls -n /usr/bin/dumpcap
-rwxr-xr-- 1 0 150 116928 Jun 7 21:16 /usr/bin/dumpcap
$ getcap /usr/bin/dumpcap
/usr/bin/dumpcap cap_dac_override,cap_net_admin,cap_net_raw=eip
有沒有辦法使用戶命名空間中的群組映射到我在父命名空間中所屬的補充組(此處為150)? ——CAP_SETGID
當然,如果沒有的話那就太容易了。 ;-)