Documentation
¶
Overview ¶
Package access is the Kubernetes-free model of MCP access governance.
It defines grants (MCPAccessGrantSpec and status), agent sessions, the request types for applying them, summaries, resource-name validation and server references, plus the allow and deny decisions they produce. The specvalidation subpackage holds the pure spec checks shared with the CRD types. Persistence is not here: the runtime API stores these objects through its own Kubernetes adapter, and platform-api owns sessions in Postgres.
It depends only on policy, sessionstate and topology, so any service can use it without pulling in a Kubernetes client.
Index ¶
- Constants
- func IsMCPServerNotFoundForRef(err error) bool
- func NormalizeEgressHost(host string) string
- func ServerEgressEqual(aHosts []string, aPorts []int32, bHosts []string, bPorts []int32) bool
- func ToJSON(obj interface{}) ([]byte, error)
- func ValidateGrantApplyRequest(req *GrantApplyRequest, now time.Time) error
- func ValidateOptionalResourceName(field, name string) error
- func ValidateResourceName(field, name string) error
- func ValidateServerEgress(hosts []string, ports []int32) error
- func ValidateSessionApplyRequest(req *SessionApplyRequest) error
- type AgentID
- type Condition
- type ConditionStatus
- type ErrMCPServerNotFound
- type GrantApplyRequest
- type GrantMode
- type GrantSummary
- type HumanID
- type MCPAccessGrantSpec
- type MCPAccessGrantStatus
- type MCPAgentSessionSpec
- type MCPAgentSessionStatus
- type Namespace
- type PolicyDecision
- type PrimitiveRule
- type SecretKeyRef
- type ServerName
- type ServerReference
- type SessionApplyRequest
- type SessionSummary
- type SubjectRef
- type TeamID
- type Time
- type ToolRule
- type ToolSideEffect
- type TrustLevel
Constants ¶
const ( // MaxServerEgressHosts bounds spec.egress.hosts. MaxServerEgressHosts = 32 // MaxServerEgressPorts bounds spec.egress.ports. MaxServerEgressPorts = 8 // DefaultServerEgressPort is used when spec.egress.ports is empty. DefaultServerEgressPort int32 = 443 )
const DefaultMCPResourceNamespace = topology.DefaultServerNamespace
DefaultMCPResourceNamespace is used when a ServerReference or access resource omits a namespace.
const EgressApprovedAnnotation = "mcpruntime.org/egress-approved"
EgressApprovedAnnotation marks an MCPServer whose declared external egress (spec.egress) a platform administrator approved. Only the admin "server egress approve" path sets it; the platform publish API never copies it from a request and drops it when the declaration changes.
const ServerRetiringAnnotation = "mcpruntime.org/retiring"
ServerRetiringAnnotation prevents issuing access or republishing a server while a failed retirement is awaiting a retry.
const ServerUIDAnnotation = "mcpruntime.org/server-uid"
ServerUIDAnnotation fences delayed authorization writes from an earlier deployment when the same namespace/name is published again.
Variables ¶
This section is empty.
Functions ¶
func IsMCPServerNotFoundForRef ¶
IsMCPServerNotFoundForRef returns true if err is an *ErrMCPServerNotFound.
func NormalizeEgressHost ¶
NormalizeEgressHost trims and lower-cases a declared host.
func ServerEgressEqual ¶
ServerEgressEqual reports whether two declarations request the same hosts and ports. Order and host case are ignored and an empty port list means the default port.
func ValidateGrantApplyRequest ¶
func ValidateGrantApplyRequest(req *GrantApplyRequest, now time.Time) error
ValidateGrantApplyRequest preserves HTTP apply normalization and validates all non-authority fields. Live server, team, agent and grant authorization remains the runtime API's responsibility.
func ValidateOptionalResourceName ¶
ValidateOptionalResourceName is ValidateResourceName but treats empty as valid. Use for optional fields like serverRef.namespace.
func ValidateResourceName ¶
ValidateResourceName returns nil if name is a valid Kubernetes object name (DNS-1123 subdomain, <= 253 characters). The field argument is used in the error message so callers can distinguish, e.g., "name" from "serverRef.name".
func ValidateServerEgress ¶
ValidateServerEgress validates a server's declared external egress: DNS names only (no wildcards, IP literals, URLs or ports), public-looking names, 1-32 unique hosts and 1-65535 unique TCP ports (at most 8).
func ValidateSessionApplyRequest ¶
func ValidateSessionApplyRequest(req *SessionApplyRequest) error
ValidateSessionApplyRequest does not reject past expiry: admin session apply also imports or revokes historical sessions, preserving the existing contract.
Types ¶
type Condition ¶
type Condition struct {
Type string `json:"type"`
Status ConditionStatus `json:"status"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
LastTransitionTime Time `json:"lastTransitionTime"`
Reason string `json:"reason"`
Message string `json:"message"`
}
Condition mirrors metav1.Condition field for field, including JSON tags.
type ConditionStatus ¶
type ConditionStatus string
ConditionStatus is the status value of a Condition.
type ErrMCPServerNotFound ¶
type ErrMCPServerNotFound struct {
Name, Namespace string
}
ErrMCPServerNotFound is returned by AssertMCPServerRef when the target MCPServer is missing.
func (*ErrMCPServerNotFound) Error ¶
func (e *ErrMCPServerNotFound) Error() string
type GrantApplyRequest ¶
type GrantApplyRequest struct {
Mode *GrantMode `json:"mode,omitempty"`
Name string `json:"name"`
Namespace string `json:"namespace"`
ServerRef ServerReference `json:"serverRef"`
Subject SubjectRef `json:"subject"`
MaxTrust TrustLevel `json:"maxTrust"`
AllowedSideEffects []ToolSideEffect `json:"allowedSideEffects"`
PolicyVersion string `json:"policyVersion"`
Disabled *bool `json:"disabled,omitempty"`
ExpiresAt *Time `json:"expiresAt,omitempty"`
ToolRules []ToolRule `json:"toolRules"`
PrimitiveRules []PrimitiveRule `json:"primitiveRules,omitempty"`
}
GrantApplyRequest is the platform apply contract shared by the CLI and API.
type GrantMode ¶
type GrantMode string
GrantMode controls whether a grant enforces or shadows its restrictions.
type GrantSummary ¶
type GrantSummary struct {
Mode GrantMode `json:"mode,omitempty"`
Name string `json:"name"`
Namespace string `json:"namespace"`
ServerRef ServerReference `json:"serverRef"`
Subject SubjectRef `json:"subject"`
MaxTrust TrustLevel `json:"maxTrust"`
AllowedSideEffects []ToolSideEffect `json:"allowedSideEffects,omitempty"`
ExpiresAt *Time `json:"expiresAt,omitempty"`
Disabled bool `json:"disabled"`
Age string `json:"age"`
}
GrantSummary provides a simplified view of a grant for UI display.
type MCPAccessGrantSpec ¶
type MCPAccessGrantSpec struct {
Mode GrantMode `json:"mode,omitempty"`
ServerRef ServerReference `json:"serverRef"`
Subject SubjectRef `json:"subject"`
MaxTrust TrustLevel `json:"maxTrust,omitempty"`
AllowedSideEffects []ToolSideEffect `json:"allowedSideEffects,omitempty"`
PolicyVersion string `json:"policyVersion,omitempty"`
Disabled bool `json:"disabled,omitempty"`
ExpiresAt *Time `json:"expiresAt,omitempty"`
ToolRules []ToolRule `json:"toolRules,omitempty"`
PrimitiveRules []PrimitiveRule `json:"primitiveRules,omitempty"`
}
MCPAccessGrantSpec defines who can use which MCP server and with what trust ceiling.
type MCPAccessGrantStatus ¶
type MCPAccessGrantStatus struct {
Phase string `json:"phase,omitempty"`
Message string `json:"message,omitempty"`
Conditions []Condition `json:"conditions,omitempty"`
}
MCPAccessGrantStatus captures observed grant state.
type MCPAgentSessionSpec ¶
type MCPAgentSessionSpec struct {
ServerRef ServerReference `json:"serverRef"`
Subject SubjectRef `json:"subject"`
ConsentedTrust TrustLevel `json:"consentedTrust,omitempty"`
ExpiresAt *Time `json:"expiresAt,omitempty"`
Revoked bool `json:"revoked,omitempty"`
UpstreamTokenSecretRef *SecretKeyRef `json:"upstreamTokenSecretRef,omitempty"`
PolicyVersion string `json:"policyVersion,omitempty"`
}
MCPAgentSessionSpec defines a consented server-side agent session.
type MCPAgentSessionStatus ¶
type MCPAgentSessionStatus struct {
Phase string `json:"phase,omitempty"`
Message string `json:"message,omitempty"`
Conditions []Condition `json:"conditions,omitempty"`
}
MCPAgentSessionStatus captures observed session state.
type Namespace ¶
type Namespace string
Namespace identifies a Kubernetes namespace that contains MCP runtime resources.
func ResolveServerRefNamespace ¶
func ResolveServerRefNamespace(ref ServerReference) Namespace
ResolveServerRefNamespace returns the namespace to resolve serverRef against. Empty or whitespace ref.Namespace defaults to DefaultMCPResourceNamespace.
type PolicyDecision ¶
type PolicyDecision string
PolicyDecision defines policy decisions for tool access.
const ( DecisionAllow PolicyDecision = "allow" DecisionDeny PolicyDecision = policypkg.DecisionDeny DecisionAudit PolicyDecision = "audit" )
type PrimitiveRule ¶
type PrimitiveRule struct {
Kind string `json:"kind"`
Pattern string `json:"pattern"`
Decision PolicyDecision `json:"decision"`
}
PrimitiveRule scopes access to MCP resources, prompts or skills.
type SecretKeyRef ¶
SecretKeyRef references a secret key.
type ServerReference ¶
type ServerReference struct {
Name ServerName `json:"name"`
Namespace Namespace `json:"namespace,omitempty"`
}
ServerReference identifies an MCPServer.
type SessionApplyRequest ¶
type SessionApplyRequest struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
ServerRef ServerReference `json:"serverRef"`
Subject SubjectRef `json:"subject"`
ConsentedTrust TrustLevel `json:"consentedTrust"`
ExpiresAt *Time `json:"expiresAt"`
Revoked *bool `json:"revoked,omitempty"`
PolicyVersion string `json:"policyVersion"`
GrantName string `json:"grantName,omitempty"`
GrantNamespace string `json:"grantNamespace,omitempty"`
}
SessionApplyRequest is the administrative platform session input contract.
type SessionSummary ¶
type SessionSummary struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
ServerRef ServerReference `json:"serverRef"`
Subject SubjectRef `json:"subject"`
ConsentedTrust TrustLevel `json:"consentedTrust"`
Revoked bool `json:"revoked"`
ExpiresAt *Time `json:"expiresAt,omitempty"`
Age string `json:"age"`
PolicyVersion string `json:"policyVersion,omitempty"`
ServerUID string `json:"serverUID,omitempty"`
GrantName string `json:"grantName,omitempty"`
GrantNamespace string `json:"grantNamespace,omitempty"`
RevokedAt string `json:"revokedAt,omitempty"`
RevocationCause string `json:"revocationCause,omitempty"`
}
SessionSummary provides a simplified view of a session for UI display.
type SubjectRef ¶
type SubjectRef struct {
HumanID HumanID `json:"humanID,omitempty"`
AgentID AgentID `json:"agentID,omitempty"`
TeamID TeamID `json:"teamID,omitempty"`
}
SubjectRef identifies the human and optional agent a grant or session applies to.
type Time ¶
Time is a point in time that marshals exactly like Kubernetes metav1.Time: RFC 3339 in UTC at second precision, "null" when zero, and local time when parsed. It keeps the grant and session wire format unchanged without making the access domain depend on Kubernetes API types.
func (*Time) DeepCopyInto ¶
DeepCopyInto copies the receiver into out, like metav1.Time.
func (Time) MarshalJSON ¶
MarshalJSON implements json.Marshaler with metav1.Time semantics.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler with metav1.Time semantics.
type ToolRule ¶
type ToolRule struct {
Name string `json:"name"`
Decision PolicyDecision `json:"decision"`
RequiredTrust TrustLevel `json:"requiredTrust,omitempty"`
}
ToolRule controls access to an individual MCP tool.
type ToolSideEffect ¶
type ToolSideEffect string
ToolSideEffect classifies whether a tool reads, mutates, or destructively changes state.
const ( SideEffectRead ToolSideEffect = "read" SideEffectWrite ToolSideEffect = "write" SideEffectDestructive ToolSideEffect = "destructive" )
type TrustLevel ¶
type TrustLevel string
TrustLevel defines trust levels for access control.
const ( TrustLow TrustLevel = "low" TrustMedium TrustLevel = "medium" TrustHigh TrustLevel = "high" )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package specvalidation owns the shared structural grant/session contract.
|
Package specvalidation owns the shared structural grant/session contract. |