mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
drivers/exec: Fix handling of capabilities for unprivileged tasks (#16643)
Currently, the `exec` driver is only setting the Bounding set, which is not sufficient to actually enable the requisite capabilities for the task process. In order for the capabilities to survive `execve` performed by libcontainer, the `Permitted`, `Inheritable`, and `Ambient` sets must also be set. Per CAPABILITIES (7): > Ambient: This is a set of capabilities that are preserved across an > execve(2) of a program that is not privileged. The ambient capability > set obeys the invariant that no capability can ever be ambient if it > is not both permitted and inheritable.
This commit is contained in:
committed by
GitHub
parent
ee9e2e0fa1
commit
70faebbbb8
@@ -628,27 +628,40 @@ func TestExecutor_Capabilities(t *testing.T) {
|
||||
testutil.ExecCompatible(t)
|
||||
|
||||
cases := []struct {
|
||||
user string
|
||||
caps string
|
||||
user string
|
||||
capAdd []string
|
||||
capDrop []string
|
||||
capsExpected string
|
||||
}{
|
||||
{
|
||||
user: "nobody",
|
||||
caps: `
|
||||
CapInh: 0000000000000000
|
||||
CapPrm: 0000000000000000
|
||||
CapEff: 0000000000000000
|
||||
capsExpected: `
|
||||
CapInh: 00000000a80405fb
|
||||
CapPrm: 00000000a80405fb
|
||||
CapEff: 00000000a80405fb
|
||||
CapBnd: 00000000a80405fb
|
||||
CapAmb: 0000000000000000`,
|
||||
CapAmb: 00000000a80405fb`,
|
||||
},
|
||||
{
|
||||
user: "root",
|
||||
caps: `
|
||||
capsExpected: `
|
||||
CapInh: 0000000000000000
|
||||
CapPrm: 0000003fffffffff
|
||||
CapEff: 0000003fffffffff
|
||||
CapBnd: 0000003fffffffff
|
||||
CapAmb: 0000000000000000`,
|
||||
},
|
||||
{
|
||||
user: "nobody",
|
||||
capDrop: []string{"all"},
|
||||
capAdd: []string{"net_bind_service"},
|
||||
capsExpected: `
|
||||
CapInh: 0000000000000400
|
||||
CapPrm: 0000000000000400
|
||||
CapEff: 0000000000000400
|
||||
CapBnd: 0000000000000400
|
||||
CapAmb: 0000000000000400`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
@@ -662,7 +675,17 @@ CapAmb: 0000000000000000`,
|
||||
execCmd.ResourceLimits = true
|
||||
execCmd.Cmd = "/bin/bash"
|
||||
execCmd.Args = []string{"-c", "cat /proc/$$/status"}
|
||||
execCmd.Capabilities = capabilities.NomadDefaults().Slice(true)
|
||||
|
||||
capsBasis := capabilities.NomadDefaults()
|
||||
capsAllowed := capsBasis.Slice(true)
|
||||
if c.capDrop != nil || c.capAdd != nil {
|
||||
calcCaps, err := capabilities.Calculate(
|
||||
capsBasis, capsAllowed, c.capAdd, c.capDrop)
|
||||
require.NoError(t, err)
|
||||
execCmd.Capabilities = calcCaps
|
||||
} else {
|
||||
execCmd.Capabilities = capsAllowed
|
||||
}
|
||||
|
||||
executor := NewExecutorWithIsolation(testlog.HCLogger(t))
|
||||
defer executor.Shutdown("SIGKILL", 0)
|
||||
@@ -690,7 +713,7 @@ CapAmb: 0000000000000000`,
|
||||
return s
|
||||
}
|
||||
|
||||
expected := canonical(c.caps)
|
||||
expected := canonical(c.capsExpected)
|
||||
tu.WaitForResult(func() (bool, error) {
|
||||
output := canonical(testExecCmd.stdout.String())
|
||||
if !strings.Contains(output, expected) {
|
||||
|
||||
Reference in New Issue
Block a user