Skip to content

Commit 877d598

Browse files
committed
api for mcp authorization
Signed-off-by: Huabing Zhao <[email protected]>
1 parent 2fa6b27 commit 877d598

File tree

4 files changed

+372
-0
lines changed

4 files changed

+372
-0
lines changed

api/v1alpha1/mcp_route.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ type MCPRouteSecurityPolicy struct {
187187
//
188188
// +optional
189189
APIKeyAuth *egv1a1.APIKeyAuth `json:"apiKeyAuth,omitempty"`
190+
191+
// Authorization defines the configuration for the MCP spec compatible authorization.
192+
//
193+
// +optional
194+
Authorization *MCPRouteAuthorization `json:"authorization,omitempty"`
190195
}
191196

192197
// MCPRouteOAuth defines a MCP spec compatible OAuth authentication configuration for a MCPRoute.
@@ -222,6 +227,43 @@ type MCPRouteOAuth struct {
222227
ProtectedResourceMetadata ProtectedResourceMetadata `json:"protectedResourceMetadata"`
223228
}
224229

230+
// MCPRouteAuthorization defines the authorization configuration for a MCPRoute.
231+
type MCPRouteAuthorization struct {
232+
// Rules defines a list of authorization rules.
233+
// These rules are evaluated in order, the first matching rule will be applied,
234+
// and the rest will be skipped.
235+
//
236+
// +optional
237+
Rules []egv1a1.AuthorizationRule `json:"rules,omitempty"`
238+
239+
// DefaultAction defines the default action to be taken if no rules match.
240+
// If not specified, the default action is Deny.
241+
// +optional
242+
DefaultAction *egv1a1.AuthorizationAction `json:"defaultAction"`
243+
}
244+
245+
// MCPRouteAuthorizationRule defines an authorization rule for MCPRoute based on the MCP authorization spec.
246+
// Reference: https://modelcontextprotocol.io/specification/draft/basic/authorization#scope-challenge-handling
247+
type MCPRouteAuthorizationRule struct {
248+
// Tools defines the list of tool names this rule applies to. The name must be a fully qualified tool name including the backend name.
249+
// For example, "mcp-backend-name__tool-name".
250+
//
251+
// If a request calls a tool in this list, this rule is considered a match.
252+
// If this request has a valid JWT token that contains all the required scopes defined in this rule,
253+
// the request will be allowed. If not, the request will be denied.
254+
//
255+
// +kubebuilder:validation:MinItems=1
256+
// +kubebuilder:validation:MaxItems=16
257+
Tools []string `json:"tools"`
258+
259+
// Scopes defines the list of JWT scopes required for the rule.
260+
// If multiple scopes are specified, all scopes must be present in the JWT for the rule to match.
261+
//
262+
// +kubebuilder:validation:MinItems=1
263+
// +kubebuilder:validation:MaxItems=16
264+
Scopes []egv1a1.JWTScope `json:"scopes"`
265+
}
266+
225267
// JWKS defines how to obtain JSON Web Key Sets (JWKS) either from a remote HTTP/HTTPS endpoint or from a local source.
226268
// +kubebuilder:validation:XValidation:rule="has(self.remoteJWKS) || has(self.localJWKS)", message="either remoteJWKS or localJWKS must be specified."
227269
// +kubebuilder:validation:XValidation:rule="!(has(self.remoteJWKS) && has(self.localJWKS))", message="remoteJWKS and localJWKS cannot both be specified."

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)