feat!: implement RunnerV2 with per-resource subjects and main/context input#5
Conversation
… input
BREAKING CHANGE: The plugin now evaluates policies per individual Kubernetes
resource instead of per cluster. The Rego input schema moved from v1
(input.clusters[...]) to v2 (input.main + input.context). Policies that read
input.clusters[...] must be rewritten against the new shape.
- Bump compliance-framework/agent v0.2.3 -> v0.3.2
- Implement RunnerV2: add Init that registers one SubjectTemplate per
main_resources entry (identity keys cluster_name/namespace/app_name/name)
via runner.InitWithSubjectsAndRisksFromPolicies
- Switch plugin registration to runner.RunnerV2GRPCPlugin
- Eval now iterates per main resource instance: each becomes its own subject
with its own evidence; policies run once per (instance, policy_path) and
evidence is batched per cluster via CreateEvidence
- New config fields:
- main_resources: subset of resources that produces subjects+evidence
(defaults to all of resources); other types are collected as context only
- identity_labels: map of identity key -> priority list of metadata.labels
keys to try (default {"app_name": ["app.kubernetes.io/name", "app"]});
falls back to metadata.name when no candidate matches
- Reserved policy_input keys updated to {schema_version, source, main, context}
- README rewritten for v2 schema, new config fields, and subject model
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR migrates the Kubernetes plugin to the agent’s RunnerV2 interface and changes evaluation semantics from cluster-level to per-resource-instance subjects/evidence, along with a breaking v2 Rego input schema (input.main + input.context).
Changes:
- Implement
Init+ switch toRunnerV2GRPCPlugin, and batchCreateEvidenceper cluster while evaluating policies per(resource instance, policy path). - Add config support for
main_resourcesandidentity_labels, and update reservedpolicy_inputkeys to the v2 schema. - Update tests and README to reflect per-resource subjects and the new input schema.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
main.go |
Implements RunnerV2 Init, rewrites eval loop for per-resource evaluation, adds subject/template/label helpers, updates Rego input builder, switches plugin to RunnerV2 GRPC plugin. |
config.go |
Adds parsing/validation for main_resources and identity_labels, updates reserved policy_input keys for v2 schema. |
main_test.go |
Expands tests to validate per-resource evaluation call shape, identity label resolution, cluster-scoped namespace handling, evidence batching, and Init behavior. |
config_test.go |
Adds coverage for main_resources defaults/subsets and identity_labels parsing/validation; updates reserved-key tests. |
README.md |
Documents breaking schema change, new config fields, per-resource subject/evidence model, and v2 policy input examples. |
go.mod / go.sum |
Bumps compliance-framework/agent and related transitive deps to support RunnerV2. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 7 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 7 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
Summary
Init, switches toRunnerV2GRPCPlugin, bumpscompliance-framework/agenttov0.4.0).main_resourcesbecomes its own subject with its own evidence, keyed bycluster_name/namespace/app_name/name. Policies are evaluated once per(resource instance, policy path); evidence is batched per cluster.input.mainis the single resource under evaluation;input.contextis{cluster, resources}— the full collected cluster snapshot. Replaces the oldinput.clusters[...]shape.main_resources— optional subset ofresourcesthat produces subjects+evidence. Types only inresourcesare collected as policy context. Defaults to all ofresources.identity_labels— map of identity key → priority list ofmetadata.labelskeys to try. Defaults to{"app_name": ["app.kubernetes.io/name", "app"]}. Falls back tometadata.namewhen no candidate matches, soapp_nameis never empty.policy_inputkeys are nowschema_version,source,main,context,subject,fleet.Reference implementation: mirrors the RunnerV2 pattern used in
plugin-dependabot(Granular mode — one evidence per subject, context assembled alongside).Why
The previous implementation produced one evidence stream per cluster: all collected resources were flattened into a single Rego input document and the same cluster-level subjects were attached to every evidence. A compliance failure on one pod tainted the whole cluster subject, history tracking could not follow individual workloads, and it did not match the
SubjectTemplate-based model the agent uses in v2. This PR aligns the plugin with that model so each workload is tracked as an individual compliance subject.Breaking change — downstream action required
Existing Rego policies in
plugin-k8s-policiesandplugin-k8s-opres-policiesreadinput.clusters[_].resources.pods[_]and will not evaluate against the new shape. Those repos must be updated to readinput.main/input.context.resources.<type>in a coordinated follow-up PR.The README contains a full v2 schema description and an updated Rego example that demonstrates cross-referencing
input.mainagainstinput.context.resources.Test plan
go build ./...go test ./...(unit tests cover: per-resource evaluation call shape, identity-label resolution with candidate priority +metadata.namefallback, cluster-scoped resources omittingnamespace, per-cluster evidence batching,Initupserting the expected subject-template set,main_resourcesvalidation, updated reserved-keys set)go vet ./...resources=["nodes","pods"],main_resources=["pods"], and a simple policy readinginput.main.metadata.namespaceandinput.context.resources.nodes; verify one subject per pod with its own evidence.cluster_nameand do not collide across clusters.plugin-k8s-policies/plugin-k8s-opres-policiesto update to the v2 input schema.🤖 Generated with Claude Code