Generated: 2026-03-03
Parent: ../AGENTS.md
Purpose: Docker API security policy enforcement
Security auditing layer for Docker container operations. Inspects create, exec, build, and pull requests against configurable policies. Can deny, rewrite, or pass-through requests.
Key Files:
create.go- Container create auditing (534 lines, most complex)exec.go- Exec create auditingbuild.go- Build request auditingpull.go- Image pull auditinglist.go- Container list filteringnamespace.go- Container label/namespace checks
Auditing happens in AuditCreate() in priority order:
- Privileged - Deny
--privilegedcontainers - Capabilities - Check
CapAddagainst denied list - Sysctls - Allowlist/denylist kernel parameters
- Bind Mounts - Path-based allow/deny with rewrite support
- SecurityOpt - Block dangerous options (seccomp=unconfined, etc.)
- Devices - Deny host device access
- OomKillDisable - Block memory OOM killer disable
- PidsLimit - Deny unlimited PIDs
- LogConfig - Block custom log drivers
- Namespace Modes - Deny
hostmode, trackcontainer:{id}refs - Label Injection - Auto-inject namespace labels
Rules use longest-prefix-match - more specific rules override general ones.
bind_mounts: default_action: "deny" rules: - source_prefix: "/home/ubuntu" rewrite_prefix: "/mnt/host/ubuntu" # Optional path rewrite action: "allow"
Security Note: Paths are string-matched only. Symlinks in allowed directories can escape boundaries. Use rewrite_prefix to mitigate - Docker sees the rewritten path.
Labels Injected:
ltkk.run/namespace- Configured namespace valueltkk.run/managed-by- Always"docker-hardened-proxy"
Cross-Namespace Validation:
When NetworkMode, IpcMode, PidMode, etc. use container:{id}, the referenced container must be in the same namespace. Returns ReferencedContainers for caller to validate.
Blocked SecurityOpt values (case-insensitive):
seccomp=unconfined,seccomp:unconfinedapparmor=unconfined,apparmor:unconfinedlabel:disable,label=disableno-new-privileges:false,no-new-privileges=false
Build Policy:
deny(default) - Block all buildsallow- Allow with security enforcementlist- Allow only for image names inallowedlist
Pull Policy:
allow(default) - Allow all pullsdeny- Block all pullslist- Allow only for registry/image prefixes inallowed
List matching: entries ending with / are prefix matches, others are exact.
| Policy Type | Add To | Pattern |
|---|---|---|
| HostConfig field | create.go |
Add checkFieldName() method, call in AuditCreate() |
| New namespace mode | create.go |
Extend checkNamespaceModes() |
| New dangerous option | create.go |
Add to dangerousSecurityOpts slice |
| Exec restrictions | exec.go |
Modify AuditExecCreate() |
| Build restrictions | build.go |
Modify AuditBuild() |
| Pull restrictions | pull.go |
Modify AuditPull() |
Each audit file has corresponding *_test.go:
- Test deny/allow cases for each policy
- Test edge cases (empty values, malformed JSON)
- Test rewrite behavior
Run: go test ./internal/audit/... -v