Skip to content

feat: harden the runtime container and validate it (#24) - #36

Merged
chaodu-agent merged 2 commits into
mainfrom
feat/runtime-container-hardening
Nov 18, 2026
Merged

chaodu-agent merged 2 commits into
mainfrom
feat/runtime-container-hardening

Conversation

@chaodu-agent

Copy link
Copy Markdown
Contributor

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, no fsGroup, terminationGracePeriodSeconds: 10 (new).

Container UID:GID Settings Writable mounts
runtime (shim) 1002:1002, runAsNonRoot readOnlyRootFilesystem: true, allowPrivilegeEscalation: false, drop: [ALL], no add, no env, no port, seed Secret read-only (0444) agent-runtime only (runtime.sock). session-plane is now readOnly: true.
proxy 1001:1001 same four settings, no capability session-plane, admin-socket, proxy-state, proxy-tokens, expiry-store
egress 1003:1003 same four settings none
agent 1000:1000 same four settings agent-runtime, home, work, tmp
netprobe 1000:1000 same four settings its status volume
netcheck root drop: [ALL], add NET_ADMIN only, read-only root its status volume
volume-prep, netinit root CHOWN+FSETID / NET_ADMIN only, read-only root socket roots / netinit-run
expiry-store-bootstrap 1001:1001 (group added) same four settings expiry-store
  • Seccomp: RuntimeDefault is enough. The shim ran hello, register and revoke under it with no denial. A Localhost profile would need a file on every node, so none is shipped.
  • Read-only root, writable only where needed: the shim writes only runtime.sock. Proved by running it: with /, the seed directory and session-plane all read-only, the pod starts and works. Connecting to session.sock needs write permission on the socket file, not on its directory.
  • AppArmor: not set in the manifest, because a node without AppArmor refuses a pod that names a profile. On the test node (k3s v1.36.2, Ubuntu 24.04) containerd applies cri-containerd.apparmor.d (enforce) to every container with no field; a pod with appArmorProfile: RuntimeDefault reads the same and Unconfined reads unconfined. The validator accepts RuntimeDefault or Localhost and refuses Unconfined.
  • Seed file: 0444, root-owned. The kubelet writes Secret files as root and the validator forbids 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.
  • Grace period: the binaries are PID 1 without a SIGTERM handler, so deletion waits the full period: 10.8 s measured instead of 30 s.

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.

  • 6/6 containers ready, restarts 0; init containers exit 0; proxy netfilter self-check ready: ok; audit hello 201 (Ed25519 proof under the hardened runtime).
  • Through runtime.sock as UID 1000: register 201, status, revoke 204; /v1/hello 404. Proxy gate 403 surrogate_missing, egress 405, 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 exec agent: CapEff/CapBnd/CapPrm/CapInh/CapAmb all zero, Seccomp: 2, NoNewPrivs: 1, touch / gives "Read-only file system". Node-side /proc/<pid> for runtime, proxy, egress, netprobe, agent: CapEff 0, Seccomp: 2; netcheck: CapEff 0x1000 (NET_ADMIN only). Runtime mounts: / ro, session-plane ro, agent-runtime rw, seed dir ro.
  • Seed: mode 444 root-owned as seen by the runtime; absent in the agent container (No such file or directory).
  • Store survives pod delete and recreate (same sha256); recreated pod gets hello 201.
  • Cleanup: namespace, volume, seven image names and seven index entries, build files removed. Snapshots before and after match (namespaces, image listing, host iptables, PVs, home listing, tailscale header). One exited helper-pod container (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 (also stage1-probe); cargo test --workspace 406 passed, 0 failed; stage1-probe lib tests 99; release build and hook greps clean; ap-egress has no ap-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.

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.
@chaodu-agent
chaodu-agent merged commit a1f8fe4 into main Nov 18, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runtime proof seed: tighten the runtime container (seccomp or AppArmor, read-only root filesystem)

1 participant