Documentation
¶
Overview ¶
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.
Index ¶
Constants ¶
const Prefix = "osk_"
Prefix heads every key, so an authenticator tells one from any other bearer token.
const RefreshInterval = time.Second
RefreshInterval bounds how often a request has the store look at the file.
const Source = "api-key"
Source is the Principal.Source of a key.
Variables ¶
This section is empty.
Functions ¶
func Revoke ¶
Revoke marks the record of id disabled in the file at path, which is rewritten whole; a key that is not there, or is disabled already, is an error.
func ValidScope ¶
ValidScope reports whether s is a scope-token of RFC 6749 § 3.3.
Types ¶
type Record ¶
type Record struct {
ID string `json:"id"`
SHA256 string `json:"sha256"`
Subject string `json:"subject"`
Scopes []string `json:"scopes"`
Expires time.Time `json:"expires,omitzero"`
Disabled bool `json:"disabled,omitempty"`
}
Record is one key as the file holds it: the SHA-256 of the secret in hex, never the secret, so reading the file does not give the key away.
func Mint ¶
Mint issues a key for subject with scopes, expiring at expires (zero for never), and appends its record to the file at path, created if absent; the key is returned once, the file never holds it.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the keys of one file, as a guard.Authenticator; it re-reads the file when its content changes and on Reload, so a revocation needs no restart.
func Open ¶
Open reads the file at path once, failing as ReadFile does; logger (nil for the default) hears each later reload and the one line a failed one logs.
func (*Store) Metadata ¶
func (*Store) Metadata() guard.ResourceMetadata
Metadata is empty: no authorization server issues a key, and no scope is requested for one.
func (*Store) Reload ¶
Reload re-reads the file now, as on SIGHUP; a file that does not read keeps the keys held and is returned as the error.
func (*Store) Verify ¶
func (s *Store) Verify(_ context.Context, authorization string, _ *http.Request) (guard.Principal, guard.Refusal)
Verify accepts a key of the file as its subject (RFC 6750 § 2.1): a bearer token that is no key is NothingPresented; an unknown id, wrong secret or disabled key Mismatch; a dead one Expired.