Documentation
¶
Overview ¶
Package security provides the session-hijack-prevention decorator for vMCP sessions. It binds a session to the identity that created it: issuer and subject, plus route, client_id and actor for delegated identities. It validates that every subsequent request comes from the same identity.
Session bindings are stored as plaintext at rest in the session metadata (see pkg/vmcp/session/binding for the format and trust-boundary statement). The binding is NOT a credential; it identifies but does not authenticate. Callers must validate the request's token independently before passing the resulting *auth.Identity to validateCaller.
Index ¶
- func BindSession(session sessiontypes.MultiSession, bindingID string) (sessiontypes.MultiSession, error)
- func ResolveBinding(identity *auth.Identity) (string, error)
- func RestoreSessionBinding(session sessiontypes.MultiSession, storedBinding string) (sessiontypes.MultiSession, error)
- func ValidateCaller(storedBinding string, caller *auth.Identity) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindSession ¶ added in v0.29.0
func BindSession( session sessiontypes.MultiSession, bindingID string, ) (sessiontypes.MultiSession, error)
BindSession wraps a session with identity-binding validation. It writes bindingID, as returned by ResolveBinding, into session metadata under MetadataKeyIdentityBinding and returns a decorator that validates the caller on every operation.
Returns an error BEFORE writing anything to the session metadata if session is nil or bindingID is neither the unauthenticated sentinel nor a valid binding — preserving the invariant that a session always has a valid MetadataKeyIdentityBinding value once written.
func ResolveBinding ¶ added in v0.70.0
ResolveBinding determines the metadata binding for a new session. It returns binding.UnauthenticatedSentinel for anonymous identities, so a result equal to the sentinel means the session is anonymous, and an error if a required binding cannot be derived. Call it once per session and pass the result to BindSession.
func RestoreSessionBinding ¶ added in v0.29.0
func RestoreSessionBinding( session sessiontypes.MultiSession, storedBinding string, ) (sessiontypes.MultiSession, error)
RestoreSessionBinding recreates the session-binding decorator from a persisted binding string read out of session metadata. Use this when reconstructing a MultiSession after a pod restart or cross-pod failover.
This function is the symmetric counterpart of BindSession for the restore path. It is invoked by the session factory after RestoreSession deserializes the binding from session metadata. Unlike BindSession, it does NOT write metadata — the factory has already restored the metadata layer separately.
storedBinding must be either:
- binding.UnauthenticatedSentinel (the session was anonymous), or
- a valid bound binding (binding.Parse returns ok), including the delegated forms.
Anything else (empty string, malformed value) is rejected as corrupted metadata.
func ValidateCaller ¶ added in v0.30.0
ValidateCaller checks caller against a stored identity-binding string (the value persisted under MetadataKeyIdentityBinding). It reproduces the decorator's per-request check for call paths that do not go through the [sessionBindingDecorator] — notably the Serve transport path, where the advertised set and call routing are owned by the core but identity binding must still be enforced by the session layer.
allowAnonymous is derived from storedBinding: an anonymous session stores the UnauthenticatedSentinel, so IsUnauthenticated(storedBinding) is exactly the allowAnonymous flag BindSession recorded (ResolveBinding decides whether the session is anonymous, and BindSession writes the value it resolved).
Types ¶
This section is empty.