feat(sandbox): give the agent a scoped credential and make GKE and vcluster work #15
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #15"
general
weight: 0.35
isadominguez314
Makes the first scoreable sandboxed run possible. 1731 tests pass, ruff clean.
Why this is needed
PR 1 built the boundary but could only reach kind, and it mounted the operator's admin client certificate as the agent's cluster credential. Two consequences made it unscoreable:
build_network_planraisedSandboxErrorfor any non-kind context, and scored runs must use remote-node clusters — co-located kind is dev-only. That is observed incident 1: a privileged pod on a kind node read the bench checkout off the host disk.gke-gcloud-auth-plugin, which needs agcloudbinary and ADC the container deliberately lacks.Pradeep's #14 makes the boundary reachable for all four CLI arms. This PR makes it hold.
What lands
A scoped credential instead of the admin cert. New
devops_bench/k8s/agent_credentials.pycreates abench-agentServiceAccount inbench-system, binds built-ineditcluster-wide plus a small cluster-scoped supplement, and mints a short-lived token (run timeout + slack, clamped to [10m, 2h]). The rendered kubeconfig carries that token and noexec:block. The admin path survives only behindBENCH_SANDBOX_ALLOW_ADMIN_CREDS=1; without it, a failure to mint raises rather than falling back.Per-provider network plans. New
Provider.sandbox_network_planhook — default is a plain bridge, so a new provider gets a working sandbox for free and only kind carries special knowledge.build_network_plan(provider, cluster_info)applies the hook, then a generic loopback normalisation rewrites127.0.0.1/localhost/::1tohost.docker.internal. GKE and vcluster stop raising.Pod security. PSA
baselinelabels on provision-time namespaces, plus aValidatingAdmissionPolicybackstop covering namespaces the agent creates later — which a label cannot, and whichdeploy-hello-appliterally asks the agent to do. Two further policies guard the exemptions that policy needs, and a fourth covers pods that predate it (both below). Newagent_pod_security:task key (baselinedefault,privilegedopts out); an unrecognised value is a load-time error, not a silent fall-back.Kubernetes 1.30 is a floor.
admissionregistration.k8s.io/v1only reached GA there, and bothnode_imagedefaults still pointed atkindest/node:v1.29.2— so every sandboxed kind task failed on a module-built cluster, which validation on GKE and vcluster could not see. Raised to the digest-pinnedv1.30.0fivetf/prebuiltstacks already use, and the version is now a checked precondition rather than only a default: left to the apply it surfaces asno matches for kind, which reads like a typo in our own manifest. Deliberately aSandboxErrorand not routed throughBENCH_SANDBOX_ALLOW_ADMIN_CREDS— that hatch is for an operator who cannot write cluster-scoped objects, and no credential makes a 1.29 apiserver serve a v1 policy. Thanks @pradeepvrd.The metadata endpoint is blocked for containers on the bastion (
DOCKER-USER -d 169.254.169.254 -j REJECT). That is observed incident 2. Minting a scoped model token is pointless while the container can curl the VM service account's unscoped one.Refusal to run unpinned. If the plan carries no context pin —
--no-infra, the no-op deployer — provisioning would write a cluster-wide admission policy and ClusterRoleBindings to whatever the ambient current-context names. It refuses and says which cluster it declined to touch.Interim state, please read
A sandboxed Vertex run cannot authenticate. The metadata block plus
_matrix_lib.shunsetting API keys means Vertex falls back to ADC through exactly the blocked endpoint. It fails loud rather than degrading to an unsandboxed run, which is correct under that invariant — but it means sandboxing is usable withAGENT_PROVIDER=google+AGENT_API_KEYand unavailable for the matrix default until PR 2.5 (a metadata-server emulator; needs aroles/iam.serviceAccountTokenCreatorgrant that does not exist yet). Ambient runs are unaffected by the block — they are host processes, soDOCKER-USERis never consulted for them. Note this is a statement about the metadata rule only; see Validation for what ambient Vertex on the bastion actually needed before it would run at all.Operator prerequisite on GKE
The runner identity needs
roles/container.admin. GKE gates admission-policy resources behindcontainer.thirdPartyObjects., whichroles/container.developerlacks — without it the pod-security backstop silently is not installed. Measured, not assumed: this blocked validation until the grant was made.Known residuals
Documented in
docs/components/agents.mdrather than left implicit:editbound cluster-wide reaches system namespaces:impersonateon serviceaccounts andcreateon serviceaccounts/token, so the agent can mint a token for a ServiceAccount bound tocluster-admin. A path to cluster-admin, and RBAC has no deny rule, so nothing in the supplement can subtract it. Thepods/execroute alongside it is now denied by the exempt-namespace guard, but that is a patch over one exit rather than a fix for the scope.editcarries read and write onsecretsin every namespace. Inherited from the built-in role, not narrowed anywhere.update/patchon namespaces, so PSA labels can be stripped. The admission policies are unaffected, so this removes the non-load-bearing half. Measured: on the GKE run the labels were byte-identical before and after — a capability held, not a behaviour seen.bench-system, the bindings, the admission policies and the PSA labels outlive the run. Fine on a disposable cluster; on a reused one the labeller looks inert because it finds its work already done.tf/prebuiltfixture that deploys privileged pods (opa-remediationships two) would fail to come up on a second run against the same cluster. Teardown of the policies belongs in PR 3 with the rest of the lifecycle work; flagging it rather than letting someone rediscover it as a flaky fixture.Narrowing is not a blind edit — the tasks were authored against admin, and too tight a scope fails them in ways that read as agent error. The A/B soak is what produces the verb set.
The scope is already too tight in one place
editcovers Kubernetes' own API groups, not the CRDs an operator installs — the agent gets whatever that operator aggregated intoedit, usually nothing. Kyverno v1.12.7 labels policy readsaggregate-to-viewand policy writesaggregate-to-admin, with noaggregate-to-editon either, so the agent readsClusterPolicyobjects and cannot write them.Two of
opa-remediation's objectives ask it to flip both policies fromAudittoEnforce. That task cannot be fully passed under the default scope — one of its three deterministic objective groups is unreachable, and its sandboxed score is not comparable to its ambient one.Nothing in a trajectory reveals this: neither agent attempted the flip, so there is no
forbiddenin the logs and the objective reads as an agent miss. An A/B soak that infers scope gaps from failures will not find this class. The fix is a per-task RBAC supplement — atask.yamlkey naming existing ClusterRoles to bind, validated against a deny-list and recorded incapabilities_granted— which is its own PR, since it lets the artifact under test widen its own sandbox and deserves review on that basis rather than as a footnote here.Gotcha worth flagging up front
AGENT_API_KEY, notGEMINI_API_KEY. The provider's own names are where the key is written inside the container; the host only ever readsAGENT_API_KEY. Unsandboxed the distinction is invisible, because the agent subprocess inherits the whole host environment. Sandboxed, only the explicit overlay crosses — so a host-sideGEMINI_API_KEYis absent and the CLI exits naming the very variable you exported. Corrected in the docs in this PR.Validation
Run on the bastion, docker only.
forbidden/deniedacross 41 trajectory steps:editplus the supplement covered everything the agent reached for.gke-gcloud-auth-plugin; the container has nogcloud, so had it been handed the ambient config everykubectlwould have failed. They all worked. kind cannot prove this — a client cert works there.get ns --show-labelsbefore and after was byte-identical but for AGE.gmp-system, andkubectl execinto a liveevent-exporter-gkepod inkube-system— which kind cannot demonstrate, having no managed components to guard. The first attempt failed, and failed correctly: withcontainer.adminabsent the run raisedSandboxErrorand refused rather than proceeding with a boundary that would not hold, independently reproducing thecontainer.thirdPartyObjects.prerequisite from a cold start.by-labelappearing zero times: every managed namespace on GKE is also on the exempt name list, soby-namematched first and half the guard had never run. The new probe holds a namespace that carries the addon manager's label and is absent from the name list, so onlyby-labelcan deny it — and the apiserver names the binding that fired:ValidatingAdmissionPolicy 'bench-agent-exempt-namespace-guard' with binding 'bench-agent-exempt-namespace-guard-by-label' denied request. Getting there took a fix of its own: GKE's addon manager prunes namespaces carrying its label, and on the probe's first run it deleted the namespace 2.5 seconds before the agent's create landed (audit log, to the millisecond).ValidatingAdmissionPolicy 'bench-agent-nonconformant-pod-guard' ... this pod was created before the benchmark's pod-security policy was applied— and its exec into the conformant one beside it succeeds. They differ only in conformance, so that pair is the guard discriminating rather than exec being broken wholesale, which is how a fail-closed policy looks if you only probe the deny.pods/ephemeralcontainersrule was proven under deliberately widened RBAC, because it was otherwise passing for the wrong reason — RBAC, not the policy. One of these probes failed on its first run and produced the last commit in this branch — see below.e13d52e) and this branch (3ed87db) each ranopa-remediationon the bastion withBENCH_AGENT_SANDBOXunset, ambient Vertex, same model and judge. All 15 deterministic verification entries are identical — 13 pass, and the same 2 fail on both — with identicalcapabilities_grantedand no parse errors on either side. The judge-scored items differ in both directions (one checklist item down,OutcomeValidity0.4 → 0.7) across trajectories of 28 and 38 steps, which is agent and judge nondeterminism rather than a systematic shift. n=1 per arm, so this shows the deterministic surface is unchanged, not that two stochastic runs are byte-identical.A probe found a real hole, and it is fixed here
The pod-security policy exempts the namespaces holding the cluster's own components, because kube-proxy and the CNI legitimately run privileged with host mounts and a fail-closed policy over them breaks the cluster rather than the agent. The module asserted the property that makes that safe — every exempt name must be one the agent cannot write to — and nothing enforced it.
editis bound cluster-wide.So
kubectl run --privileged -n kube-systemwas an admitted request on a cluster carrying the full policy set. The escape the whole stack exists to deny, reachable by appending a flag. That is not a derivation from reading the RBAC; the probe ran and the pod was created.A third policy closes it: the agent's own username may not create or update anything that can produce a pod inside an exempt namespace, nor exec into one already there. Every workload kind rather than
podsalone, because a Deployment reaches the same place with its pod made by the ReplicaSet controller under another identity — the workload object is the last point the agent's name is on the request.pods/exec,pods/attachandpods/portforwardtoo, becauseeditgrants exec and these are precisely the namespaces whose pods are privileged; a shell in kube-proxy is the same escape by a longer route. Config is untouched: a ConfigMap inkube-systemis a blast-radius question, not an escape, and denying it would fail tasks for no boundary gain.Re-probed on the cluster that failed the original: the privileged pod, an unprivileged Deployment (which only this guard can deny, so it cannot pass on the pod policy's back) and
kubectl execinto a runningcorednsare all refused by name, andcontrol:ordinary-pod/control:ordinary-namespacestill pass — the guard is not simply failing closed over everything.A fourth policy closes the route the same reasoning leaves open in the other direction, and @pradeepvrd caught it in review: admission only sees requests, so nothing retracts a pod that already exists — and the deployer runs before credentials are provisioned.
tf/prebuilt/opa-remediationleavesprivileged: truepods inteam-alphaandteam-beta, neither exempt, so the policy is in scope for them and simply arrived too late.kubectl debugand podUPDATEwere already closed;CONNECTwas the one left, and admission there is nearly blind — the object on apods/execrequest is aPodExecOptions, so there is nothing to test a property against. The run scans every namespace before the agent starts, finds the pods the policy would have rejected, and names them. Applied even when the list is empty, with a constanttrue: nothing is torn down, so a reused cluster would otherwise keep the previous run's list, and an empty CEL list literal has no element type to infer — a policy that fails to compile underfailurePolicy: Faildenies every exec the agent attempts, which is the opposite of inert.This also closes the exec half of the first known residual above. The
impersonate/serviceaccounts/tokenhalf stays open — RBAC has no deny rule, so only replacingeditwith a derived role fixes the scope itself.Worth saying plainly: I had written this hole up as a reasoned concern from reading the RBAC and was ready to ship with it documented. The probe is what turned it into a merge blocker, and it is the argument for PR 4 promoting these into an e2e test.
Two more things only a real cluster found
The GKE run also earned its keep by finding two things a kind run could not. It exposed the stale exempt list fixed in this branch — the labeller had stamped
enforce=baselineon four GKE-managed namespaces and the fail-closed pod policy had them in scope. And a blanket metadataREJECTturned out to take container DNS down with it, because on a GCP VM the metadata address is the resolver; kind conceals that, since containers on a user-defined network resolve through Docker's embedded server instead. Both are fixed here.Still open, and I'd rather say so than imply otherwise:
by-labelbinding is proven on GKE only. Nothing on kind or vcluster carries the addon manager's label, so there the binding matches nothing and the probe cannot run at all. That is the intended shape — the name list is what covers those providers — but it does mean one of the two bindings is exercised on exactly one provider.no matches for kind) is the one that was observed.Probes live on
validation/sandbox-probes(hack/sandbox_probe.py), deliberately not in this PR — dev tooling, not shipped surface. PR 4 promotes them into an e2e test.