Decides whether the Hermes platform handoff is fit to release, and refuses to round an absence of evidence up to a pass. The harness is read-only by default and classifies 71 checks PASS / FAIL / NOT_RUN / NOT_APPLICABLE. Any mandatory FAIL or NOT_RUN is NO_GO, and so is a harness-level problem: an unreachable vantage, a catalog entry whose evidence no longer exists, an expired deadline, or an evaluator that raised. Evidence comes from two vantages that cannot cover for each other: an external read-only operator kubeconfig, and the Hermes agent probing itself from inside its own pod. Before any check runs, the harness asks each vantage who it is and stops if they are the same principal, because dual-vantage evidence from one identity is a restatement rather than a corroboration. `--as` is rejected for every operator-side command and reachable only as the inner command of a `kubectl exec`, so impersonation can never stand in for a real self-probe. A deny check needs a live refused request, not only an authorization review. Two safety properties are structural rather than conventional, enforced where an argv becomes a subprocess: the default mode mutates nothing (mutating verbs require a server dry run; there is deliberately no live TokenRequest probe, because a successful one would mint a real credential), and no probe can pull a credential value into a report (no vault/sops/curl, secrets readable only with -o name, environment probes list names, shell only through frozen reviewed templates). Captures are bounded before they are screened, and the rendered report is re-screened before it is written. Mutation lives behind a separate arming flag with an exact confirmation phrase, a caller-supplied unique ref, a preflight that refuses a protected push target before any network call, and a cleanup whose verification is itself mandatory. A default run reports those four checks NOT_RUN. The catalog is declarative so a reviewer reads what is asserted rather than how it is plumbed, and so structural properties can be proven over every entry before a run. Catalog drift surfaces as NOT_RUN, which stops the release. docs/hermes_full_handoff_acceptance.md carries the merge order for PRs #14-#18 on top of the merged #13 baseline, the image build and Flux rollout, the rollback point for each step, the go/no-go checklist, and the limits that are asserted rather than exercised. Validation: 295 handoff tests pass with 100% line coverage on all 15 new modules; the full unit suite is 647 passed with two failures that reproduce unchanged on origin/main; Ruff, py_compile, kustomize render, and a diff credential screen are clean; a live read-only run against Atlas returns NO_GO for the pre-merge cluster with no unscreened fields in the report.
235 lines
9.5 KiB
Python
235 lines
9.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Acceptance checks for what Hermes may and may not do to the cluster.
|
|
|
|
Every deny check pairs an in-pod authorization review with a real request that
|
|
must be refused, because a review reports what RBAC says and only an attempt
|
|
proves the API server enforces it. Mutating attempts go through a server dry
|
|
run: the API server authorises the request and discards it, so the refusal is
|
|
genuine and nothing is written either way.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from hermes_handoff_catalog import (
|
|
FLUX_PROJECTION,
|
|
OPERATOR,
|
|
SELF,
|
|
Targets,
|
|
check,
|
|
deny,
|
|
step,
|
|
)
|
|
from hermes_handoff_model import ATTEMPT, REVIEW, CheckSpec
|
|
from hermes_handoff_policy import shell
|
|
|
|
|
|
def _access(targets: Targets) -> list[CheckSpec]:
|
|
namespace = targets.namespace
|
|
return [
|
|
check(
|
|
"access.no-cluster-admin-binding-for-agent",
|
|
"No ClusterRoleBinding grants the agent service account cluster-admin",
|
|
"access-denied",
|
|
"names_absent",
|
|
[step("bindings", OPERATOR, "kubectl", "get", "clusterrolebindings", "-o", "name")],
|
|
{"step": "bindings", "contains": ("hermes-agent-cluster-admin",)},
|
|
rationale="The operator half of the pair; the in-pod attempts below are the enforcement half.",
|
|
),
|
|
deny(
|
|
"access.secrets-are-denied",
|
|
"Hermes cannot read Secrets cluster-wide",
|
|
("kubectl", "auth", "can-i", "get", "secrets", "--all-namespaces"),
|
|
("kubectl", "get", "secrets", "--all-namespaces", "-o", "name"),
|
|
"Even a regression that granted this could only return object names: the probe is pinned to -o name.",
|
|
),
|
|
check(
|
|
"access.service-account-tokens-are-denied",
|
|
"Hermes cannot mint a service-account token",
|
|
"access-denied",
|
|
"denied",
|
|
[
|
|
step(
|
|
"review-token",
|
|
SELF,
|
|
"kubectl",
|
|
"auth",
|
|
"can-i",
|
|
"create",
|
|
"serviceaccounts/token",
|
|
"--namespace",
|
|
namespace,
|
|
kind=REVIEW,
|
|
),
|
|
step(
|
|
"review-serviceaccount",
|
|
SELF,
|
|
"kubectl",
|
|
"auth",
|
|
"can-i",
|
|
"create",
|
|
"serviceaccounts",
|
|
"--namespace",
|
|
namespace,
|
|
kind=REVIEW,
|
|
),
|
|
step(
|
|
"attempt",
|
|
SELF,
|
|
"kubectl",
|
|
"--namespace",
|
|
namespace,
|
|
"create",
|
|
"serviceaccount",
|
|
"hermes-acceptance-probe",
|
|
"--dry-run=server",
|
|
kind=ATTEMPT,
|
|
),
|
|
],
|
|
rationale="TokenRequest has no side-effect-free live attempt — a successful one would mint a real credential — so it is asserted by review alongside a refused write in the same RBAC family.",
|
|
),
|
|
deny(
|
|
"access.impersonation-is-denied",
|
|
"Hermes cannot impersonate another identity",
|
|
("kubectl", "auth", "can-i", "impersonate", "users", "--all-namespaces"),
|
|
("kubectl", "get", "namespaces", "--as", "system:admin", "-o", "name"),
|
|
"`--as` is reachable only from inside the pod, where the identity is testing its own refusal.",
|
|
),
|
|
deny(
|
|
"access.workload-mutation-is-denied",
|
|
"Hermes cannot mutate its own workload",
|
|
("kubectl", "auth", "can-i", "patch", "deployments", "--namespace", namespace),
|
|
(
|
|
"kubectl",
|
|
"--namespace",
|
|
namespace,
|
|
"patch",
|
|
f"deploy/{targets.agent_deployment}",
|
|
"--type=merge",
|
|
"--patch",
|
|
'{"metadata":{"annotations":{"acceptance.bstein.dev/probe":"deny"}}}',
|
|
"--dry-run=server",
|
|
),
|
|
"A server dry run is authorised and then discarded, so the refusal is real and nothing is written.",
|
|
),
|
|
deny(
|
|
"access.pod-exec-is-denied",
|
|
"Hermes cannot exec into an arbitrary pod",
|
|
("kubectl", "auth", "can-i", "create", "pods/exec", "--all-namespaces"),
|
|
(
|
|
"kubectl",
|
|
"--namespace",
|
|
namespace,
|
|
"exec",
|
|
f"deploy/{targets.switchyard_deployment}",
|
|
"--container",
|
|
targets.switchyard_container,
|
|
"--",
|
|
*shell("path_readable", path="/tmp"),
|
|
),
|
|
"Exec is the one subresource with a harmless real attempt; attach and port-forward are covered by their own reviews.",
|
|
),
|
|
check(
|
|
"access.attach-portforward-and-kube-system-writes-are-denied",
|
|
"Hermes holds no attach, port-forward, or control-plane write authority",
|
|
"access-denied",
|
|
"denied",
|
|
[
|
|
step("review-attach", SELF, "kubectl", "auth", "can-i", "create", "pods/attach", "--all-namespaces", kind=REVIEW),
|
|
step("review-portforward", SELF, "kubectl", "auth", "can-i", "create", "pods/portforward", "--all-namespaces", kind=REVIEW),
|
|
step("review-create", SELF, "kubectl", "auth", "can-i", "create", "configmaps", "--namespace", "kube-system", kind=REVIEW),
|
|
step(
|
|
"attempt",
|
|
SELF,
|
|
"kubectl",
|
|
"--namespace",
|
|
"kube-system",
|
|
"create",
|
|
"configmap",
|
|
"hermes-acceptance-probe",
|
|
"--dry-run=server",
|
|
kind=ATTEMPT,
|
|
),
|
|
],
|
|
rationale="Attach and port-forward have no side-effect-free live attempt, so their reviews ride alongside a real, refused control-plane write.",
|
|
),
|
|
check(
|
|
"access.required-reads-are-allowed",
|
|
"Hermes retains the reads its operator role depends on",
|
|
"access-allowed",
|
|
"allowed",
|
|
[
|
|
step("watch-review", SELF, "kubectl", "auth", "can-i", "watch", "pods", "--namespace", namespace, kind=REVIEW),
|
|
step("pods", SELF, "kubectl", "--namespace", namespace, "get", "pods", "-o", "name"),
|
|
step("namespaces", SELF, "kubectl", "get", "namespaces", "-o", "name"),
|
|
step("deployments", SELF, "kubectl", "--namespace", namespace, "get", "deployments", "-o", "name"),
|
|
step("nodes", SELF, "kubectl", "get", "nodes", "-o", "name"),
|
|
],
|
|
),
|
|
check(
|
|
"access.pod-logs-are-allowed",
|
|
"Hermes can still read pod logs",
|
|
"access-allowed",
|
|
"allowed",
|
|
[
|
|
step(
|
|
"logs",
|
|
SELF,
|
|
"kubectl",
|
|
"--namespace",
|
|
targets.namespace,
|
|
"logs",
|
|
f"deploy/{targets.switchyard_deployment}",
|
|
"--container",
|
|
targets.switchyard_container,
|
|
"--tail",
|
|
"1",
|
|
record=False,
|
|
)
|
|
],
|
|
),
|
|
check(
|
|
"access.flux-and-helm-status-are-allowed",
|
|
"Hermes can read Flux and Helm reconciliation status",
|
|
"access-allowed",
|
|
"allowed",
|
|
[
|
|
step("kustomizations", SELF, "kubectl", "get", "kustomizations.kustomize.toolkit.fluxcd.io", "--all-namespaces", "-o", "name", record=False),
|
|
step("helmreleases", SELF, "kubectl", "get", "helmreleases.helm.toolkit.fluxcd.io", "--all-namespaces", "-o", "name", record=False),
|
|
],
|
|
),
|
|
check(
|
|
"access.namespace-view-agrees-across-vantages",
|
|
"The operator and in-pod vantages see the same namespace inventory",
|
|
"access-allowed",
|
|
"vantages_agree",
|
|
[
|
|
step("operator", OPERATOR, "kubectl", "get", "namespaces", "-o", "name", record=False),
|
|
step("self", SELF, "kubectl", "get", "namespaces", "-o", "name", record=False),
|
|
],
|
|
{"steps": ("operator", "self")},
|
|
rationale="A disagreement here means one vantage is not seeing the cluster the other is certifying.",
|
|
),
|
|
]
|
|
|
|
|
|
def _gitops(targets: Targets) -> list[CheckSpec]:
|
|
return [
|
|
check(
|
|
f"gitops.{kind.split('.')[0]}-reconcile-cleanly",
|
|
f"No unexpected {label} suspension or unhealthy reconciliation",
|
|
"gitops",
|
|
"flux_health",
|
|
[step("objects", OPERATOR, "kubectl", "get", kind, "--all-namespaces", "-o", FLUX_PROJECTION, record=False)],
|
|
{"step": "objects", "expected_suspensions": targets.expected_suspensions},
|
|
)
|
|
for kind, label in (
|
|
("kustomizations.kustomize.toolkit.fluxcd.io", "Kustomization"),
|
|
("helmreleases.helm.toolkit.fluxcd.io", "HelmRelease"),
|
|
)
|
|
]
|
|
|
|
|
|
def access_checks(targets: Targets) -> list[CheckSpec]:
|
|
"""Return the access-denied, access-allowed, and GitOps health checks."""
|
|
return [*_access(targets), *_gitops(targets)]
|