Add ALLOW_EXEC / ALLOW_KILL / ALLOW_DELETE granular flags (fixes #114)#176
Open
gilberg-vrn wants to merge 1 commit into
Open
Add ALLOW_EXEC / ALLOW_KILL / ALLOW_DELETE granular flags (fixes #114)#176gilberg-vrn wants to merge 1 commit into
gilberg-vrn wants to merge 1 commit into
Conversation
Fixes Tecnativa#114. Until now, setting CONTAINERS=1 + POST=1 implicitly granted three high-impact operations: * POST /containers/<id>/exec — create new exec sessions * POST /containers/<id>/kill — kill a container * DELETE /containers/<id> — remove a container In a typical sandboxing setup (an untrusted workload reaching the host Docker socket only via this proxy) these are exactly the operations one wants to deny by default, while still allowing inspect/logs/create-only flows via CONTAINERS=1. The existing EXEC env controls only /exec/<id>/start|resize|inspect (operations on already-created sessions), not creation of new ones — see issue Tecnativa#114. This change introduces three new env flags following the same pattern as the existing ALLOW_START / ALLOW_STOP / ALLOW_RESTARTS: * ALLOW_EXEC — POST /containers/<id>/exec * ALLOW_KILL — POST /containers/<id>/kill * ALLOW_DELETE — DELETE /containers/<id> All three default to 0 (deny). The deny rules are evaluated before the generic CONTAINERS allow rule, so existing deployments that wanted these operations under CONTAINERS=1 must now opt in explicitly — this is the intended behavior change. Tests cover the deny path (default behavior) for each new flag. The existing test_exec_permissions is updated to set ALLOW_EXEC=1 alongside the existing CONTAINERS=1 EXEC=1 POST=1, documenting the new requirement for callers that genuinely need exec.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #114.
Problem
Setting
CONTAINERS=1+POST=1(a common minimum for builders/runners that need to inspect/create containers) implicitly grants three high-impact operations:POST /containers/<id>/exec— create a new exec session in any containerPOST /containers/<id>/kill— kill any containerDELETE /containers/<id>— remove any containerIn a typical sandboxing setup (untrusted workload talks to host Docker via this proxy) these are exactly what one wants to deny by default. The existing
EXECenv flag controls only/exec/<id>/start|resize|inspect(operations on already-created sessions), not creation of new sessions via the/containers/<id>/execpath — see #114 for the original report.Change
Three new env flags, following the same pattern as the existing
ALLOW_START/ALLOW_STOP/ALLOW_RESTARTS:ALLOW_EXECPOST /containers/<id>/execALLOW_KILLPOST /containers/<id>/killALLOW_DELETEDELETE /containers/<id>All default to
0(deny). Deny rules run before the genericCONTAINERSallow rule.Backward compatibility
This does change behavior: existing deployments using
CONTAINERS=1 POST=1to performdocker exec/docker kill/docker rmwill start getting 403 until they add the correspondingALLOW_*=1. The README has been updated to document the new flags and the limitation of the existingEXECflag.I chose to make this an opt-in change rather than gate it behind a "strict mode" toggle because:
ALLOW_START/ALLOW_STOP/ALLOW_RESTARTS, which are also off by default even withCONTAINERS=1.If the maintainers prefer a non-breaking rollout, I'm happy to gate the new behavior behind a
STRICT_CONTAINERS=1flag instead — let me know.Tests
Added three deny-path regression tests (
test_*_denied_without_allow_*) verifying thatCONTAINERS=1 POST=1alone is not enough for exec/kill/delete. Updated the existingtest_exec_permissionsto also setALLOW_EXEC=1, documenting the new requirement for callers that need exec.The allow path of
ALLOW_EXECis covered by the updated existing test. I did not add explicit allow-path tests forALLOW_KILL/ALLOW_DELETEbecausedocker kill/docker rm -fover HAProxy's TCP proxy is flaky with newer dockercli versions (the client opens a hijack-mode connection that HAProxy doesn't keep alive past the response). The deny path is verified byProcessExecutionErrorregardless of which side closes the connection. I'm happy to switch the test suite to arequests-based client if you prefer explicit allow-path coverage.Verification