Skip to content

Add accesspolicy controller - #1257

Draft
vibhor-5 wants to merge 1 commit into
Kuadrant:mainfrom
vibhor-5:add-accesspolicy-controller
Draft

Add accesspolicy controller#1257
vibhor-5 wants to merge 1 commit into
Kuadrant:mainfrom
vibhor-5:add-accesspolicy-controller

Conversation

@vibhor-5

@vibhor-5 vibhor-5 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR introduces the XAccessPolicy Controller, a Kubernetes controller designed to bridge the gap between high-level, gateway-agnostic MCP authorization intent and the concrete enforcement mechanisms provided by Kuadrant's Authorino.

It watches XAccessPolicy resources targeting Gateway objects and enables declarative, tool-level access control for MCP (Model Context Protocol) servers.

Key Responsibilities:

  1. CEL Translation: Translates domain-specific CEL variables (e.g., request.mcp.tool_name) into their data-plane equivalents (e.g., request.headers['x-mcp-toolname']) that Authorino can evaluate at runtime.
  2. Policy Aggregation: Combines multiple XAccessPolicy rules targeting the same Gateway into a single Kuadrant AuthPolicy, seamlessly handling Kuadrant's 1:1 policy-to-target constraint.

Relates to #804

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4853b54a-2c00-4735-8317-41485b59bb79

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vibhor-5
vibhor-5 force-pushed the add-accesspolicy-controller branch from 62298b1 to d529995 Compare July 8, 2026 08:58
Signed-off-by: vibhor kumar <vibhork1105@gmail.com>
@vibhor-5
vibhor-5 force-pushed the add-accesspolicy-controller branch from d529995 to a541de3 Compare July 8, 2026 08:59
SectionName *string `json:"sectionName,omitempty"`
}

type AccessPolicySpec struct {

@guicassolato guicassolato Jul 10, 2026

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.

We should probably not redefine the type in our codebase but import it from sigs.k8s.io/kube-agentic-networking.

Rebuilding the CRD from code ourselves is unexpected, as we don't own the API group, and risks becoming inconsistent with the source of the upstream. Instead, we should make having the CRD installed a requirement for using the controller.

return ctrl.Result{}, nil
}

targetRef := policy.Spec.TargetRefs[0]

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.

An XAccessPolicy resource could still target multiple different gateways, no? Are planning to support multiple targets?

Comment on lines +95 to +99
// Fetch all XAccessPolicies targeting this gateway
var policyList agenticv1alpha1.XAccessPolicyList
if err := r.List(ctx, &policyList, client.InNamespace(policy.Namespace)); err != nil {
return ctrl.Result{}, err
}

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.

Because what we'll be actually reconciling is the state of the gateways, not the policies, there's a different pattern that could be used here. Instead of implementing a reconciler for XAccessPolicy custom resources, we can implement a Gateway reconciler instead – although the name doesn't really matter. The important part is that, with this pattern, the object that the reconciler receives in the request argument is of the Gateway kind, not of the XAccessPolicy kind. We then define an event mapping function/handler that perceives XAccessPolicy-related events but enqueues calls to reconcile each of the Gateway objects referenced in the spec.targetRefs of the policy instead.

This could save from having to list all gateways for each individual policy reconciliation and, within the loop, all policies affected by the gateway, while multiple reconciliation events related to multiple XAccessPolicy resources may be enqueue – effectively to yield the same outcome but with more cycles.

See controller-runtime's EnqueueRequestsFromMapFunc.

Comment on lines +115 to +116
if rule.Source.Type == agenticv1alpha1.AuthorizationSourceTypeSPIFFE {
continue

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.

I'll have to think this through, but I think there may be something we can do regarding authentication here.

I'm thinking maybe using the plain type of authentication from the AuthPolicy when an SPIFFE ID is known to be injected by the proxy, say, for example, because it has mTLS authentication enabled.

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.

2 participants