Repository navigation
feat: harden the runtime container and validate it (#24) - #36
Merged
Merged
Conversation
pod.yaml: runtime mounts session-plane read-only (its only writable mount is agent-runtime), terminationGracePeriodSeconds 10, expiry-store-bootstrap gets runAsGroup 1001, comments for seccomp and the optional AppArmor field. validate_manifests.py: 13 new rules (seccomp on every container, AppArmor not Unconfined, drop ALL / no extra capability / read-only root for every container, root only in volume-prep, netinit, netcheck, fixed UID and GID, runtime writable mount, runtime env and ports, seed flag and mount, seed in no other container list, seed not in env, short grace period, no API token). 22 new mutation tests. Existing rules are unchanged. Docs: README "Runtime container hardening" and checklist, runtime-split.md note, docs/evidence/runtime-hardening.md. Verified: validator and 79 tests pass; cargo fmt --check, clippy -D warnings (also stage1-probe), cargo test --workspace (406 passed), stage1-probe lib tests (99), release hook greps clean, ap-egress has no ap-broker, sidecar matrix 59/59, passthrough matrix 18/18, run on the build host. Cluster run on a k3s node: see docs/evidence/runtime-hardening.md.
…lume (MEDIUM 1) The seed holder rules keyed on the one secret volume, so a projected volume naming auth-proxy-runtime-key and mounted into agent passed validation. Walk every volume for the seed Secret name (as cred_named does for the credential), require each such volume to be a secret volume (new check runtime-key-volume-is-secret-type), and compute runtime-key-mounted-only-by-runtime and runtime-key-not-in-any-other-container-list over all of them. Add a test for the projected agent mount. Verification (macmini, /usr/bin/python3, rsync of this worktree to ~/repo/auth-proxy-pr36): - ssh macmini 'cd repo/auth-proxy-pr36/deploy/k8s && /usr/bin/python3 validate_manifests.py --root .' -> exit 0, 118 PASS, 0 FAIL, 'all checks passed' - ssh macmini 'cd repo/auth-proxy-pr36/deploy/k8s && /usr/bin/python3 test_validate_manifests.py' -> Ran 80 tests, OK (0 failures, 0 errors) - New test on the pre-fix validator (252412a copy, same test file): FAILED (failures=1), confirming the test catches the gap. Baseline manifest on the pre-fix validator: exit 0. Review LOWs (.agents/tasks/pr36-review/opus.md): - LOW 2 (PR body counts): skipped. It is a PR description edit on GitHub, outside this change. - LOW 3 (README known-gap bullet): addressed. Removed the bullet that this PR resolves. - LOW 4 (RBAC guidance for the seed): addressed. One added sentence in the pods/ephemeralcontainers guidance covering the seed. - LOW 5 (supplementalGroups, sysctls, seLinuxOptions unchecked): skipped. Refusing these needs an allowlist decision for securityContext keys, which is a product choice. - LOW 6 (volume-prep chmod/chown on agent-runtime not validated): skipped. It needs new validator assertions and is a follow-up per the review.
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 #24
Design note: securityContext per container, and why it is safe
Pod level:
seccompProfile: RuntimeDefault(inherited by every init and app container; no container overrides it),shareProcessNamespace: false,automountServiceAccountToken: false,enableServiceLinks: false, nofsGroup,terminationGracePeriodSeconds: 10(new).runAsNonRootreadOnlyRootFilesystem: true,allowPrivilegeEscalation: false,drop: [ALL], no add, no env, no port, seed Secret read-only (0444)agent-runtimeonly (runtime.sock).session-planeis nowreadOnly: true.drop: [ALL], addNET_ADMINonly, read-only rootCHOWN+FSETID/NET_ADMINonly, read-only rootRuntimeDefaultis enough. The shim ran hello, register and revoke under it with no denial. ALocalhostprofile would need a file on every node, so none is shipped.runtime.sock. Proved by running it: with/, the seed directory andsession-planeall read-only, the pod starts and works. Connecting tosession.sockneeds write permission on the socket file, not on its directory.cri-containerd.apparmor.d(enforce) to every container with no field; a pod withappArmorProfile: RuntimeDefaultreads the same andUnconfinedreadsunconfined. The validator acceptsRuntimeDefaultorLocalhostand refusesUnconfined.fsGroup(PRs docs: credential Secret at-rest requirements and validator rules (#21) #26, feat: fail closed when the per-UID netfilter rules are missing (#20) #30), so 0444 is the only mode UID 1002 can read. The agent UID cannot read it because the agent does not mount the volume and shares no PID namespace, not because of the mode. Any process inside the runtime container can read it. This is documented as residual risk.Validator
13 new rules (names in README "Runtime container hardening"), each with a bad-manifest test (22 new tests; 79 total). Nothing from #26 and #30 is weakened or reordered: the existing seccomp, credential Secret, NET_ADMIN-only-in-netinit-and-netcheck, no-capability-in-proxy and status-file ownership rules are untouched, and all pass unchanged.
Cluster evidence (single-node k3s v1.36.2, Ubuntu 24.04, namespace
ap-hard)Full table and cleanup check:
docs/evidence/runtime-hardening.md.netfilter self-check ready: ok; audithello201 (Ed25519 proof under the hardened runtime).runtime.sockas UID 1000: register 201, status, revoke 204;/v1/hello404. Proxy gate403 surrogate_missing, egress405, other loopback port refused, direct egress and DNS refused. Credential, caller key and seed: 0 hits in all container logs and in the agent's env and files.kubectl execagent:CapEff/CapBnd/CapPrm/CapInh/CapAmball zero,Seccomp: 2,NoNewPrivs: 1,touch /gives "Read-only file system". Node-side/proc/<pid>for runtime, proxy, egress, netprobe, agent:CapEff0,Seccomp: 2; netcheck:CapEff0x1000 (NET_ADMINonly). Runtime mounts:/ro,session-planero,agent-runtimerw, seed dir ro.No such file or directory).hello201.helper-podcontainer (volume cleanup) remains in kube-system until the kubelet collects it.Checks run on the build host
validator and tests (79 OK);
cargo fmt --all --check; clippy-D warnings(alsostage1-probe);cargo test --workspace406 passed, 0 failed; stage1-probe lib tests 99; release build and hook greps clean;ap-egresshas noap-broker; sidecar matrix 59/59 (cargo target and driver); passthrough matrix 18/18 (cargo target and driver). One earlier run of the passthrough cargo target failed after 31 s with no cause found; three reruns passed.Not run: a node without AppArmor, the real upstream.