fix: add Kyverno mutation for kagent declarative agent pod security#34
Merged
Merged
Conversation
kagent's upstream sub-agent charts (cilium-policy-agent, promql-agent, etc.) render Agent CRs without securityContext in spec.declarative.deployment. The kagent controller therefore creates Deployments without the fields required by GS restricted-PSS Kyverno policies, which blocks reconciliation. Add a ClusterPolicy that mutates Deployments in the kagent namespace at admission time, adding the four required fields using Kyverno's +(key) anchor (add-if-absent) so existing values on other Deployments in that namespace are not affected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
ClusterPolicythat mutates Deployments in the kagent namespace at admission time to add the four fields required by GS restricted-PSS Kyverno policies.Why
kagent's upstream sub-agent chart templates (
cilium-policy-agent,promql-agent, etc.) renderAgentCRs withoutpodSecurityContext/securityContextinspec.declarative.deployment. The kagent controller creates Deployments from those CRs without the required fields, which Kyverno blocks:disallow-capabilities-strict— missingcapabilities.drop: [ALL]disallow-privilege-escalation— missingallowPrivilegeEscalation: falserequire-run-as-nonroot— missingrunAsNonRoot: truerestrict-seccomp-strict— missingseccompProfile.type: RuntimeDefaultThe Agent CRD v1alpha2 does support these fields (
spec.declarative.deployment.podSecurityContext/.securityContext), but the upstream templates don't wire them through values.An upstream fix has been opened at kagent-dev/kagent#1977. This PR is a bridge until that releases and we bump the subchart version — at which point this
ClusterPolicycan be dropped in favour of setting the values directly.Approach
Kyverno
+(key)anchors (add-if-absent) so existing Deployments in the kagent namespace that already carry correct security context (kagent-controller, kagent-ui, klaud-coding) are not touched.The policy is conditional on
kagent.enabledand respectskagent.namespaceOverride.