docker driver allow_caps
and cap_add
don't work as documented (fails closed)
#16692
Labels
allow_caps
and cap_add
don't work as documented (fails closed)
#16692
While testing #16643 which fixes the behavior of
cap_add
for theexec
driver, I discovered that thedocker
driver has the same bug. This is because upstream Docker has the same bug (see moby/moby#38664 moby/moby#8460) but has intentionally decided not to fix it. This results in unexpected behavior in thedocker
task driver as well.Note: this bug "fails closed". It does not open capabilities unexpectedly, so it's not a security bug.
tl;dr: for unprivileged users:
allow_caps
can only reduce, not expand, the permitted set of capabilities.cap_add
can only remove selected capabilities from thecap_drop
set (making them allowed again).Unfortunately there's no workaround for this issue short of getting Docker to fix it upstream, which they've previously rejected. So I'm going to update the documentation to note the current behavior and point to this issue.
To verify this behavior, I used the following jobspec. Note that in order to properly test
net_bind_service
you need to set thesysctl net.ipv4.ip_unprivileged_port_start 1024
. This is because upstream Docker has worked around this whole thing for the common case of binding to low ports by setting the defaultsysctl net.ipv4.ip_unprivileged_port_start 0
.job spec
I tested this jobspec along several dimensions: user namespace remapping, the
allow_caps
field on the plugin, theuser
field on the task, and thecap_add
/cap_drop
field. For each test I ran the job,alloc exec
'd into the allocation (if it ran at all), and ran two tests for the netbind and netraw capabilities:Some combinations would not run at all, because
cap_add
is restricted to those capabilities allowed inallow_caps
. But as it turns out,allow_caps
doesn't work to expand the permitted set either. This results in task events like the following:I didn't test every combination out of practicality, but there's more than enough data to draw conclusions.
allow_caps
cap_add
cap_drop
[<defaults>]
[]
[]
[<defaults>, "net_raw"]
[]
[]
[<defaults>]
[]
[]
[<defaults>, "net_raw"]
[]
[]
[<defaults>]
[]
[]
[<defaults>]
[]
["net_bind_service"]
[<defaults>]
["net_bind_service"]
["all"]
["chown"]
["all"]
[]
["all"]
["net_raw"]
[]
[<defaults>]
["net_raw"]
[]
[<defaults>]
["net_bind_service"]
[]
["all"]
[]
[]
["all"]
["net_raw"]
[]
[<defaults>]
["net_bind_service"]
[]
The text was updated successfully, but these errors were encountered: