identitybroker

package
v0.0.52 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package identitybroker is the in-process core of the agent identity broker.

Service is the contract for the whole identity broker: Mecatl calls it, and only it, whether the broker runs in process or as its own service. Core is the broker side of that contract, with the authenticated workload on every call; NewInProcess joins the two through an Authenticator. Broker is the Core, and package conformance holds the contract tests every implementation passes.

New validates explicitly supplied configuration, an ECDSA P-256 (ES256) signing capability, and already-loaded definition records, and returns a Broker holding an independently owned snapshot of them, and no broker sessions. The broker signs agent credentials (JWT-SVIDs) with the signer and verifies them itself, for Mecatl's calls and for AS-1. Every agent has the shared agent identity: one ag_ identifier generated per process, and a SPIFFE ID under one shared path that differs only by incarnation. The snapshot holds only definitions the broker loads itself, operator-loaded global definitions and system built-ins; repository definitions never enter it.

ClientAssertionSigner mints the client assertions the broker authenticates with at AS-1 and AS-2, with the broker client key, separate from the agent issuer key; the token-endpoint client is an adapter. With WithAuthServer, session open converts the user's access token at AS-1 through that adapter into a refresh token the session holds. With WithGateway, AuthorizeCall authorizes each MCP gateway call with its own gateway token: it exchanges the session's refresh token at AS-1 (IDJAGIssuer) for an ID-JAG, records it (Recorder), and redeems it at the gateway's AS-2 (GatewayAuthServer), bound with BindGatewayAS2. The package performs no file, environment, or network access; source loading and transport belong in adapters that call it.

Index

Constants

View Source
const (
	// BrokerClientID is the identity broker's OAuth client at AS-1 and AS-2.
	BrokerClientID = "mecatl"
	// MaxClientAssertionLifetime is the largest exp - iat of a client
	// assertion, and the lifetime used when none is configured.
	MaxClientAssertionLifetime = 60 * time.Second
)
View Source
const (
	// SourceGlobal is the source of the operator's global definitions.
	SourceGlobal = "global"
	// SourceSystem is the source of the built-in definitions each Mecatl
	// release ships.
	SourceSystem = "system"

	// BuiltinMain names the built-in definition of the main agent of a session
	// started without a named definition: system/main.
	BuiltinMain = "main"
	// BuiltinExplorer names the built-in definition of the child agent of a
	// subagent call that names no definition: system/explorer.
	BuiltinExplorer = "explorer"
)

Definition sources and built-in names. They become segments of agent SPIFFE IDs, so they are part of the registration contract, not details of the loader that produces the records.

View Source
const (
	MethodToolsCall = "tools/call"
	MethodToolsList = "tools/list"
)

The MCP methods AuthorizeCallRequest.Method names.

View Source
const (
	// ExchangeGrantType is the RFC 9396 authorization_details type of
	// ToolHive's exchange grant: a refresh token whose use is fixed when it is
	// issued.
	ExchangeGrantType = "https://toolhive.dev/exchange_grant"
	// TokenTypeIDJAG is the ID-JAG token type, the only output the broker's
	// grants issue.
	TokenTypeIDJAG = "urn:ietf:params:oauth:token-type:id-jag" // #nosec G101 -- token type URN, not a credential.
	// TokenTypeRefreshToken is the RFC 8693 refresh token type, the token a
	// session-open exchange issues.
	TokenTypeRefreshToken = "urn:ietf:params:oauth:token-type:refresh_token" // #nosec G101 -- token type URN, not a credential.
)

Token types and the authorization_details type of the session-open exchange (design step (3)).

View Source
const DigestSHA256 = "sha256"

DigestSHA256 is the only digest algorithm this package accepts.

View Source
const MaxCredentialLifetime = time.Hour

MaxCredentialLifetime bounds Config.CredentialLifetime. Agent credentials are short-lived bearer tokens; the bound limits how long a stolen one stays usable and rejects unit mistakes such as hours entered for minutes. The value is an interim choice: the agent identity design does not set one.

View Source
const MaxSegmentBytes = 63

MaxSegmentBytes bounds DefinitionRef.Source and DefinitionRef.Name. Both become segments of agent SPIFFE IDs, and the cap keeps the longest planned ID within the 2,048 bytes SPIFFE-ID section 2.3 advises against exceeding.

View Source
const TokenTypeJWT = "urn:ietf:params:oauth:token-type:jwt" // #nosec G101 -- token type URN, not a credential.

TokenTypeJWT is the RFC 8693 JWT token type, the type of the agent SVID a per-call ID-JAG exchange sends as its actor token.

Variables

View Source
var (
	ErrInvalidConfig         = errors.New("identitybroker: invalid configuration")
	ErrInvalidSigner         = errors.New("identitybroker: invalid signer")
	ErrInvalidDefinition     = errors.New("identitybroker: invalid definition record")
	ErrConflictingDefinition = errors.New("identitybroker: conflicting definition records")
)

Errors returned by New and DefinitionRecord.Validate. Each returned error wraps exactly one of them, so a transport adapter can map failures with errors.Is.

View Source
var ErrMalformedResponse = errors.New("identitybroker: the authorization server's response could not be decoded")

ErrMalformedResponse reports a success response from AS-1 or AS-2 the broker cannot decode. The server may have issued a token the broker cannot read, so session open closes the session, as for a mismatched answer. Errors wrapping it also wrap ErrTransportConfiguration.

View Source
var ErrNoResponse = errors.New("identitybroker: no response from the authorization server")

ErrNoResponse reports a token or revocation endpoint request to AS-1 or AS-2 that got no response, such as a dropped connection: the server may or may not have processed it. Callers may retry once, with a new client assertion. At session open the retry resends the same access token: if AS-1 had converted it, the resend is refused with token_used and the client must refresh its access token and open again (design step (3), "Lost response"), which applies to a 502 or 504 there too.

View Source
var ErrTransportConfiguration = errors.New("identitybroker: the connection to the authorization server is misconfigured")

ErrTransportConfiguration reports a request to AS-1 or AS-2 that failed because the connection's configuration is wrong, such as a server certificate that does not verify against the configured trust, or because a success response could not be decoded, which points at the wrong or an incompatible server (see ErrMalformedResponse): a configuration fault, not an outage, so it is not retried.

Functions

func IsConfigurationFault added in v0.0.52

func IsConfigurationFault(err error) bool

IsConfigurationFault reports whether err is a failure the design's error reasons treat as a configuration fault or broker bug (gRPC INTERNAL): ErrTransportConfiguration, or a refusal with invalid_client, unauthorized_client, or invalid_target, or with the reason subject_token_audience, subject_token_source_client, grant_invalid, upstream_subject_missing, sub_id_missing, dpop_not_supported, bound_elapsed, or resource_denied, or any other refusal without a known reason code. A description that does not follow the reason-code convention, such as prose, counts as no reason. A transient refusal (see IsUnavailable) never is. A failed client authentication is always invalid_client. A caller needing a reason-specific outcome, such as an AS-2 invalid_grant with no reason, checks the ServerRefusal first. Session open does: AS-1 refuses an access token a fresh one could replace with subject_token_invalid, which session open reports as subject_invalid; an invalid_request with no reason is a broker bug or configuration fault there too (design step (3)).

func IsUnavailable added in v0.0.52

func IsUnavailable(err error) bool

IsUnavailable reports whether err is a retryable infrastructure failure (gRPC UNAVAILABLE), not a denial: ErrNoResponse, or a transient refusal.

Types

type AgentRef

type AgentRef struct {
	Subject string
}

AgentRef refers to a registered agent instance by its canonical subject, which the caller checks matches the instance it registered. The zero value refers to no agent.

func (AgentRef) IsZero

func (a AgentRef) IsZero() bool

IsZero reports whether a refers to no agent.

type AuthServer added in v0.0.52

type AuthServer interface {
	Exchange(ctx context.Context, req TokenExchange) (TokenExchangeResult, error)
}

AuthServer is AS-1's token endpoint as session open uses it: the RFC 8693 exchange of the user's access token for a refresh token that issues only ID-JAGs. The adapter authenticates as BrokerClientID with a fresh client assertion on every call and serialises req as it is. A refusal is a *ServerRefusal; a request with no response wraps ErrNoResponse; a misconfigured connection wraps ErrTransportConfiguration; a success response it cannot decode wraps both ErrMalformedResponse and ErrTransportConfiguration. Errors never carry a token.

type Authenticator

type Authenticator interface {
	Authenticate(ctx context.Context) (Workload, error)
}

Authenticator decides which workload is calling. A failure is an *Error, normally with CodeUnauthenticated or CodePermissionDenied.

type Authorization

type Authorization struct {
	// GatewayToken is the token the call is dispatched with, obtained for
	// this call alone.
	GatewayToken Token
	// ExpiresAt is the broker's use-before deadline for GatewayToken: the
	// earliest of the ID-JAG's exp, AS-2's expires_in, and the token's own
	// exp. The authorization server may keep the token valid longer.
	ExpiresAt time.Time
	// AttemptID identifies this authorization, so a caller whose token the
	// gateway rejects reports it in AuthorizeCallRequest.RejectedAttemptID.
	AttemptID string
}

Authorization is an allowed MCP call.

type AuthorizeCallRequest

type AuthorizeCallRequest struct {
	SessionID string
	// Credential is the acting agent's credential from RegisterAgent. The
	// broker identifies the acting agent from it.
	Credential Token
	// OperationID identifies this call.
	OperationID string
	// RunID is the run the call belongs to.
	RunID string
	// DelegationID is the delegation the run acts under; empty for a root
	// run.
	DelegationID string
	// RunOwner is the owner the run acts for.
	RunOwner Owner
	// Method is MethodToolsCall or MethodToolsList.
	Method string
	// Server is the gateway backend the call is routed to, such as "github".
	Server string
	// Tool is the exact tool name the call sends as params.name, such as
	// "github.pull_request_read". Set for tools/call only.
	Tool string
	// ArgumentsSHA256 is the argument hash, 64 lowercase hex characters, as
	// credentials-and-lifecycle.md step (8), "The argument hash", defines it:
	// the SHA-256 of the RFC 8785 (JCS) serialization of params.arguments as
	// sent, or of {} when there are none, not of the raw request bytes. Set
	// for tools/call only.
	ArgumentsSHA256 string
	// RejectedAttemptID, when set, reports that the gateway rejected the token
	// of that attempt, so the broker obtains a fresh one. A caller reports an
	// attempt at most once, with the attempt's own call fields.
	RejectedAttemptID string
}

AuthorizeCallRequest asks whether an agent may make one MCP call.

func (AuthorizeCallRequest) Validate

func (r AuthorizeCallRequest) Validate() error

Validate reports whether r is well formed. The error is an *Error with CodeInvalidArgument.

type Broker

type Broker struct {
	// contains filtered or unexported fields
}

Broker is the identity broker core. Its startup state is immutable after New, except the gateway's AS-2: New binds a non-zero Gateway.AS2, BindGatewayAS2 binds one while none is bound, and its unbind removes it, so binding again after an unbind works. Its broker sessions are guarded by a mutex. Its methods are safe for concurrent use.

func New

func New(config Config, definitions []DefinitionRecord, signer crypto.Signer, opts ...Option) (*Broker, error)

New validates its inputs and returns a ready Broker, or an error wrapping one of the package's sentinel errors. Inputs are copied before validation, so later caller mutations cannot affect the broker. Records that repeat a reference with identical provenance collapse to one; records that repeat a reference with different provenance are rejected. An empty definition set is valid. New rejects the whole set if any record is invalid; a loader that skips bad definitions filters them first with DefinitionRecord.Validate.

The signer must have an ECDSA P-256 public key, the ES256 algorithm that JWT-SVID permits. A raw *ecdsa.PrivateKey is copied; any other signer, such as a KMS handle, is retained as supplied.

Options add optional collaborators, such as WithAuthServer, and are validated after they are applied.

func (*Broker) AuthorizeCall

func (b *Broker) AuthorizeCall(ctx context.Context, workload Workload, req AuthorizeCallRequest) (Authorization, error)

AuthorizeCall implements Core, in the order Service.AuthorizeCall documents. Every refusal after the session lookup is recorded.

func (*Broker) BindGatewayAS2 added in v0.0.52

func (b *Broker) BindGatewayAS2(as2 GatewayAS2) (unbind func(), err error)

BindGatewayAS2 binds the configured gateway's AS-2, which AuthorizeCall needs to redeem ID-JAGs; until it is bound, a call that passes the checks before a grant fails with CodeUnavailable. It returns an error wrapping ErrInvalidConfig when no gateway is configured, AS-2 is already bound, or as2 is incomplete.

The returned unbind is idempotent and leaves a later binding alone. It returns once the calls using this binding have finished; calls after it starts find AS-2 unbound. It must not be called from as2's AuthServer or the broker's IDJAGIssuer, as it would wait for its own call.

Shortcut: AS-2 bound late, leaving an UNAVAILABLE window; removed by #2560 (AS-2 reached over the network as a configured gateway entry).

func (*Broker) CloseSession

func (b *Broker) CloseSession(_ context.Context, workload Workload, req CloseSessionRequest) error

CloseSession implements Core. A call already in progress is refused with the closing reason at its next session check and gets no gateway token, even if AS-2 has already issued one. CloseSession discards the session's refresh token; an open converting a token for the session meanwhile discards the new one.

func (*Broker) Definition

func (b *Broker) Definition(ref DefinitionRef) (DefinitionRecord, bool)

Definition returns a copy of the loaded record for ref, and whether one exists. Mutating the returned record does not affect the broker.

func (*Broker) FindSession

func (b *Broker) FindSession(_ context.Context, workload Workload, req FindSessionRequest) (Session, bool, error)

FindSession implements Core.

func (*Broker) OpenSession

func (b *Broker) OpenSession(ctx context.Context, workload Workload, req OpenSessionRequest) (Session, error)

OpenSession implements Core. Opens of one host session run one at a time, so concurrent opens for it return the same broker session.

With an AuthServer configured, an open whose request carries an access token converts it into the session's refresh token, as convert describes. An open without one, or without an AuthServer, only pairs the session with the reported owner.

func (*Broker) RegisterAgent

func (b *Broker) RegisterAgent(_ context.Context, workload Workload, req RegisterAgentRequest) (Registration, error)

RegisterAgent implements Core. It checks the session, the owner, the root host session or parent, and an earlier registration of the instance, issues the credential, and only then records the instance in the session, so a failure changes nothing. The definition is accepted as reported, without a root eligibility check, because the broker loads no definitions yet.

func (*Broker) VerifyCredential

func (b *Broker) VerifyCredential(_ context.Context, req VerifyCredentialRequest) (VerifiedAgent, error)

VerifyCredential implements CredentialVerifier. After the credential's own checks (see credentialIssuer.verify), its subject must be a registered instance, and that instance must be registered to the request's session, and that session must be open, so closing a session ends its credentials' use at once rather than at their expiry. Only a credential issued since the instance moved to this session verifies, so reopening a session does not revive credentials issued before it closed. Per-instance subjects are what bind a credential to one session, with no session claim. It does not check which workload opened the session; the broker's per-operation checks do.

func (*Broker) VerifyCredentialForOwner added in v0.0.52

func (b *Broker) VerifyCredentialForOwner(_ context.Context, req VerifyCredentialForOwnerRequest) (VerifiedAgent, error)

VerifyCredentialForOwner implements CredentialVerifier. After the credential's own checks, its subject must be a registered instance whose present session is open and owned by req.Owner, and the credential must have been issued since the instance moved to that session, so a credential from before a session closed does not verify once the instance registers into the session that replaces it. The owner compared is the session's Owner, which its registrations are checked against, not its verified owner: the broker's per-operation checks put the agent in the session whose refresh token AS-1 exchanges, and that session's verified owner equals its Owner. Every refusal after the credential's own checks has the same detail, so an error passed on whole tells AS-1 nothing about the session's state.

type ClientAssertionSigner added in v0.0.52

type ClientAssertionSigner struct {
	// contains filtered or unexported fields
}

ClientAssertionSigner mints the private_key_jwt client assertions (RFC 7523) the broker authenticates with as BrokerClientID at every token and revocation endpoint request. Its key is the broker client key, separate from the agent issuer's. It is safe for concurrent use.

func NewClientAssertionSigner added in v0.0.52

func NewClientAssertionSigner(signer crypto.Signer, lifetime time.Duration) (*ClientAssertionSigner, error)

NewClientAssertionSigner returns a signer for assertions with the given lifetime: zero selects MaxClientAssertionLifetime, and a lifetime shorter than a second or longer than MaxClientAssertionLifetime is refused. The signer must have an ECDSA P-256 public key; a raw *ecdsa.PrivateKey is copied, any other signer, such as a KMS handle, is retained as supplied. Errors wrap ErrInvalidSigner or ErrInvalidConfig.

func (*ClientAssertionSigner) ClientAssertion added in v0.0.52

func (s *ClientAssertionSigner) ClientAssertion(audience string, now time.Time) (Token, error)

ClientAssertion returns a fresh assertion for the authorization server whose issuer identifier is audience: header typ client-authentication+jwt, alg ES256, and the key's kid; claims iss and sub BrokerClientID, aud audience as a single string, iat now, exp the lifetime after iat, and a random jti. Each call yields a new jti, so an assertion is used once.

func (*ClientAssertionSigner) JWKS added in v0.0.52

func (s *ClientAssertionSigner) JWKS() JWKSet

JWKS returns the public key set authorization servers register for BrokerClientID, inline, as ToolHive accepts no jwks_uri.

type CloseSessionRequest

type CloseSessionRequest struct {
	SessionID string
	// Reason is the closing reason later calls on the session fail with.
	// ReasonSessionClosed is the only closing reason Mecatl supplies today.
	Reason Reason
}

CloseSessionRequest closes a broker session.

func (CloseSessionRequest) Validate

func (r CloseSessionRequest) Validate() error

Validate reports whether r is well formed. The error is an *Error with CodeInvalidArgument.

type Code

type Code string

Code classifies a Service error. The values mirror the gRPC status codes the agent identity design assigns, without importing gRPC.

const (
	CodeUnauthenticated    Code = "UNAUTHENTICATED"
	CodePermissionDenied   Code = "PERMISSION_DENIED"
	CodeInvalidArgument    Code = "INVALID_ARGUMENT"
	CodeFailedPrecondition Code = "FAILED_PRECONDITION"
	CodeAlreadyExists      Code = "ALREADY_EXISTS"
	CodeAborted            Code = "ABORTED"
	CodeUnavailable        Code = "UNAVAILABLE"
	CodeInternal           Code = "INTERNAL"
)

Codes a Service error can carry.

type Config

type Config struct {
	// TrustDomain is the SPIFFE trust domain name for agent identities, such as
	// "agents.example.com", without the spiffe:// scheme.
	TrustDomain string
	// Audience is the single audience every agent credential names: the
	// broker's, such as "https://broker.example.com". JWT-SVID recommends one
	// audience per token, and the broker's verifiers reject more than one.
	Audience string
	// CredentialLifetime is the validity period of an agent credential. It must
	// be positive and at most MaxCredentialLifetime.
	CredentialLifetime time.Duration
}

Config is the operator-supplied identity configuration. The caller resolves it from whatever configuration source it uses; New validates it. Config holds only immutable values, so New's copy is independent of the caller's.

type Core

type Core interface {
	OpenSession(ctx context.Context, workload Workload, req OpenSessionRequest) (Session, error)
	FindSession(ctx context.Context, workload Workload, req FindSessionRequest) (Session, bool, error)
	CloseSession(ctx context.Context, workload Workload, req CloseSessionRequest) error
	RegisterAgent(ctx context.Context, workload Workload, req RegisterAgentRequest) (Registration, error)
	AuthorizeCall(ctx context.Context, workload Workload, req AuthorizeCallRequest) (Authorization, error)
}

Core is the broker side of the contract: Service's calls, each with the workload the authenticator determined. Implementations provide the behavior documented on Service, and also:

  • A workload that fails Validate is refused with CodeUnauthenticated, before any other check.
  • A broker session is bound to the whole Workload that opened it, Verified included, so a verified and an unverified workload with the same name are different workloads.
  • Another workload cannot tell another workload's broker session from none: closing, registering into, or calling through it fails exactly as for an unknown session ID (CodePermissionDenied, before any closing reason), and FindSession reports none open. Opening its host session is refused with CodePermissionDenied.
  • AuthorizeCall checks the workload, then the request, neither recorded; then the session, where an unknown session is not recorded and a closed one is; then a rejection report, the session's grant, the credential, and the server, in the order documented on Service; then it exchanges the session's grant for an ID-JAG, records it, and redeems it for the gateway token. Every refusal after the session lookup is recorded with the configured Recorder, and is returned whether or not the record is accepted; a success is returned only once recorded.

type CredentialRef added in v0.0.52

type CredentialRef struct {
	Issuer string
	ID     string
}

CredentialRef names a credential by its issuer and ID (iss, jti), never by its value.

type CredentialVerifier

type CredentialVerifier interface {
	// VerifyCredential checks an agent credential for use in a broker
	// session: the design's credential checks, in order, then that the agent
	// is registered to that session, the credential was issued since the
	// agent moved there, and the session is open. It returns the agent, its
	// ag_ identifier, and the credential's expiry. A malformed request fails
	// with CodeInvalidArgument; an expired credential with
	// CodeUnauthenticated and ReasonSVIDExpired; a closed session with its
	// closing reason, such as ReasonSessionClosed; every other failure with
	// CodePermissionDenied and ReasonDenied.
	VerifyCredential(ctx context.Context, req VerifyCredentialRequest) (VerifiedAgent, error)
	// VerifyCredentialForOwner checks an agent credential for use under a
	// grant of req.Owner, as AS-1 does before issuing an ID-JAG: the design's
	// credential checks, in order, then that the agent's present broker
	// session is open and owned by req.Owner, and the credential was issued
	// since the agent moved there. Which of the owner's sessions the call is
	// for is not checked here; the broker's per-operation checks do that. It
	// returns what VerifyCredential does. It refuses only with
	// CodeUnauthenticated and ReasonSVIDExpired for an expired credential, and
	// CodePermissionDenied and ReasonDenied for anything else, a malformed
	// request and a closed session included, so no closing reason reaches
	// AS-1. Any other error means the check could not be made, which AS-1
	// treats as retryable.
	VerifyCredentialForOwner(ctx context.Context, req VerifyCredentialForOwnerRequest) (VerifiedAgent, error)
}

CredentialVerifier checks agent credentials inside the broker, in two forms: one keyed by broker session, for the broker's own per-operation checks, and one keyed by owner, for AS-1's actor-token validator. Its callers run in process with the broker, so it takes no workload, and Mecatl never calls it. It is apart from Core so that a transport serving Core cannot publish an unauthenticated credential check by accident; AS-1's wiring takes a CredentialVerifier, never a Core.

type DecisionOutcome added in v0.0.52

type DecisionOutcome string

DecisionOutcome is how an AuthorizeCall ended.

const (
	OutcomeSuccess DecisionOutcome = "success"
	OutcomeDenied  DecisionOutcome = "denied"
	OutcomeError   DecisionOutcome = "error"
)

Decision outcomes: success when the call is allowed, error for a CodeInternal or CodeUnavailable failure, and denied for any other refusal.

type DecisionRecord added in v0.0.52

type DecisionRecord struct {
	At        time.Time
	SessionID string
	Workload  Workload
	// Owner is the broker session's verified owner, or the owner mecak8s
	// reported when the session has none; OwnerVerified says which.
	Owner Owner
	// OwnerVerified is true when Owner is the owner the broker verified at
	// session open, and false when it is only what mecak8s reported
	// (audit.md, "verified" or "reported:<component>").
	OwnerVerified bool
	// Agent and AgentID are zero when the credential did not verify.
	Agent             AgentRef
	AgentID           string
	RunID             string
	DelegationID      string
	RunOwner          Owner
	OperationID       string
	AttemptID         string
	RejectedAttemptID string
	Method            string
	Server            string
	Tool              string
	ArgumentsSHA256   string
	Outcome           DecisionOutcome
	// Code and Reason are the refusal's; empty on success.
	Code   Code
	Reason Reason
	IDJAG  CredentialRef
	// GatewayToken names the gateway token. GatewayTokenUnreferenced reports
	// an issued token that is not a JWT, so it has no (iss, jti) reference;
	// it does not mean no token was issued.
	GatewayToken             CredentialRef
	GatewayTokenUnreferenced bool
}

DecisionRecord records one AuthorizeCall decision.

type DefinitionRecord

type DefinitionRecord struct {
	Ref        DefinitionRef
	Provenance Provenance
}

DefinitionRecord is one loaded definition as the identity core sees it: the reference and its provenance. It deliberately carries no instructions, tools, or execution settings.

func (DefinitionRecord) Validate

func (r DefinitionRecord) Validate() error

Validate reports whether r is a well-formed definition record, applying the same rules as New. The returned error wraps ErrInvalidDefinition. A loader that skips bad definitions, rather than failing startup, uses it to filter records before calling New.

type DefinitionRef

type DefinitionRef struct {
	// Source identifies where the definition came from, such as "global" for
	// operator-loaded definitions or "system" for built-ins. It becomes the
	// definition category segment of agent SPIFFE IDs.
	Source string
	// Name is the definition name within the source, such as "code-reviewer".
	Name string
	// Revision is the source's own revision identifier, such as a Git commit or
	// an object revision. It is opaque to the broker and is not a content digest.
	Revision string
}

DefinitionRef identifies one agent definition: the configured source it was loaded from, its name within that source, and the selected source revision. Two references are equal only when all three fields are byte-identical, so the same name from different sources, or at different revisions, names different definitions. DefinitionRef is comparable and is the snapshot key.

type Digest

type Digest struct {
	Algorithm string
	Value     string
}

Digest is a content digest in canonical form: a supported algorithm and the lowercase hexadecimal digest value. The canonical form makes value equality mean digest equality.

type Error

type Error struct {
	Code   Code
	Reason Reason
	Detail string
}

Error is the error every Service call returns. Detail is for diagnostics; it never contains credentials.

func NewError

func NewError(code Code, reason Reason, detail string) *Error

NewError returns an *Error. reason may be empty.

func ReasonError

func ReasonError(reason Reason, detail string) *Error

ReasonError returns an *Error for reason with the code the design assigns.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(target error) bool

Is reports whether target is an *Error with the same code and, when target names one, the same reason, so errors.Is(err, &Error{Code: c}) matches by code.

type ExchangeGrant added in v0.0.52

type ExchangeGrant struct {
	Type               string
	IssuableTokenTypes []string
	// ExpiresAt is zero when the entry has no expires_at.
	ExpiresAt time.Time
}

ExchangeGrant is an exchange-grant authorization_details entry.

type FindSessionRequest

type FindSessionRequest struct {
	RootHostSessionID string
}

FindSessionRequest finds the open broker session for a root host session.

func (FindSessionRequest) Validate

func (r FindSessionRequest) Validate() error

Validate reports whether r is well formed. The error is an *Error with CodeInvalidArgument.

type Gateway added in v0.0.52

type Gateway struct {
	// Servers are the backend names the gateway routes. A call naming any
	// other server is denied.
	Servers []string
	// AS2 is the gateway's authorization server. The zero value leaves it
	// unbound until BindGatewayAS2.
	AS2 GatewayAS2
}

Gateway is the MCP gateway the broker authorizes calls through.

type GatewayAS2 added in v0.0.52

type GatewayAS2 struct {
	// Issuer is AS-2's issuer, an ID-JAG's audience.
	Issuer string
	// Resource is the vMCP resource, an ID-JAG's resource.
	Resource string
	// AuthServer redeems ID-JAGs at AS-2's token endpoint.
	AuthServer GatewayAuthServer
}

GatewayAS2 is the gateway's authorization server, AS-2, as the broker uses it: the audience of the ID-JAGs it requests, the vMCP resource, and the port that redeems ID-JAGs there.

type GatewayAuthServer added in v0.0.52

type GatewayAuthServer interface {
	Redeem(ctx context.Context, req Redemption) (GatewayTokenResult, error)
}

GatewayAuthServer is AS-2's token endpoint as a call uses it, design step (8): the RFC 7523 JWT-bearer redemption of an ID-JAG for a gateway token. The token endpoint and HTTP client live in the adapter, as the core holds no network client. Its errors follow IDJAGIssuer's.

type GatewayTokenResult added in v0.0.52

type GatewayTokenResult struct {
	AccessToken Token
	// ExpiresIn is AS-2's expires_in, zero when it sent none.
	ExpiresIn time.Duration
}

GatewayTokenResult is AS-2's answer to a redemption.

type IDJAGIssuer added in v0.0.52

type IDJAGIssuer interface {
	IssueIDJAG(ctx context.Context, req IDJAGRequest) (IDJAGResult, error)
}

IDJAGIssuer is AS-1's token endpoint as a call uses it, design step (7): the RFC 8693 exchange of the session's refresh token, with the agent's SVID as the actor token, for an ID-JAG addressed to AS-2. Its errors follow AuthServer's: a refusal is a *ServerRefusal; a request with no response wraps ErrNoResponse; a misconfigured connection wraps ErrTransportConfiguration; a success response it cannot decode, or whose issued_token_type is not an ID-JAG's, wraps both ErrMalformedResponse and ErrTransportConfiguration. The core separately checks the token's header typ. Errors never carry a token.

type IDJAGRecord added in v0.0.52

type IDJAGRecord struct {
	At          time.Time
	SessionID   string
	Agent       AgentRef
	AgentID     string
	RunID       string
	OperationID string
	AttemptID   string
	IDJAG       CredentialRef
	ExpiresAt   time.Time
}

IDJAGRecord records an ID-JAG the broker obtained for a call.

type IDJAGRequest added in v0.0.52

type IDJAGRequest struct {
	// SubjectToken is the session's refresh token.
	SubjectToken Token
	// ActorToken is the acting agent's SVID.
	ActorToken Token
	// Audience is AS-2's issuer.
	Audience string
	// Resource is the vMCP resource the gateway token is for.
	Resource string
	// OperationID is the call's operation, sent as mecatl_operation.
	OperationID string
}

IDJAGRequest is a per-call ID-JAG exchange request.

type IDJAGResult added in v0.0.52

type IDJAGResult struct {
	IDJAG Token
}

IDJAGResult is AS-1's answer to an ID-JAG exchange.

type JWK added in v0.0.52

type JWK struct {
	KeyType   string `json:"kty"`
	Curve     string `json:"crv"`
	X         string `json:"x"`
	Y         string `json:"y"`
	KeyID     string `json:"kid"`
	Use       string `json:"use"`
	Algorithm string `json:"alg"`
}

JWK is a public EC signing key as an RFC 7517 JSON Web Key.

type JWKSet added in v0.0.52

type JWKSet struct {
	Keys []JWK `json:"keys"`
}

JWKSet is an RFC 7517 JWK Set.

type MemoryRecorder added in v0.0.52

type MemoryRecorder struct {
	// contains filtered or unexported fields
}

MemoryRecorder is a Recorder holding the most recent records in memory, up to maxMemoryRecords of each kind, dropping the oldest. Its methods are safe for concurrent use.

Shortcut: records held in memory, dropping the oldest beyond 10,000 of each kind; removed by #2541 (record sink) and #2563 (durable state).

func NewMemoryRecorder added in v0.0.52

func NewMemoryRecorder() *MemoryRecorder

NewMemoryRecorder returns an empty MemoryRecorder.

func (*MemoryRecorder) Decisions added in v0.0.52

func (r *MemoryRecorder) Decisions() []DecisionRecord

Decisions returns a copy of the decision records, oldest first.

func (*MemoryRecorder) IDJAGs added in v0.0.52

func (r *MemoryRecorder) IDJAGs() []IDJAGRecord

IDJAGs returns a copy of the ID-JAG records, oldest first.

func (*MemoryRecorder) RecordDecision added in v0.0.52

func (r *MemoryRecorder) RecordDecision(_ context.Context, rec DecisionRecord) error

RecordDecision implements Recorder.

func (*MemoryRecorder) RecordIDJAG added in v0.0.52

func (r *MemoryRecorder) RecordIDJAG(_ context.Context, rec IDJAGRecord) error

RecordIDJAG implements Recorder.

type OpenSessionRequest

type OpenSessionRequest struct {
	HostSessionID string
	// Incarnation is the host session's incarnation, which its main agent
	// registers with, so it must be a Mecatl incarnation (see
	// RegisterAgentRequest.Incarnation).
	Incarnation string
	Owner       Owner
	// AccessToken is the user's AS-1 access token, when the request has one.
	// A broker that converts tokens checks that its sub_id is Owner and
	// exchanges it at AS-1 for the session's refresh token. AS-1 converts each
	// token once, so the caller passes a freshly refreshed token, and need not
	// pass one while the session holds a live refresh token; a token AS-1 may
	// already have converted, for any session, is not exchanged again. A
	// token not converted before replaces the session's refresh token. Other
	// brokers ignore it.
	AccessToken Token
}

OpenSessionRequest opens the broker session for a root host session.

func (OpenSessionRequest) Validate

func (r OpenSessionRequest) Validate() error

Validate reports whether r is well formed. The error is an *Error with CodeInvalidArgument.

type Option added in v0.0.52

type Option func(*Broker)

Option configures a Broker in New.

func WithAuthServer added in v0.0.52

func WithAuthServer(as1 AuthServer) Option

WithAuthServer has OpenSession convert the access token of a request that carries one at as1 (design step (3)). Without it, or with nil, the broker ignores access tokens and every open only pairs its session.

func WithClock added in v0.0.52

func WithClock(now func() time.Time) Option

WithClock replaces the broker's clock, which times session hard expiry, converted-token memory, and agent credentials, so a test can move past a session's hard expiry. Without it the broker uses time.Now.

func WithGateway added in v0.0.52

func WithGateway(g Gateway) Option

WithGateway has AuthorizeCall authorize calls through g. Without it every call that reaches the server check is denied. New refuses a second WithGateway, a gateway with no servers, with a server name that is not printable text without spaces or that appears twice, or with a partly set AS2, and a gateway without WithRecorder and WithIDJAGIssuer. New binds a non-zero AS2.

Shortcut: one gateway, the embedded one; removed by #2538 (operator-declared gateway entries, each with its own AS-2).

func WithIDJAGIssuer added in v0.0.52

func WithIDJAGIssuer(as1 IDJAGIssuer) Option

WithIDJAGIssuer has AuthorizeCall obtain each call's ID-JAG at as1 (design step (7)). A gateway requires it.

func WithRecorder added in v0.0.52

func WithRecorder(r Recorder) Option

WithRecorder has AuthorizeCall record its decisions with r. Without it, or with nil, nothing is recorded.

type Owner

type Owner struct {
	Issuer  string
	Subject string
}

Owner is a session owner: the user's company identity, such as issuer "https://login.example.com" and subject "alice-204".

type Provenance

type Provenance struct {
	// Profile identifies the provenance profile, such as "git/v1".
	Profile string
	// Metadata holds profile-specific facts, such as a repository and path.
	// Keys must be non-empty printable text without spaces; values must be
	// valid UTF-8. A nil and an empty map are equivalent.
	Metadata map[string]string
	// SourceDigest is the digest of the bytes read from the source.
	SourceDigest Digest
	// DefinitionDigest is the digest of the normalized definition the loader
	// accepted. It differs from SourceDigest whenever parsing normalizes input.
	DefinitionDigest Digest
}

Provenance records where a loaded definition came from and what was accepted. The profile names the source kind and versions the meaning of Metadata; this package requires a profile but does not interpret it.

type Reason

type Reason string

Reason is a design-defined reason code that tells the caller what to do, such as opening a new broker session. Reasons are lowercase letters and underscores.

const (
	// ReasonSessionClosed: the broker session is closed; open a new one on the
	// user's next request.
	ReasonSessionClosed Reason = "session_closed"
	// ReasonSessionOwned: the host session's broker session belongs to another
	// owner.
	ReasonSessionOwned Reason = "session_owned"
	// ReasonDenied: the call is not allowed.
	ReasonDenied Reason = "denied"
	// ReasonSVIDExpired: the agent credential has expired; get a new one and
	// retry.
	ReasonSVIDExpired Reason = "svid_expired"
	// ReasonOwnerMismatch: at session open, the access token's company
	// identity is not the owner the caller reported; a pairing bug.
	ReasonOwnerMismatch Reason = "owner_mismatch"
	// ReasonSubjectInvalid: at session open, the access token is not
	// acceptable; refresh it and open once more.
	ReasonSubjectInvalid Reason = "subject_invalid"
	// ReasonTokenUsed: at session open, the access token was already
	// converted; refresh it and open once more.
	ReasonTokenUsed Reason = "token_used"
	// ReasonSignedOut: the user signed out everywhere; stop the run. At
	// session open mecak8s answers it with a 401, so the client signs in
	// again.
	ReasonSignedOut Reason = "signed_out"
	// ReasonUpstreamRevoked: the company IdP revoked the user's sign-in; stop
	// the run. At session open mecak8s answers it with a 401, so the client
	// signs in again.
	ReasonUpstreamRevoked Reason = "upstream_revoked"
	// ReasonOwnerActionRequired: the user must sign in again.
	ReasonOwnerActionRequired Reason = "owner_action_required"
	// ReasonNoGrant: the broker session holds no refresh token, so no call
	// can be authorized in it; open the session with an access token.
	ReasonNoGrant Reason = "no_grant"
	// ReasonConsentRequired: the gateway's authorization server needs the
	// user's consent before it issues a token for the call.
	ReasonConsentRequired Reason = "consent_required"
)

Reasons a Service error can carry. Later work adds the design's other reasons as it returns them.

func (Reason) Code

func (r Reason) Code() Code

Code returns the code the design assigns to r.

func (Reason) RequiresSignIn added in v0.0.52

func (r Reason) RequiresSignIn() bool

RequiresSignIn reports whether r is a user-wide revocation of the user's authority (signed_out, upstream_revoked, owner_action_required): a refreshed access token is refused too, so the user signs in again.

type Recorder added in v0.0.52

type Recorder interface {
	RecordIDJAG(ctx context.Context, rec IDJAGRecord) error
	RecordDecision(ctx context.Context, rec DecisionRecord) error
}

Recorder keeps the broker's records of AuthorizeCall: each ID-JAG it obtains and each decision it makes. Records name credentials by reference, never by value. An implementation is safe for concurrent use.

type Redemption added in v0.0.52

type Redemption struct {
	// Assertion is the ID-JAG.
	Assertion Token
	// Resource is the vMCP resource.
	Resource string
}

Redemption is an ID-JAG redemption request. It carries no authorization_details yet (#2727).

type RegisterAgentRequest

type RegisterAgentRequest struct {
	SessionID string
	// HostSessionID is the agent's own host session. With no Parent it must
	// equal the broker session's root host session. A child agent's differs,
	// so it is not compared; checking that it belongs to the session's tree
	// will be addressed later.
	HostSessionID string
	// Owner must equal the broker session's owner.
	Owner Owner
	// Incarnation is the agent instance's incarnation, which the harness
	// allocates and persists: its host session's incarnation. With no Parent
	// it must equal the broker session's incarnation. It becomes a segment of
	// the agent's SPIFFE ID, so it must be a Mecatl incarnation: inc_ and 26
	// lowercase base32 characters, or legacy_ and 64 hex characters.
	Incarnation string
	// Definition is the definition the instance runs. Name is required. Source
	// and Revision are checked when set but may be empty for now, because
	// Mecatl sessions know their definition only by name; requiring them will
	// be addressed later.
	Definition DefinitionRef
	// Parent is the registered instance that created this one; zero for a
	// session's main agent.
	Parent AgentRef
}

RegisterAgentRequest registers an agent instance in a broker session.

func (RegisterAgentRequest) Validate

func (r RegisterAgentRequest) Validate() error

Validate reports whether r is well formed. The error is an *Error with CodeInvalidArgument.

type Registration

type Registration struct {
	Agent      AgentRef
	Credential Token
	// ExpiresAt is when the credential expires. Register again before then
	// for a fresh one.
	ExpiresAt time.Time
}

Registration is a registered agent instance and its credential. Mecatl's trusted harness code holds the credential and presents it on each call; it never reaches the engine or the model.

type ServerRefusal added in v0.0.52

type ServerRefusal struct {
	Status int
	Code   string
	Reason string
}

ServerRefusal is AS-1's or AS-2's refusal of a token or revocation endpoint request: the HTTP status and, from an RFC 6749 §5.2 error body, the error code and the reason code that starts error_description (design "Error reasons"). Code and Reason are empty when absent and "unknown" when present but not a code the broker knows, so a server cannot place arbitrary text, such as a token, in the error.

func NewServerRefusal added in v0.0.52

func NewServerRefusal(status int, code, description string) *ServerRefusal

NewServerRefusal returns the refusal for status and a response's error and error_description members, keeping the code and the leading reason code (description "reason" or "reason: text") only when each is known, and nothing else.

func (*ServerRefusal) Error added in v0.0.52

func (r *ServerRefusal) Error() string

type Service

type Service interface {
	// OpenSession opens the broker session for a root host session, or returns
	// the one already open for it.
	OpenSession(ctx context.Context, req OpenSessionRequest) (Session, error)
	// FindSession returns the open broker session for a root host session, and
	// whether one is open.
	FindSession(ctx context.Context, req FindSessionRequest) (Session, bool, error)
	// CloseSession closes a broker session with a closing reason. Closing an
	// already closed session succeeds and keeps its first reason.
	CloseSession(ctx context.Context, req CloseSessionRequest) error
	// RegisterAgent registers an agent instance in an open broker session and
	// returns its reference and credential.
	RegisterAgent(ctx context.Context, req RegisterAgentRequest) (Registration, error)
	// AuthorizeCall decides whether the agent presenting the credential may
	// make an MCP call, and returns the gateway token when it may. A denial is
	// an error, so a caller that ignores the result cannot dispatch.
	//
	// The checks run in order, each failing as shown:
	//   - an invalid request: CodeInvalidArgument;
	//   - an unknown session: as for any call;
	//   - a closed session: its closing reason;
	//   - a rejection report for an attempt never issued, or already
	//     reported: CodePermissionDenied, ReasonDenied;
	//   - a session that holds no refresh token: CodeFailedPrecondition,
	//     ReasonNoGrant;
	//   - a credential that does not verify for the session: as
	//     VerifyCredential refuses it;
	//   - a server no gateway routes: CodePermissionDenied, ReasonDenied.
	//
	// Then the broker obtains a fresh gateway token for this call alone,
	// failing as shown:
	//   - the gateway's authorization server not bound, or an authorization
	//     server or the broker's records unavailable: CodeUnavailable;
	//   - a reported attempt that does not match the call:
	//     CodePermissionDenied, ReasonDenied;
	//   - the session closed during the call: its closing reason;
	//   - AS-1's svid_expired, denied, signed_out, upstream_revoked, or
	//     owner_action_required: that reason; its actor_token_expired:
	//     ReasonSVIDExpired; its approval_required: ReasonDenied;
	//   - a revoked grant, unless the session holds a newer one:
	//     ReasonSessionClosed, closing the session;
	//   - consent the gateway requires: CodeFailedPrecondition,
	//     ReasonConsentRequired;
	//   - any other failure: CodeInternal.
	AuthorizeCall(ctx context.Context, req AuthorizeCallRequest) (Authorization, error)
}

Service is the contract between Mecatl and the identity broker: every call Mecatl makes goes through it, whether the broker runs in process or as its own service. Requests and results are plain values owned by this package, and every error is an *Error carrying a Code and, where the design defines one, a Reason.

Behavior every implementation provides:

  • OpenSession for a host session that already has an open broker session returns that session when the incarnation and owner match. A different owner fails with CodePermissionDenied and ReasonSessionOwned; a different incarnation fails with CodeAlreadyExists.
  • OpenSession with no access token pairs the broker session with the owner the caller reports, and the session holds no refresh token.
  • FindSession finds the open broker session from its root host session.
  • A closed broker session is never reopened. It refuses registration and calls with its closing reason, such as ReasonSessionClosed with CodeFailedPrecondition, and a later OpenSession for the same host session opens a new broker session with a new ID.
  • RegisterAgent refuses a request whose owner differs from the broker session's owner with CodePermissionDenied: one session tree has one owner. It also refuses, with CodePermissionDenied, an agent with no parent whose host session or incarnation is not the broker session's root host session or incarnation, and an agent whose parent is not registered to the session.
  • Registering the same incarnation again returns the same agent with a fresh credential, so a lost response or an expiring credential is handled by registering again. Registering it into a new broker session moves it there, keeping its identity. A registration of the same incarnation with a different owner, host session, or parent fails with CodeAlreadyExists and changes nothing.
  • A failed registration leaves any earlier registration as it was.
  • Agents with different incarnations are different agents. An agent's subject is a SPIFFE ID ending in "/inst/" and its incarnation, so the caller can check that the agent returned is the one it registered.
  • A broker session ID the broker never issued is refused with CodePermissionDenied.
  • Invalid requests fail with CodeInvalidArgument.

An implementation that converts access tokens at session open (design step (3); Broker with WithAuthServer) also:

  • Refuses, without calling AS-1, an access token whose sub_id, read without verification, is not the reported owner, with CodePermissionDenied and ReasonOwnerMismatch, or is missing or not of format iss_sub, with CodeUnauthenticated and ReasonSubjectInvalid; and an open of a session whose verified owner is another user, with ReasonSessionOwned. A broker session has two owners: the one the caller reported, which pairs it, and the verified owner, recorded only when AS-1 first accepts a token for it.
  • Exchanges the token at AS-1 for a refresh token the session holds, never past the session's hard expiry, and reports it in Session.HoldsRefreshToken. A token AS-1 may already have converted, for any session, is never presented to AS-1 again: an open repeating it returns the session as it is when the session holds a live refresh token, and fails with ReasonTokenUsed otherwise. AS-1's token_used and its refusal of the token fail with CodeUnauthenticated and ReasonTokenUsed or ReasonSubjectInvalid, after which the client refreshes its access token and opens again; a user-wide revocation fails with ReasonSignedOut, ReasonUpstreamRevoked, or ReasonOwnerActionRequired and the reason's code, after which the user signs in again; an unavailable AS-1 fails with CodeUnavailable, and any other failure with CodeInternal. A failed exchange leaves the session paired, with any refresh token it held; an answer that does not match the request or cannot be decoded closes it. When the session closes while AS-1 converts the token, the open fails with CodeFailedPrecondition and ReasonSessionClosed and the session keeps no refresh token; the token has been spent, so the client refreshes it before opening again.
  • Closes a session with ReasonSessionClosed when its refresh token's expiry, the session's hard expiry, passes: from then on every call finds it closed, and the next OpenSession for its host session opens a new broker session.

No request names the calling workload: the broker authenticates it itself, and Mecatl gets a Service from NewInProcess. Implementations provide this behavior by implementing Core.

func NewInProcess

func NewInProcess(authn Authenticator, core Core) Service

NewInProcess returns the Service Mecatl calls when the broker runs in its process. Each call asks authn which workload is calling, then passes it to core, so the in-process path takes the same authentication step as a remote one.

type Session

type Session struct {
	// ID is the broker session ID. The broker allocates it and never reuses it.
	ID            string
	HostSessionID string
	Incarnation   string
	// Owner is the owner the caller reported when it opened the session.
	Owner Owner
	// HoldsRefreshToken reports whether the session held a live refresh token
	// when the call returned: while it does, the caller need not send an
	// access token. The broker itself never presents a token AS-1 may
	// already have converted, for any session, to AS-1 again. The refresh
	// token never leaves the broker.
	HoldsRefreshToken bool
}

Session is a broker session.

type Token

type Token struct {
	// contains filtered or unexported fields
}

Token is a bearer credential: an AS-1 access token, an agent credential, or a gateway token. Its value is only available through Value; formatting a Token with any verb prints a redacted placeholder.

func NewToken

func NewToken(value string) Token

NewToken returns a Token holding value.

func (Token) Format

func (t Token) Format(f fmt.State, _ rune)

Format prints String for every verb, so no verb reaches the value.

func (Token) IsZero

func (t Token) IsZero() bool

IsZero reports whether t holds no credential.

func (Token) String

func (t Token) String() string

func (Token) Value

func (t Token) Value() string

Value returns the credential. Callers pass it only to the party that consumes it, never to logs, events, or the model.

type TokenExchange added in v0.0.52

type TokenExchange struct {
	// SubjectToken is the user's AS-1 access token.
	SubjectToken Token
	// Grant is the one authorization_details entry the request carries. A
	// zero ExpiresAt leaves expires_at out, and AS-1 applies its maximum.
	Grant ExchangeGrant
}

TokenExchange is a session-open exchange request.

type TokenExchangeResult added in v0.0.52

type TokenExchangeResult struct {
	// RefreshToken is the issued token, which RFC 8693 returns in
	// access_token.
	RefreshToken    Token
	IssuedTokenType string
	// Grants are the authorization_details entries AS-1 echoed.
	Grants []ExchangeGrant
}

TokenExchangeResult is AS-1's answer to a session-open exchange.

type UnverifiedAuthenticator

type UnverifiedAuthenticator struct {
	Name string
}

UnverifiedAuthenticator returns the same unverified workload for every call. It stands in until the broker authenticates the workload's credential, which will be addressed later.

func (UnverifiedAuthenticator) Authenticate

Authenticate implements Authenticator. The workload is never verified.

type VerifiedAgent

type VerifiedAgent struct {
	Agent AgentRef
	// AgentID is the agent's opaque ag_ identifier, the value AS-1 names the
	// acting agent by. It never contains a SPIFFE path or definition name.
	AgentID string
	// ExpiresAt is when the credential expires.
	ExpiresAt time.Time
}

VerifiedAgent is the agent a valid credential identifies.

type VerifyCredentialForOwnerRequest added in v0.0.52

type VerifyCredentialForOwnerRequest struct {
	Owner      Owner
	Credential Token
}

VerifyCredentialForOwnerRequest asks whether an agent credential is valid for use under a grant of Owner, whichever of the owner's broker sessions the agent is registered to. AS-1's actor-token validator sends it, with Owner read from the grant's sub_id.

type VerifyCredentialRequest

type VerifyCredentialRequest struct {
	SessionID  string
	Credential Token
}

VerifyCredentialRequest asks whether an agent credential is valid for use in a broker session.

func (VerifyCredentialRequest) Validate

func (r VerifyCredentialRequest) Validate() error

Validate reports whether r is well formed. The error is an *Error with CodeInvalidArgument.

type Workload

type Workload struct {
	// Name identifies the calling service, such as a Kubernetes
	// ServiceAccount.
	Name string
	// Verified reports that an authenticator verified the workload's
	// credential. The zero value is false, so only an authenticator that
	// verifies a credential sets it. When false, Name is a claim nobody
	// proved: implementations must never treat it as the verified workload of
	// the same name, and records must not present it as verified.
	Verified bool
}

Workload is the service making a call, as the broker's authenticator determined it. It is never a request field: Mecatl presents no identity of its own, and the broker decides who is calling.

func (Workload) Validate

func (w Workload) Validate() error

Validate reports whether w has a name. The error is an *Error with CodeUnauthenticated.

Directories

Path Synopsis
adapter
as1server
Package as1server hosts AS-1, Mecatl's sign-in authorization server, on ToolHive's embedded authorization server.
Package as1server hosts AS-1, Mecatl's sign-in authorization server, on ToolHive's embedded authorization server.
as1server/as1servertest
Package as1servertest runs the real AS-1 (package as1server) for tests of the identity broker and the code that wires it: in process, on loopback TLS, with the identityharness IdP as its upstream and the broker's delegate client keyed by a fresh broker key.
Package as1servertest runs the real AS-1 (package as1server) for tests of the identity broker and the code that wires it: in process, on loopback TLS, with the identityharness IdP as its upstream and the broker's delegate client keyed by a fresh broker key.
authserverclient
Package authserverclient is the identity broker's client of the authorization servers AS-1 and AS-2: it calls their token and revocation endpoints, authenticating every request as the OAuth client identitybroker.BrokerClientID with private_key_jwt (RFC 7523), a fresh client assertion each time, and never with a client secret.
Package authserverclient is the identity broker's client of the authorization servers AS-1 and AS-2: it calls their token and revocation endpoints, authenticating every request as the OAuth client identitybroker.BrokerClientID with private_key_jwt (RFC 7523), a fresh client assertion each time, and never with a client secret.
definitionloader
Package definitionloader loads the agent definitions the identity broker knows: the operator's global definitions and the built-in definitions each Mecatl release ships.
Package definitionloader loads the agent definitions the identity broker knows: the operator's global definitions and the built-in definitions each Mecatl release ships.
inprocesshttp
Package inprocesshttp serves HTTP client requests straight from an http.Handler in the same process, without a network listener.
Package inprocesshttp serves HTTP client requests straight from an http.Handler in the same process, without a network listener.
Package conformance provides the contract tests every identity broker implementation, an identitybroker.Core and identitybroker.CredentialVerifier, passes.
Package conformance provides the contract tests every identity broker implementation, an identitybroker.Core and identitybroker.CredentialVerifier, passes.

Jump to

Keyboard shortcuts

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