Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ Implemented and tested in Phase 1:
- Matrix positive rows run against a feature-enabled test binary, not the release binary
- Live run of the K8s pod on a cluster is not in CI: the validator checks the manifest only
- The signature check on the runtime proof is not a constant-time comparison. The design note explains why; revisit if the proof path changes.
- The manifest validator does not catch the runtime proof seed being exposed through env or secretKeyRef. Add a check.
- The 503 error code on the hello path is `unavailable` in the code and `broker_unavailable` elsewhere in the design. Align them.
- The final checks summary lists one test target with 0 passed; the workspace total (289) appears only in the report.

Expand Down Expand Up @@ -244,6 +243,45 @@ flowchart TB
- **Names come from `deploy/k8s/pod.yaml`:** container, volume and port names match that file.
Image references are placeholders until a release pins digests.

### Runtime container hardening

The runtime container holds the Ed25519 proof seed, so its surface is the smallest in the pod
(issue #24). The settings below are in `deploy/k8s/pod.yaml`. `deploy/k8s/validate_manifests.py`
fails on each rule, and each rule has a bad-manifest test. Evidence:
[docs/evidence/runtime-hardening.md](docs/evidence/runtime-hardening.md).

| Setting | Value | Why it is safe |
|---|---|---|
| Seccomp | pod-level `RuntimeDefault`, inherited by every init and app container; no container overrides it | The shim started, said `hello`, registered and revoked a session under it, with no denial. A custom profile is not needed, and a `Localhost` profile would need a file on every node. |
| Root filesystem | `readOnlyRootFilesystem: true` | The shim writes only `runtime.sock`. No `/tmp` and no other path. Measured: `touch` fails on `/`, on the seed directory and on `session-plane`. |
| Writable mounts | `agent-runtime` only | `session-plane` is mounted `readOnly: true`: connecting to `session.sock` needs write permission on the socket file, not on its directory. Measured: `hello`, register and renew work with the read-only mount. |
| Privileges | `allowPrivilegeEscalation: false`, `capabilities.drop: [ALL]`, no `add`, not privileged | `CapEff` and `CapBnd` are all zero, `NoNewPrivs` is 1. |
| User | UID and GID 1002, `runAsNonRoot: true` | Fixed, distinct from the agent (1000), the proxy (1001) and egress (1003). |
| Seed file | Secret volume, `defaultMode` 0444, owned by root, mounted read-only into `runtime` only | The kubelet writes Secret files as root, and the validator forbids `fsGroup`, so 0444 is the only mode UID 1002 can read. The agent cannot read it because it does not mount the volume and shares no process namespace. Measured: the file is absent in the agent container. Not a mode protection: any process in the runtime container can read the seed. |
| Env, ports | none | The seed is never in an env var. |
| PID namespace | `shareProcessNamespace: false` | Other containers cannot reach the runtime's `/proc/<pid>/root`. |
| Service account | `automountServiceAccountToken: false` | A compromised runtime has no API token. |
| Termination | `terminationGracePeriodSeconds: 10` | The binaries run as PID 1 without a SIGTERM handler, so deletion takes about the full grace period (10.8 s measured, 30 s by default). |
| AppArmor | not set in the manifest | A node without AppArmor refuses a pod that names a profile. containerd applies its default profile (`cri-containerd.apparmor.d`, enforce) on a node that has AppArmor, with or without a field. To pin it, add `appArmorProfile: {type: RuntimeDefault}` to the container. The validator accepts `RuntimeDefault` or `Localhost` and refuses `Unconfined`. |

Validator rules added for this (names as printed): `every-container-has-an-enforcing-seccomp-profile`,
`apparmor-profile-if-set-is-not-unconfined`, `every-container-drops-all-and-is-read-only-root`
(no capability beyond `CHOWN` and `FSETID` for `volume-prep` and `NET_ADMIN` for `netinit` and
`netcheck`; no privileged, no hostPort, no non-default procMount),
`only-volume-prep-netinit-netcheck-run-as-root`, `non-root-containers-have-a-fixed-uid-and-gid`,
`runtime-only-writable-mount-is-the-agent-socket-dir`, `runtime-has-no-env-port-or-envfrom`,
`runtime-seed-flag-is-the-secret-item`, `runtime-key-not-in-any-other-container-list` (init and
ephemeral containers included), `runtime-key-not-referenced-by-env`,
`termination-grace-period-is-short` (1 to 15 s) and
`no-service-account-token-and-no-service-links`. The existing seed rules still apply: mode 0444,
one Secret volume, mounted only into `runtime`, read-only, no `fsGroup`.

**Residual risk.** A compromised runtime container can still sign `hello` and session calls with
the seed for as long as that container runs, and it can read the seed. Hardening limits what the attacker can do from there: no
network (netinit gives UID 1002 no route), no writable filesystem, no capability, no API token, no
view of the other containers. It does not stop forged proofs from inside the container. Threshold
shares and per-start derived seeds are out of scope.

### Credential Secret at-rest requirements

The real credential lives in the Secret `auth-proxy-kiro`. The file the proxy reads is not a plain
Expand Down Expand Up @@ -354,7 +392,10 @@ verified against a cluster.
Minimum principal: grant none of `pods/exec`, `pods/attach`, `pods/ephemeralcontainers` and
`nodes/proxy` in `auth-proxy` (or on its node, for `nodes/proxy`) to anyone, apart from a
named break-glass administrator, and treat each like `get` on `auth-proxy-kiro`.
**[untested]**
The seed has the same run-time exposure: a principal that can create a `pods/ephemeralcontainers`
entry with `targetContainerName: runtime` (or run `kubectl debug --target=runtime`) can read it
through the shared process namespace, so treat that verb like `get` on `auth-proxy-runtime-key`
too. **[untested]**
- Backups and snapshots: etcd snapshots, Velero-style namespace backups and node disk snapshots
must be encrypted, or must exclude `auth-proxy-kiro`. This is repo policy and no cited page
states it. **[untested]**
Expand All @@ -370,6 +411,13 @@ verified against a cluster.

- [ ] `python3 deploy/k8s/validate_manifests.py` passes (credential mount, volume type, mode,
read-only and env rules).
- [ ] The same run passes the runtime-hardening rules listed under "Runtime container hardening":
seccomp on every container, read-only root filesystems, no capability beyond the three
allowed, fixed UID and GID, the runtime's only writable mount is `agent-runtime`, the seed
mounted only into `runtime`, a short grace period.
- [ ] On the target node, `kubectl exec` into the agent container shows `CapEff` zero, `Seccomp: 2`
and a read-only root, and the seed path does not exist there. If the node has AppArmor,
`/proc/<pid>/attr/current` of the runtime shows an enforcing profile.
- [ ] Etcd encryption at rest is on for `secrets` in the target cluster with a provider that is
not `identity` and not `aescbc` (`secretbox` or `kms` v2), `k3s secrets-encrypt status`
shows `Enabled`, and `auth-proxy-kiro` was written or rewritten after it was enabled and
Expand Down
23 changes: 22 additions & 1 deletion deploy/k8s/pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ spec:
automountServiceAccountToken: false
enableServiceLinks: false
shareProcessNamespace: false
# Short on purpose: the proxy and the runtime hold no state that needs a long drain (the expiry
# store is on its own volume), and a compromised runtime should not outlive its pod by the default
# 30 s. See "Runtime container hardening" in the README.
terminationGracePeriodSeconds: 10
# Seccomp: the pod-level profile applies to every init and app container, and no container
# overrides it (the validator fails on an override or on Unconfined). RuntimeDefault is enough for
# the runtime shim (measured on a k3s node, see the README). AppArmor is not set here, because a node without AppArmor refuses a pod that names
# a profile. To opt in on a node that has it, add to each container's securityContext (or to this
# pod-level one):
# appArmorProfile:
# type: RuntimeDefault
# The validator accepts RuntimeDefault or Localhost and refuses Unconfined, here or as a
# container.apparmor.security.beta.kubernetes.io/* annotation.
securityContext:
seccompProfile:
type: RuntimeDefault
Expand Down Expand Up @@ -133,6 +146,7 @@ spec:
fi
securityContext:
runAsUser: 1001
runAsGroup: 1001
runAsNonRoot: true
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
Expand Down Expand Up @@ -256,6 +270,9 @@ spec:
readOnly: true
# The runtime: the hello proof and the only client of session.sock. It serves runtime.sock to the
# agent. It runs only ap-runtime-shim and has no network (netinit gives UID 1002 no route out).
# Its only writable path is agent-runtime, where it creates runtime.sock. Its root filesystem is
# read-only, session-plane is mounted read-only (connecting to session.sock needs no write access
# to the directory), and the proof seed is read-only. It has no env, no port and no capability.
- name: runtime
image: REPLACE_RUNTIME_IMAGE
command:
Expand All @@ -279,6 +296,7 @@ spec:
volumeMounts:
- name: session-plane
mountPath: /run/auth-proxy-session
readOnly: true
- name: agent-runtime
mountPath: /run/auth-proxy-agent
# The proof seed. Only this container mounts the Secret, read-only.
Expand Down Expand Up @@ -413,7 +431,10 @@ spec:
- key: api_key
path: api_key
# The hello proof seed (base64 of 32 bytes). Only the runtime mounts it. Mode 0444, as for
# kiro-secret. The validator fails if any other container or init container mounts it.
# kiro-secret: the kubelet writes the file as root, and with no fsGroup (the validator forbids
# one) 0444 is the only mode UID 1002 can read. The agent UID cannot read it because the agent
# container does not mount the volume and shares no process namespace, not because of the mode.
# The validator fails if any other container, init container or ephemeral container mounts it.
- name: runtime-key
secret:
secretName: auth-proxy-runtime-key
Expand Down
152 changes: 152 additions & 0 deletions deploy/k8s/test_validate_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,19 @@ def mutate(pod):
copy.edit_pod(mutate)
self.assert_fails(copy, "runtime-key-mode-0444")

def test_runtime_key_through_a_projected_volume_in_the_agent_is_refused(self):
copy = Copy(self)

def mutate(pod):
pod["spec"]["volumes"].append({"name": "pj", "projected": {"sources": [
{"secret": {"name": "auth-proxy-runtime-key"}}]}})
copy.container(pod, "agent")["volumeMounts"].append(
{"name": "pj", "mountPath": "/k", "readOnly": True})

copy.edit_pod(mutate)
self.assert_fails(copy, "runtime-key-volume-is-secret-type")
self.assert_fails(copy, "runtime-key-not-in-any-other-container-list")

def test_hostpath_volume_is_refused(self):
copy = Copy(self)

Expand Down Expand Up @@ -649,6 +662,145 @@ def mutate(pod):
copy.edit_pod(mutate)
self.assert_fails(copy, "containers-agent-proxy-runtime-egress")

# ---- Runtime container hardening (issue #24): one minimal bad manifest per rule ----

def init_container(self, pod, name):
return next(c for c in pod["spec"]["initContainers"] if c["name"] == name)

def test_pod_seccomp_unconfined_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: pod["spec"]["securityContext"].__setitem__(
"seccompProfile", {"type": "Unconfined"}))
self.assert_fails(copy, "every-container-has-an-enforcing-seccomp-profile")

def test_missing_pod_seccomp_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: pod["spec"]["securityContext"].pop("seccompProfile"))
self.assert_fails(copy, "every-container-has-an-enforcing-seccomp-profile")

def test_runtime_container_seccomp_unconfined_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: copy.container(pod, "runtime")["securityContext"].__setitem__(
"seccompProfile", {"type": "Unconfined"}))
self.assert_fails(copy, "every-container-has-an-enforcing-seccomp-profile")

def test_localhost_seccomp_without_a_profile_name_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: pod["spec"]["securityContext"].__setitem__(
"seccompProfile", {"type": "Localhost"}))
self.assert_fails(copy, "every-container-has-an-enforcing-seccomp-profile")

def test_apparmor_runtime_default_on_the_runtime_is_accepted(self):
copy = Copy(self)
copy.edit_pod(lambda pod: copy.container(pod, "runtime")["securityContext"].__setitem__(
"appArmorProfile", {"type": "RuntimeDefault"}))
code, out = run_validator(copy.root)
self.assertEqual(code, 0, out)

def test_apparmor_unconfined_field_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: copy.container(pod, "runtime")["securityContext"].__setitem__(
"appArmorProfile", {"type": "Unconfined"}))
self.assert_fails(copy, "apparmor-profile-if-set-is-not-unconfined")

def test_apparmor_unconfined_annotation_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: pod["metadata"].setdefault("annotations", {}).__setitem__(
"container.apparmor.security.beta.kubernetes.io/runtime", "unconfined"))
self.assert_fails(copy, "apparmor-profile-if-set-is-not-unconfined")

def test_init_container_with_a_writable_root_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: self.init_container(pod, "expiry-store-bootstrap")[
"securityContext"].__setitem__("readOnlyRootFilesystem", False))
self.assert_fails(copy, "every-container-drops-all-and-is-read-only-root")

def test_privileged_egress_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: copy.container(pod, "egress")["securityContext"].__setitem__(
"privileged", True))
self.assert_fails(copy, "every-container-drops-all-and-is-read-only-root")

def test_extra_capability_on_the_runtime_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: copy.container(pod, "runtime")["securityContext"][
"capabilities"].__setitem__("add", ["NET_BIND_SERVICE"]))
self.assert_fails(copy, "every-container-drops-all-and-is-read-only-root")

def test_extra_capability_on_volume_prep_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: self.init_container(pod, "volume-prep")["securityContext"][
"capabilities"].__setitem__("add", ["CHOWN", "FSETID", "DAC_OVERRIDE"]))
self.assert_fails(copy, "every-container-drops-all-and-is-read-only-root")

def test_bootstrap_running_as_root_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: self.init_container(pod, "expiry-store-bootstrap")[
"securityContext"].__setitem__("runAsUser", 0))
self.assert_fails(copy, "only-volume-prep-netinit-netcheck-run-as-root")

def test_bootstrap_without_a_group_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: self.init_container(pod, "expiry-store-bootstrap")[
"securityContext"].pop("runAsGroup"))
self.assert_fails(copy, "non-root-containers-have-a-fixed-uid-and-gid")

def test_runtime_with_a_writable_session_plane_is_refused(self):
copy = Copy(self)

def mutate(pod):
for m in copy.container(pod, "runtime")["volumeMounts"]:
if m["name"] == "session-plane":
m.pop("readOnly")

copy.edit_pod(mutate)
self.assert_fails(copy, "runtime-only-writable-mount-is-the-agent-socket-dir")

def test_runtime_with_an_env_var_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: copy.container(pod, "runtime").__setitem__(
"env", [{"name": "X", "value": "1"}]))
self.assert_fails(copy, "runtime-has-no-env-port-or-envfrom")

def test_seed_flag_naming_another_file_is_refused(self):
copy = Copy(self)

def mutate(pod):
cmd = copy.container(pod, "runtime")["command"]
cmd[cmd.index("--seed-file") + 1] = "/var/run/auth-proxy-runtime/other.seed"

copy.edit_pod(mutate)
self.assert_fails(copy, "runtime-seed-flag-is-the-secret-item")

def test_ephemeral_container_mounting_the_seed_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: pod["spec"].__setitem__("ephemeralContainers", [{
"name": "dbg", "image": "x",
"volumeMounts": [{"name": "runtime-key", "mountPath": "/k", "readOnly": True}]}]))
self.assert_fails(copy, "runtime-key-not-in-any-other-container-list")

def test_seed_secret_as_env_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: copy.container(pod, "egress").__setitem__("env", [{
"name": "SEED", "valueFrom": {"secretKeyRef": {
"name": "auth-proxy-runtime-key", "key": "runtime_ed25519.seed"}}}]))
self.assert_fails(copy, "runtime-key-not-referenced-by-env")

def test_missing_grace_period_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: pod["spec"].pop("terminationGracePeriodSeconds"))
self.assert_fails(copy, "termination-grace-period-is-short")

def test_long_grace_period_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: pod["spec"].__setitem__("terminationGracePeriodSeconds", 300))
self.assert_fails(copy, "termination-grace-period-is-short")

def test_service_account_token_automount_is_refused(self):
copy = Copy(self)
copy.edit_pod(lambda pod: pod["spec"].__setitem__("automountServiceAccountToken", True))
self.assert_fails(copy, "no-service-account-token-and-no-service-links")


if __name__ == "__main__":
unittest.main()
Loading
Loading