Skip to content

Commit d1ea251

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

File tree

4 files changed

+371
-0
lines changed

4 files changed

+371
-0
lines changed

api/v1alpha1/mcp_route.go

Lines changed: 41 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,42 @@ 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.
249+
//
250+
// If a request calls a tool in this list, this rule is considered a match.
251+
// If this request has a valid JWT token that contains all the required scopes defined in this rule,
252+
// the request will be allowed. If not, the request will be denied.
253+
//
254+
// +kubebuilder:validation:MinItems=1
255+
// +kubebuilder:validation:MaxItems=16
256+
Tools []string `json:"tools"`
257+
258+
// Scopes defines the list of JWT scopes required for the rule.
259+
// If multiple scopes are specified, all scopes must be present in the JWT for the rule to match.
260+
//
261+
// +kubebuilder:validation:MinItems=1
262+
// +kubebuilder:validation:MaxItems=16
263+
Scopes []egv1a1.JWTScope `json:"scopes"`
264+
}
265+
225266
// JWKS defines how to obtain JSON Web Key Sets (JWKS) either from a remote HTTP/HTTPS endpoint or from a local source.
226267
// +kubebuilder:validation:XValidation:rule="has(self.remoteJWKS) || has(self.localJWKS)", message="either remoteJWKS or localJWKS must be specified."
227268
// +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)