access

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

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

View Source
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
)
View Source
const DefaultMCPResourceNamespace = topology.DefaultServerNamespace

DefaultMCPResourceNamespace is used when a ServerReference or access resource omits a namespace.

View Source
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.

View Source
const ServerRetiringAnnotation = "mcpruntime.org/retiring"

ServerRetiringAnnotation prevents issuing access or republishing a server while a failed retirement is awaiting a retry.

View Source
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

func IsMCPServerNotFoundForRef(err error) bool

IsMCPServerNotFoundForRef returns true if err is an *ErrMCPServerNotFound.

func NormalizeEgressHost

func NormalizeEgressHost(host string) string

NormalizeEgressHost trims and lower-cases a declared host.

func ServerEgressEqual

func ServerEgressEqual(aHosts []string, aPorts []int32, bHosts []string, bPorts []int32) bool

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 ToJSON

func ToJSON(obj interface{}) ([]byte, error)

ToJSON converts a grant or session to JSON bytes.

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

func ValidateOptionalResourceName(field, name string) error

ValidateOptionalResourceName is ValidateResourceName but treats empty as valid. Use for optional fields like serverRef.namespace.

func ValidateResourceName

func ValidateResourceName(field, name string) error

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

func ValidateServerEgress(hosts []string, ports []int32) error

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 AgentID

type AgentID string

AgentID identifies an authenticated agent principal.

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.

const (
	GrantModeEnforce GrantMode = "enforce"
	GrantModeMonitor GrantMode = "monitor"
)

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 HumanID

type HumanID string

HumanID identifies an authenticated human principal.

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

type SecretKeyRef struct {
	Name string `json:"name"`
	Key  string `json:"key"`
}

SecretKeyRef references a secret key.

type ServerName

type ServerName string

ServerName identifies an MCPServer resource by name.

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 TeamID

type TeamID string

TeamID identifies a stable platform team principal.

type Time

type Time struct {
	time.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 NewTime

func NewTime(t time.Time) Time

NewTime wraps t.

func (*Time) DeepCopy

func (t *Time) DeepCopy() *Time

DeepCopy returns a copy of the receiver, or nil for a nil receiver.

func (*Time) DeepCopyInto

func (t *Time) DeepCopyInto(out *Time)

DeepCopyInto copies the receiver into out, like metav1.Time.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler with metav1.Time semantics.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) error

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"
)

Directories

Path Synopsis
Package specvalidation owns the shared structural grant/session contract.
Package specvalidation owns the shared structural grant/session contract.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL