1 回答

TA貢獻1847條經驗 獲得超7個贊
我追蹤了源代碼cmd.Run(),發現:
type SysProcAttr struct {
? ? UidMappings? []SysProcIDMap // User ID mappings for user namespaces.
? ? GidMappings? []SysProcIDMap // Group ID mappings for user namespaces.
? ? // GidMappingsEnableSetgroups enabling setgroups syscall.
? ? // If false, then setgroups syscall will be disabled for the child process.
? ? // This parameter is no-op if GidMappings == nil. Otherwise for unprivileged
? ? // users this should be set to false for mappings work.
? ? GidMappingsEnableSetgroups bool
}
因此,如果 的值為默認GidMappingsEnableSetgroups值false,則無論子進程是否具有 root 權限,justiceInit都沒有權限使用syscall。setgroups
結果,當我在函數中cmd.SysProcAttr.GidMappingsEnableSetgroups設置如下時,它就起作用了!truemain
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.SysProcAttr = &syscall.SysProcAttr{
? ? // ...
? ? GidMappingsEnableSetgroups: true,
}
- 1 回答
- 0 關注
- 151 瀏覽
添加回答
舉報