Skip to content

Feat: add ValidatingAdmissionPolicy to protect kagenti.io/type label#418

Draft
rh-dnagornuks wants to merge 6 commits into
kagenti:mainfrom
rh-dnagornuks:vap-agent-label
Draft

Feat: add ValidatingAdmissionPolicy to protect kagenti.io/type label#418
rh-dnagornuks wants to merge 6 commits into
kagenti:mainfrom
rh-dnagornuks:vap-agent-label

Conversation

@rh-dnagornuks

@rh-dnagornuks rh-dnagornuks commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

The kagenti.io/type label on Deployments and StatefulSets can currently be applied by any user, bypassing the AgentRuntime workflow. This PR adds a ValidatingAdmissionPolicy (VAP) that prevents direct application of the label — only the operator's service account (via the AgentRuntime controller) can set or change it. This enforces the intended enrollment flow: users create an AgentRuntime CR, and the controller applies the label. The DefaultsConfigReconciler (which handled unmanaged labeled workloads) is removed since the VAP makes that path impossible. Documentation, samples, and E2E tests are updated to reflect the new enforcement.

Changes

  • ValidatingAdmissionPolicy + Binding — rejects CREATE/UPDATE of Deployments/StatefulSets that set kagenti.io/type unless the request is from the operator's service account or the label value is unchanged on an UPDATE
  • E2E test refactoring — fixtures no longer manually apply kagenti.io/type; tests create an AgentRuntime CR and wait for the operator to apply the label before proceeding
  • DefaultsConfigReconciler removal — deleted the reconciler, its tests, and the ComputeDefaultsOnlyHash function (no longer reachable with VAP in place)
  • Documentation updates — removed manual labeling instructions from GETTING_STARTED.md, api-reference.md, dynamic-agent-discovery.md, controller-webhook-interaction.md, operator-managed-client-registration.md; all examples now use AgentRuntime CRs
  • Sample fix — removed manual kagenti.io/type from skill-discovery sample Deployment metadata
  • AgentCard naming fix — updated api-reference.md to use the auto-generated {name}-{kind}-card naming pattern
  • Stale comment cleanup — removed references to deleted defaults_config_reconciler.go in controller and fixture comments
  • UI Backend exemption — add backend SA to the policy exemption list to allow the UI to continue to function (will require code and documentation/demo rework to use AgentRuntime instead of manual labeling)
  • Kustomize/Helm chart templates — add Kustomize and Helm chart templates to apply the policy on install

Testing

  • Pre-commit checks/tests pass
  • Admission Policy correct behavior verified on a ROSA cluster

Related Issues

Resolves: RHAIENG-4934
Resolves: RHAIENG-4937

Made with Cursor

@rh-dnagornuks rh-dnagornuks force-pushed the vap-agent-label branch 4 times, most recently from 2d7af7f to b31dd19 Compare June 10, 2026 20:41
Adds a ValidatingAdmissionPolicy (agent-label-protection) that prevents
manual application of the kagenti.io/type label on Deployments and
StatefulSets. Only the operator's service account is allowed to set
this label via an AgentRuntime CR. Users who attempt to add the label
directly are rejected with a message directing them to create an
AgentRuntime instead. The policy allows non-operator users to update
workloads that already carry the label as long as they don't change
its value.

Signed-off-by: Daniels Nagornuks <dnagornu@redhat.com>

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Removes manual kagenti.io/type labels from all E2E test fixtures
(echoAgent, noProtoAgent, auditAgent, signedAgent, authBridgeAgent,
authBridgeDisabledAgent) and adds AgentRuntime CRs to drive the label
via the operator. Each test now deploys the workload without the
protected label, creates an AgentRuntime, waits for the operator to
apply kagenti.io/type, then proceeds with existing assertions. This
aligns E2E tests with the new ValidatingAdmissionPolicy that prevents
manual label application.

Signed-off-by: Daniels Nagornuks <dnagornu@redhat.com>

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
The DefaultsConfigReconciler maintained config-hash annotations on
workloads with kagenti.io/type that were not managed by an AgentRuntime
CR. With the new ValidatingAdmissionPolicy enforcing that the label can
only be set via an AgentRuntime, no unmanaged workloads can exist.
The reconciler was effectively a no-op and is now removed along with
its tests and the ComputeDefaultsOnlyHash helper.

Signed-off-by: Daniels Nagornuks <dnagornu@redhat.com>

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Remove manual kagenti.io/type labeling from docs, samples, and
comments. All examples now use AgentRuntime CRs, matching the
ValidatingAdmissionPolicy that prevents direct label application.
Fix auto-created AgentCard naming to use the {name}-{kind}-card
pattern produced by AgentCardSync.

Signed-off-by: Daniels Nagornuks <dnagornu@redhat.com>
Exempt the kagenti-backend service account and the Helm-deployed
operator SA (kagenti-system:controller-manager) from the agent label
protection policy.

Signed-off-by: Daniels Nagornuks <dnagornu@redhat.com>
Add ValidatingAdmissionPolicy and ValidatingAdmissionPolicyBinding as Helm chart templates.

Signed-off-by: Daniels Nagornuks <dnagornu@redhat.com>
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.

1 participant