Skip to content
This repository was archived by the owner on Nov 12, 2026. It is now read-only.

✨ Feat: AgentCard signing production readiness and Helm chart fixes - #221

Merged
usize merged 11 commits into
rossoctl:mainfrom
kevincogan:feat/agentcard-signing-production-readiness
Mar 16, 2026
Merged

usize merged 11 commits into
rossoctl:mainfrom
kevincogan:feat/agentcard-signing-production-readiness

Conversation

@kevincogan

@kevincogan kevincogan commented Mar 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

AgentCard SPIRE signing improvements and Helm chart fixes to make end-to-end signing work reliably in production.

Helm chart fixes

  • Fix duplicate RBAC rules (rbac.authorization.k8s.io block, events rule)
  • Move serviceaccounts from rbac API group to correct core API group
  • Add deployments/finalizers and statefulsets/finalizers update verb
  • Fix http-route ClusterRoleBinding referencing wrong ClusterRole name
  • Guard http-route resources with rbac.enable and add chart labels
  • Remove broken/unused webhook helper templates
  • Make imagePullPolicy configurable via values
  • Update SPIRE trust bundle defaults to match ZTWIM standard (spire-bundle/bundle.crt)

Operator improvements

  • Auto-detect and parse PEM-encoded certificates or SPIFFE JSON trust bundles
  • Add ConfigMapFetcher that reads signed cards from ConfigMap before HTTP fallback
  • AgentCard signer writes signed card to ConfigMap after signing (non-fatal on failure)
  • Simplify NetworkPolicy egress to allow-all (port-only rules silently dropped by OVN-Kubernetes)
  • Add proactive restart cooldown to prevent infinite restart loops on SVID expiry
  • Auto-populate identityBinding on auto-created AgentCards when SPIRE trust domain is configured

Demo fixes

  • Add Role/RoleBinding for agentcard-signer to create/update ConfigMaps
  • Add istio.io/dataplane-mode: none label to opt agent pods out of ambient mesh
  • Proactive restart demo captures and restores original operator args instead of hardcoding

Related issue(s)

#783 feature: Integrate AgentCard signing and verification into the Kagenti UI

(Optional) Testing Instructions

All unit tests pass (make test in kagenti-operator/).

Verified end-to-end on OpenShift (OVN-Kubernetes + Istio Ambient Mesh) from a clean environment:

  1. agentcard-spire-signing demo - Agent signed (ES256), synced, verified, bound, identity matched
  2. agentcard-auto-discovery demo - Sync controller auto-created AgentCard for labeled workload
  3. agentcard-enforcement demo - Wrong trust domain rejected, correct binding restored
  4. agentcard-proactive-restart demo - SVID expiry detected, pod restarted, key rotated

Helm chart validated with helm lint and helm template under multiple value combinations (rbac.enable=false, signatureVerification.enabled=true).

@kevincogan
kevincogan requested a review from a team as a code owner March 13, 2026 17:26
- Remove duplicate rbac.authorization.k8s.io rules block
- Move serviceaccounts from rbac API group to core API group
- Remove duplicate events rule (already in core API group)
- Add deployments/finalizers and statefulsets/finalizers update verb
- Fix http-route ClusterRoleBinding referencing wrong ClusterRole name
- Guard http-route resources with rbac.enable and add chart labels
- Remove broken/unused hasMutatingWebhooks/hasValidatingWebhooks helpers

Signed-off-by: Kevin Cogan <[email protected]>
… defaults

- Make imagePullPolicy configurable via values with IfNotPresent default
- Update SPIRE trust bundle defaults to match ZTWIM standard (spire-bundle/bundle.crt)
- Update comment to reflect PEM and SPIFFE JSON format support

Signed-off-by: Kevin Cogan <[email protected]>
- Auto-detect and parse PEM-encoded certificates or SPIFFE JSON trust bundles
- Add ConfigMapFetcher that reads signed cards from ConfigMap before HTTP fallback
- Wire ConfigMap fetcher into the AgentCard controller

Signed-off-by: Kevin Cogan <[email protected]>
- After signing, write the signed card to a ConfigMap for the operator
  to read without needing HTTP access to the agent pod
- Log warning on failure (non-fatal, operator falls back to HTTP)

Signed-off-by: Kevin Cogan <[email protected]>
…mpatibility

Port-only egress rules (DNS port 53, HTTPS port 443 without explicit
destinations) are silently dropped by OVN-Kubernetes on OpenShift,
breaking DNS resolution and external API access for agent pods.

Use allow-all egress for both permissive and restrictive policies since
the NetworkPolicy's purpose is to control ingress (who can reach the
agent), not egress. Remove unused corev1, intstr, and ptr imports.

Signed-off-by: Kevin Cogan <[email protected]>
- Add cooldown check in maybeRestartForResign to prevent infinite
  restart loops when SVID expiry grace period triggers re-signing
- Auto-populate identityBinding spec on auto-created AgentCards when
  SPIRE trust domain is configured

Signed-off-by: Kevin Cogan <[email protected]>
… args

- Add Role/RoleBinding for agentcard-signer to create/update ConfigMaps
- Add istio.io/dataplane-mode: none label to opt agent pods out of ambient mesh
- Proactive restart demo now captures and restores original operator args
  instead of hardcoding, preventing config drift

Signed-off-by: Kevin Cogan <[email protected]>
@kevincogan
kevincogan force-pushed the feat/agentcard-signing-production-readiness branch from d9f4b09 to 1cf7755 Compare March 13, 2026 17:56
Break function signatures and chained method calls exceeding 120 characters
across multiple lines. Replace empty branch with verbose-mode logging.

Signed-off-by: Kevin Cogan <[email protected]>
@kevincogan
kevincogan marked this pull request as draft March 13, 2026 18:24

@cwiklik cwiklik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Solid production-readiness improvements for AgentCard signing. The ConfigMap fallback for card fetching, PEM trust bundle support, and proactive restart cooldown are well-designed. Helm chart RBAC fixes are thorough. A few observations below.

Areas reviewed: Go (controllers, agentcard, signature), Helm chart, Shell scripts, Demo manifests
Commits: 8 commits, all DCO signed-off
Verdict: COMMENT — suggestions only, author can decide

},
},
Ingress: []netv1.NetworkPolicyIngressRule{ingressRule},
Egress: []netv1.NetworkPolicyEgressRule{{}},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The empty NetworkPolicyEgressRule{{}} means allow-all egress. The commit message explains the rationale (OVN-Kubernetes silently drops port-only rules), which makes sense. Worth a brief inline comment here documenting why allow-all was chosen, so future readers don't try to re-add port restrictions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added inline comment on the permissive policy:

// Allow all egress for verified agents so they can reach external APIs and DNS.

The restrictive policy uses targeted K8s API egress via kubeAPIEgressRules() which is self-documenting.

"configMap", cmName, "namespace", namespace)
}
} else if !apierrors.IsNotFound(err) {
fetcherLogger.Info("Error reading ConfigMap, falling back to HTTP",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Non-404 ConfigMap read errors (e.g., RBAC forbidden, network issues) are logged at Info level here. Consider Error level — a real API failure that forces fallback to HTTP is worth surfacing more prominently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Changed to fetcherLogger.Error(err, "Failed to read ConfigMap, falling back to HTTP", ...) with the error as a structured first argument per logr convention.


podAnnotations := getPodTemplateAnnotations(acc)
if ts, ok := podAnnotations[AnnotationResignTrigger]; ok {
if lastTrigger, err := time.Parse(time.RFC3339, ts); err == nil && time.Since(lastTrigger) < grace {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: If time.Parse fails on a malformed annotation, the err == nil check silently skips the cooldown — the pod could restart immediately. Consider logging when the timestamp is unparseable so operators can detect annotation corruption.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Restructured the conditional to explicitly handle the parse failure:

lastTrigger, err := time.Parse(time.RFC3339, ts)
if err != nil {
     agentCardLogger.Info("Ignoring malformed resign-trigger annotation",
         "value", ts, "error", err.Error())
 } else if time.Since(lastTrigger) < grace {
     return
 }

Logged at Info since it is recoverable. The reconciler proceeds to evaluate whether a restart is needed.

@@ -131,3 +136,99 @@ func TestGetServiceURL(t *testing.T) {
t.Errorf("GetServiceURL: got %q, want %q", got, want)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Good coverage of ConfigMap found, not-found, and invalid-JSON scenarios. Consider adding a case where the ConfigMap exists but the expected key is missing (empty Data map) to exercise that edge.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TestConfigMapFetcher_MissingKey. Creates a ConfigMap with an empty Data map and verifies fallback to HTTP.

# Restores the operator grace period to 30m without overwriting other args.
#

set -eu

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: set -eu is missing -o pipefail. Without it, failures in piped commands (e.g., kubectl get ... | grep ...) are silently ignored.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated all 8 demo scripts (run + teardown) from set -eu to set -euo pipefail.

@usize usize left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, pending the followups @cwiklik requested. Thanks for fixing up the demos.

Restrictive NetworkPolicies for unverified agents now allow egress only
to dynamically discovered K8s API server endpoints on port 6443, instead
of deny-all. This permits the agentcard-signer init container to write
signed ConfigMaps while fully isolating unverified agents from all other
outbound traffic.

- Add KubeAPIServerCIDRs discovery from kubernetes Endpoints at startup
- Add kubeAPIEgressRules() to construct targeted egress rules
- Grant operator RBAC permission to read endpoints
- Add inline comment on permissive policy explaining allow-all egress

Signed-off-by: Kevin Cogan <[email protected]>
- Upgrade ConfigMap read error log from Info to Error level (fetcher.go)
- Log warning when resign-trigger annotation timestamp is malformed
- Add TestConfigMapFetcher_MissingKey for empty Data map edge case
- Add -o pipefail to all demo scripts for strict pipe error handling

Signed-off-by: Kevin Cogan <[email protected]>
@kevincogan
kevincogan marked this pull request as ready for review March 15, 2026 12:57
@kevincogan
kevincogan requested a review from cwiklik March 15, 2026 12:58
@kevincogan

Copy link
Copy Markdown
Contributor Author

Note on allow-all egress for verified agents

The permissive NetworkPolicy currently uses allow-all egress for verified agents. The original scoped egress rules on main (verified peers + DNS + K8s API only) were silently dropped by OVN-Kubernetes on OpenShift, breaking DNS resolution and external API access. Allow-all is the working baseline for now.

I will be opening a follow-up GitHub issue to add per-agent egress scoping possibly via an optional spec.networkPolicy.egressRules field on the AgentCard CRD. This will let operators define custom egress rules per agent (e.g. allow HTTPS to specific CIDRs + DNS) while defaulting to allow-all when not configured, so agents that need external service access (such as external LLM APIs) continue to work without disruption.

CC: @usize @cwiklik

RESTORED_ARGS=$(echo "$CURRENT_ARGS" | python3 -c "
import sys, json, re
args = json.loads(sys.stdin.read())
patched = [re.sub(r'^--svid-expiry-grace-period=.*', '--svid-expiry-grace-period=30m', a) for a in args]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
patched = [re.sub(r'^--svid-expiry-grace-period=.*', '--svid-expiry-grace-period=30m', a) for a in args]
patched = [re.sub(r'^--svid-expiry-grace-period=[^[:space:]]+', '--svid-expiry-grace-period=30m', a) for a in args]

I haven't actually tested this, but the regex you used looks dangerous ... if there are any other args, won't the .* encompass them?

@kevincogan kevincogan Mar 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on hardening the regex. The .* was technically safe since each arg is an individual string in the JSON array, so there's no risk of spanning across other args. That said, I've tightened it to \S+ to be more explicit about intent. Worth noting that the POSIX [^[:space:]] syntax in the suggestion isn't supported by Python's re module, so \S+ is the correct Python equivalent.

fetcher := NewConfigMapFetcher(fakeClient)

card, err := fetcher.Fetch(context.Background(), A2AProtocol, "", "my-agent", "test-ns")
if err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use github.com/onsi/gomega and Expect() the way agentcard_networkpolicy_controller_test.go does? To shorten all these != and err != nil conditions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I converted the file to use gomega with NewGomegaWithT(t) to match the controller test style. All 11 tests pass.

- Harden regex in teardown-demo.sh from .* to \S+ for defensive coding
- Convert fetcher_test.go assertions to gomega for project consistency
Signed-off-by: Kevin Cogan <[email protected]>

Signed-off-by: Kevin Cogan <[email protected]>
@usize
usize merged commit 259a618 into rossoctl:main Mar 16, 2026
5 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants