Documentation
¶
Overview ¶
Package actor decides whether the agent acting on a user's behalf, named by a delegated token, is allowed.
It authorizes the actor a token already names, when the token is presented: the outermost act claim, or the client under SourceClient. Checking an actor's credential before ToolHive issues a token, and so deciding what goes into act, is tokenexchange.ActorTokenValidator.
Index ¶
Constants ¶
const ( // SourceAct takes the actor from the token's outermost act claim. It is // the default. SourceAct = "act" // SourceClient takes the actor from the client the token was issued to, // for providers that never emit act. There is no fallback between sources. SourceClient = "client" )
Where an identity provider names the actor.
const ( ReasonAllowed = "allowed" ReasonNoActor = "no_actor" ReasonIssuerNotAllowed = "actor_issuer_not_allowed" )
Stable reasons in Decision.Reason.
Variables ¶
var ( // ErrNoActor means the source is "act" and the token has no act claim. ErrNoActor = errors.New("token has no actor") // ErrMalformedActor means the act claim, or the input that stands in for // it, cannot name an actor. ErrMalformedActor = errors.New("malformed actor") )
Functions ¶
This section is empty.
Types ¶
type Actor ¶
type Actor struct {
// Source is where the identity provider names the actor.
Source string
// Issuer is act.iss, or the token's issuer when act has none.
Issuer string
// Subject is act.sub, or the client ID when Source is SourceClient.
Subject string
// Claims is a copy of the outermost act object without its nested act
// member, so a prior actor cannot drive a decision. It is nil when Source
// is SourceClient. DefaultPolicy does not read it; it is there for Policy
// implementations that do.
Claims map[string]any
}
Actor is the agent a token names as acting on the user's behalf.
func Effective ¶
Effective returns the actor a token names. Only the outermost act counts (RFC 8693 section 4.1): Claims is a deep copy of it with the nested act removed, and does not alias the caller's map or any map[string]any or []any inside it (the shapes JSON decoding produces). An act without iss takes tokenIssuer, so providers that omit it (Okta) work.
For SourceClient the actor is the client, with tokenIssuer as its issuer. An empty source means SourceAct.
Effective is the strict parser for authorization decisions: it fails closed, unlike the lenient audit parser audit.ParseDelegationChain (toolhive-core), which never fails.
type Decision ¶
type Decision struct {
Allow bool
// Reason is a stable string callers map to a reason code.
Reason string
// Principal is the actor identity for session binding and audit.
Principal string
// Source is where the actor came from, SourceAct or SourceClient, copied
// from the Actor for audit. It is empty when there was no actor.
Source string
}
Decision is a Policy's answer.
type DefaultPolicy ¶
type DefaultPolicy struct {
// contains filtered or unexported fields
}
DefaultPolicy allows an actor whose issuer is the token issuer or one of the issuers configured to act through it. There is one policy per token issuer.
func NewDefaultPolicy ¶
func NewDefaultPolicy(tokenIssuer string, actorIssuers []string) (*DefaultPolicy, error)
NewDefaultPolicy returns a DefaultPolicy for tokens issued by tokenIssuer. The actor's issuer must be tokenIssuer or one of actorIssuers, which may be empty.
act.iss is not required to equal the token issuer: a ToolHive authorization server names its agents under a different issuer (for example a SPIFFE trust domain), and the server refuses an actor issuer equal to its own issuer.
tokenIssuer must be non-empty. Empty issuers are refused, and so is any issuer containing #, because Principal is issuer#subject and splitting on the first # must recover both parts.
type Policy ¶
Policy decides whether an actor may act for a user. A Decision that does not allow is a denial. A non-nil error means the policy could not decide (for example a directory-backed policy that is unavailable, or a request for another token issuer): the Decision does not allow, and callers answer with a server error rather than a denial, like subject.ErrUnavailable.
type Request ¶
type Request struct {
TokenIssuer string
// ClientID is a separate input. It is never the actor, except when the
// issuer's source is SourceClient.
ClientID string
// Actor is nil when the token has no actor.
Actor *Actor
User string
Resource string
}
Request is what a Policy decides on.