Documentation
¶
Overview ¶
Package principal is the caller a request authenticated as: who it is, which credential proved it, and what that credential is limited to. auth/authn produces one and auth/rbac reads one; the accounts it names, and how they are stored, are the product's.
It is a leaf: it imports nothing from the rest of the module, so every other package can depend on it.
Index ¶
Constants ¶
const Wildcard = "*"
Wildcard in a rule's kinds or verbs matches any kind or verb.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Credential ¶
type Credential struct {
Kind CredentialKind
// KeyID and KeyName name the key or token presented, for audit. Empty for a session.
KeyID string
KeyName string
// Scope narrows what this credential may do below what the principal holds; nil leaves it unrestricted.
Scope *CredentialScope
}
Credential is what the request presented.
type CredentialKind ¶
type CredentialKind string
CredentialKind is how the caller proved who it is.
const ( CredentialSession CredentialKind = "session" CredentialAPIKey CredentialKind = "api-key" CredentialToken CredentialKind = "token" // CredentialService is a shared secret configured for a service, such as an operator's bearer. CredentialService CredentialKind = "service" )
type CredentialScope ¶
type CredentialScope struct {
Rules []Rule
// Within maps an action kind to the scopes the credential is limited to there: a resource of that kind is reached only when one of the listed scopes, of any kind, is in its scope chain. A list on a resource with no id and no owner is admitted, its rows then filtered through Visible or ScopeOf; any other verb on such a resource is refused. A kind absent from the map is not limited by scope.
Within map[string][]Scope
}
CredentialScope narrows a credential below what its principal holds. It fails closed: no rules permit nothing, and a kind present in Within with an empty list reaches nothing.
type Principal ¶
type Principal struct {
// ID is the product's durable id for the account. Empty, with Admin unset, means unauthenticated.
ID string
Kind Kind
// Issuer and Subject are the stable identity an external identity provider asserted. Empty for a local account.
Issuer string
Subject string
// Username and Email are for display and lookup, never a join key.
Username string
Email string
// Groups are the group names the identity provider asserted, as asserted.
Groups []string
// Subjects are the binding subjects the caller acts under.
Subjects []string
Roles []string
// Admin passes every product rule and binding; the credential scope still applies. It is meant for break-glass callers: roles such as owner or admin are better ordinary roles, so a grant check can tell their holders apart. Mapping a role to Admin is the product's choice.
Admin bool
Credential Credential
// Audience is the `aud` the presented token was issued for, as the token carried it. Empty for any other credential and for a token without one. It lives here rather than on Credential so Credential stays comparable.
Audience []string
// SessionID correlates the session the caller came from. It is derived from the session token, never equal to it, because audit readers see it.
SessionID string
Status Status
}
Principal is an authenticated caller.
func (*Principal) Authenticated ¶
Authenticated reports whether p is a caller that may be evaluated.