Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidCredentials is returned when credentials are invalid. ErrInvalidCredentials = errors.New("invalid credentials") )
Functions ¶
Types ¶
type AuthInfo ¶
type AuthInfo struct {
// Subject is the entity established by the authenticator.
Subject Subject
// AuthMethod is the authentication method used.
AuthMethod string
}
AuthInfo contains the result of token validation by an authenticator.
It carries the authenticated subject separately from the method that proved it.
type Authenticator ¶
type Authenticator interface {
// Name returns the authenticator name for logging.
Name() string
// Supports checks if this authenticator can handle the given credential.
Supports(credential Credential) bool
// Authenticate validates the credential and returns authentication info.
//
// The requestInfo provides request context such as the gRPC method being
// called.
Authenticate(ctx context.Context, credential Credential, requestInfo *RequestInfo) (*AuthInfo, error)
}
Authenticator is the interface for authentication methods.
type Credential ¶ added in v0.1.0
type Credential struct {
// Token is the value of the authentication metadata header, empty when
// absent.
Token string
// TLS is the connection state of a TLS transport, nil on plaintext.
TLS *tls.ConnectionState
}
Credential is what a request presents for authentication: the token from its metadata and the state of the TLS connection it arrived on.
Either part may be absent. A request without a token has an empty Token, a request over plaintext has a nil TLS.
type Principal ¶
type Principal struct {
// User is the authenticated username.
User string
// Groups is the list of group memberships for RBAC.
Groups []string
// AuthMethod is the authentication method used.
AuthMethod string
// AuthTime is when the authentication occurred.
AuthTime time.Time
// IsAnonymous indicates if this is an unauthenticated/anonymous principal.
IsAnonymous bool
}
Principal represents an authenticated identity with their authorization context.
It is carried in the request context and used for authorization and audit logging.
func FromContext ¶
FromContext extracts the Principal from the context.
Returns nil if no Principal is present.
type RequestInfo ¶
type RequestInfo struct {
// FullMethod is the full gRPC method name, e.g.
// "/routepb.RouteService/InsertRoute".
FullMethod string
}
RequestInfo contains request metadata needed for authentication.
Some authenticators (e.g. SSH key) need to verify method binding, so the actual gRPC method is passed here.
type Subject ¶
type Subject struct {
// Issuer scopes the identifier to the authority that assigned it.
//
// For OIDC this is the exact `iss` value. Local authenticators use `local`.
Issuer string
// Identifier is the stable value assigned within the issuer namespace.
//
// For OIDC this is `sub`; it need not be human-readable or usable as a
// system account name.
Identifier string
// Login is an optional account lookup name for file, NSS, or LDAP providers.
//
// It may be mutable and must not be treated as a globally stable subject
// identifier.
Login string
// Assertion contains optional verified attributes from the credential.
//
// A claims-backed identity provider may interpret them, while lookup-based
// providers can ignore them.
Assertion VerifiedAssertion
}
Subject identifies the entity proven by a credential.
The authority namespace and its stable identifier form the subject key. Account lookup names and verified attributes are auxiliary data and are not part of that key.
func NewLocalSubject ¶
NewLocalSubject creates a local subject with one value serving as both its stable identifier and account lookup name.
type VerifiedAssertion ¶
type VerifiedAssertion interface {
// AssertionType identifies the assertion format for provider dispatch.
AssertionType() string
}
VerifiedAssertion marks credential attributes whose authenticity has been established.
Implementations must only be returned after the carrying credential has been fully validated. Verification does not make an attribute an authorization decision; an identity provider must still interpret it.