Documentation
¶
Overview ¶
Package guard is what the services other machines may reach share: who a bearer credential speaks for (RFC 6750), and that a listener off loopback requires one.
Index ¶
- Constants
- func IsB64Token(s string) bool
- func IsLoopbackAddr(addr net.Addr) bool
- func IsLoopbackHost(host string) bool
- func ListenAddress(spec string) (string, error)
- func NoToken(env string) error
- func WithPrincipal(ctx context.Context, p Principal) context.Context
- type Authenticator
- type Chain
- type Principal
- type Refusal
- type ResourceMetadata
- type StaticToken
- type Token
Constants ¶
const SourceStaticToken = "static-token"
SourceStaticToken is the Principal.Source of a static token.
const StaticTokenSubject = "token"
StaticTokenSubject is the subject of the principal a static token speaks for.
Variables ¶
This section is empty.
Functions ¶
func IsB64Token ¶
IsB64Token reports whether s is a b64token of RFC 6750 § 2.1.
func IsLoopbackAddr ¶
IsLoopbackAddr reports whether a bound address can be reached from this machine only.
func IsLoopbackHost ¶
IsLoopbackHost reports whether a host name or address is this machine's loopback interface.
func ListenAddress ¶
ListenAddress reads a listening address as every service spells one: a port alone, or host:port whose host is empty, binds loopback (localhost).
Types ¶
type Authenticator ¶ added in v0.13.0
type Authenticator interface {
// Verify classifies an Authorization header (RFC 6750 § 2.1) and names the
// principal of an Accepted one; r is nil on a transport with no HTTP request.
Verify(ctx context.Context, authorization string, r *http.Request) (Principal, Refusal)
// Metadata is what the authenticator has the resource advertise.
Metadata() ResourceMetadata
}
Authenticator decides who an Authorization header speaks for; a service asks the ones it is configured with through a Chain.
type Chain ¶ added in v0.13.0
type Chain []Authenticator
Chain asks authenticators in order and answers with the first verdict that is not NothingPresented, so each claims the credentials of its own kind.
func (Chain) Metadata ¶ added in v0.13.0
func (c Chain) Metadata() ResourceMetadata
Metadata is the authenticators' metadata together, in their order and with each value once.
type Principal ¶ added in v0.13.0
type Principal struct {
// Subject identifies the principal stably and is never empty: an OIDC
// sub, an API key's subject, StaticTokenSubject.
Subject string
// Name is how the principal is displayed: an e-mail address, a key's label.
Name string
// Scopes are the scopes the credential grants (RFC 6749 § 3.3).
Scopes []string
// Expires is when the credential stops being accepted; zero is never.
Expires time.Time
// Source names the kind of authenticator that accepted the credential and
// holds no colon, so that ID reads one way.
Source string
}
Principal is who an accepted credential speaks for.
func PrincipalFrom ¶ added in v0.13.0
PrincipalFrom is the principal the request of ctx was accepted for, to key what its caller owns by ID; there is none on a transport that authenticates nobody.
type Refusal ¶
type Refusal int
Refusal is why an Authorization header was not accepted, or Accepted.
const ( // Accepted is a header carrying a credential the server accepts. Accepted Refusal = iota // NothingPresented is a request with no Authorization header; from one // Authenticator of a Chain, also a credential of a kind it does not read. NothingPresented // NotBearer is an Authorization header of another scheme. NotBearer // Malformed is a Bearer header whose credentials are not a b64token. Malformed // Mismatch is a well-formed bearer token that is not this server's. Mismatch // Expired is a bearer token of this server's whose lifetime has ended. Expired // InsufficientScope is a valid bearer token without a scope the server requires. InsufficientScope // it being out of reach; RFC 6750 § 3.1 has no error code for it. Unavailable )
func Bearer ¶ added in v0.13.0
Bearer reads the bearer token of an Authorization header (RFC 6750 § 2.1): the b64token with Accepted, or why the header carries none.
func (Refusal) ChallengeParams ¶
ChallengeParams are the error parameters of a WWW-Authenticate challenge, none for a refusal with no error code.
func (Refusal) Code ¶
Code is the RFC 6750 § 3.1 error code, empty when nothing was presented and for Unavailable, which is not the client's error.
func (Refusal) Description ¶
Description says what was wrong, empty when nothing was presented.
func (Refusal) HTTPStatus ¶
HTTPStatus is the status a refusal is answered with (RFC 6750 § 3.1): 400 for an unreadable header, 403 for a missing scope, 503 for Unavailable, 401 otherwise.
type ResourceMetadata ¶ added in v0.13.0
type ResourceMetadata struct {
// AuthorizationServers are the issuers of its tokens (authorization_servers).
AuthorizationServers []string
// ScopesSupported are the scopes a client may request (scopes_supported).
ScopesSupported []string
}
ResourceMetadata is what an authenticator has the resource advertise in its protected resource metadata (RFC 9728 § 2).
type StaticToken ¶ added in v0.13.0
type StaticToken struct {
// contains filtered or unexported fields
}
StaticToken authenticates the one token a service was given out of band (RFC 6750); it reads every bearer token, so it ends the Chain it is in.
func NewStaticToken ¶ added in v0.13.0
func NewStaticToken(token Token, scopes ...string) StaticToken
NewStaticToken is the authenticator of token, whose principal holds scopes: every scope the service defines, the token being its operator's.
func (StaticToken) Metadata ¶ added in v0.13.0
func (StaticToken) Metadata() ResourceMetadata
Metadata is empty: no authorization server issues a static token, and no scope is requested for one.
type Token ¶
type Token struct {
// contains filtered or unexported fields
}
Token is the one access token a service accepts (RFC 6750), issued out of band by whoever runs it; the zero value is no token.
func New ¶
New reads a token as RFC 6750 § 2.1 spells one (b64token), so a client can send what the server was given; anything else is refused.
func Read ¶
Read reads the token -token-file (one trailing line break dropped), -token or the environment variable env names, in that precedence; both flags set is refused, none and an empty variable is no token. The text is returned beside the token for a command that prints its configuration.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package apikey authenticates the access keys a service hands people and CI: bearer tokens osk_<id>.<secret> (RFC 6750), checked against a file of hashed records.
|
Package apikey authenticates the access keys a service hands people and CI: bearer tokens osk_<id>.<secret> (RFC 6750), checked against a file of hashed records. |
|
Package flags declares the command-line flags that configure a service's authenticators once, so every command reads the same ones and resolves them alike.
|
Package flags declares the command-line flags that configure a service's authenticators once, so every command reads the same ones and resolves them alike. |
|
Package oidc authenticates the access tokens an OpenID provider issues (RFC 9068, OpenID Connect Discovery 1.0) as one member of a guard.Chain.
|
Package oidc authenticates the access tokens an OpenID provider issues (RFC 9068, OpenID Connect Discovery 1.0) as one member of a guard.Chain. |