feat: separate privileged iptables setup into init container #431
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.
The agent container previously required NET_ADMIN capability at startup, then dropped it via
capshbefore executing user commands. This relied on runtime tooling for security enforcement rather than Docker's layer-based isolation.Changes
Init container pattern
agent-setupcontainer with NET_ADMIN capability runs first, configures iptables, exitsnetwork_mode: service:agentservice_completed_successfullySimplified agent container
gosu,libcap2-bin,iptablessuinstead ofcapsh --drop=cap_net_adminType system
network_mode?: stringtoDockerServiceinterfacenetworksoptional to support namespace sharingCI/CD
agent-setupimage build/sign/attest to release workflowArchitecture
Security Impact
Defense-in-depth: agent container never receives NET_ADMIN capability. Iptables manipulation is impossible from user code execution context. Security boundary enforced at Docker layer, not runtime script.
Original prompt
This section details on the original issue you should resolve
<issue_title>Security: Separate privileged iptables setup from unprivileged command execution using Docker layers</issue_title>
<issue_description>## Summary
The current agent container architecture adds and drops
CAP_NET_ADMINcapability within the same entrypoint script. While functionally secure, this pattern could be improved by separating privileged setup from unprivileged command execution at the Docker layer level.Current Architecture
The current flow in
containers/agent/entrypoint.sh:NET_ADMINcapabilityentrypoint.shruns as root and sets up iptables rules (line 115)entrypoint.shdropsCAP_NET_ADMINusingcapsh --drop=cap_net_admin(line 144)gosu awfuserswitches to unprivileged userConcerns:
capsh,gosu) to enforce security rather than Docker's built-in mechanismsProposed Solution: Init Container Pattern
Separate the privileged iptables setup into a dedicated init container, allowing the agent container to run without ever having
NET_ADMINcapability.Architecture
Docker Compose Changes
Dockerfile Changes
Benefits
NET_ADMINcapability, even at startupUSER awfuser) enforces user, not runtime scriptcapsh,gosuin the command execution pathChallenges to Address
network_mode: "service:X"requires careful orderingagent-setupandagentimagesAlternative: Simpler Two-Stage Entrypoint
If the init container pattern is too complex,...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.