Documentation
¶
Overview ¶
Package auth exchanges a CipherStash access key for verified tokens.
NewTokenSource returns an oauth2.TokenSource for one workspace. It exchanges the access key with the CipherStash Token Service (CTS) and verifies each token's RS256 signature against CTS's published signing keys, its issuer, audience, expiry, workspace and role, and the ZeroKMS endpoint it advertises. Tokens are cached until one minute before expiry and refreshed on demand.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrConfig = errors.New("cipherstash: invalid configuration") ErrAuthentication = errors.New("cipherstash: authentication failed") ErrTransport = errors.New("cipherstash: transport failed") ErrResponse = errors.New("cipherstash: invalid service response") )
Failure categories. Errors wrap one of these and, where relevant, the underlying context or HTTP client error. They never include credentials.
Functions ¶
func NewTokenSource ¶
func NewTokenSource(ctx context.Context, crn CRN, key AccessKey, opts ...Option) (oauth2.TokenSource, error)
NewTokenSource validates its configuration without contacting CTS. The key's type selects the required role: Control accepts Control or Admin (logging a warning for Admin), Admin requires Admin, and Member requires Member.
ctx is the token source's lifetime: every exchange and signing-key request uses it. Pass a context that lives as long as the token source's owner, not a request context, and cancel it at shutdown. Cancelling it stops a request in progress and makes later exchanges fail with ErrTransport, but a cached token is still returned until it is within a minute of expiry.
Token has no context parameter, so a call can wait for another caller's refresh. The HTTP timeout bounds each request in that refresh.
func ZeroKMSURL ¶
ZeroKMSURL returns the verified ZeroKMS endpoint carried by a token from NewTokenSource: an HTTPS URL without credentials, query or fragment, which may include a path. CTS can return a ZeroKMS instance in a different region from itself, so the endpoint comes from the token, not the CRN. Each call returns a new copy, so callers may modify it without affecting the cached token that other callers share.
Types ¶
type AccessKey ¶
type AccessKey interface {
Validate() error
// contains filtered or unexported methods
}
AccessKey binds a parsed credential to the role required when exchanging it. Parsing checks syntax; only a verified CTS token proves the credential's role. The interface is sealed: use ControlAccessKey, AdminAccessKey or MemberAccessKey.
type AdminAccessKey ¶
type AdminAccessKey struct {
// contains filtered or unexported fields
}
AdminAccessKey requires Admin permission.
func ParseAdminAccessKey ¶
func ParseAdminAccessKey(value string) (AdminAccessKey, error)
func (*AdminAccessKey) EnvDecode ¶
func (k *AdminAccessKey) EnvDecode(_ context.Context, value string) error
func (AdminAccessKey) Validate ¶
func (k AdminAccessKey) Validate() error
type CRN ¶
type CRN struct {
// contains filtered or unexported fields
}
CRN identifies a CipherStash workspace, without a service suffix.
func (CRN) CTSURL ¶
CTSURL returns the workspace region's CTS base URL, with a trailing slash. CTS also issues the workspace's tokens under this URL.
func (CRN) Validate ¶
Validate rejects the zero value, such as an unset configuration field. ParseCRN is the only way to make a nonzero CRN.
func (CRN) WorkspaceID ¶
WorkspaceID returns the workspace's 16-character ID.
type ControlAccessKey ¶
type ControlAccessKey struct {
// contains filtered or unexported fields
}
ControlAccessKey requires Control or, for compatibility, Admin permission.
func ParseControlAccessKey ¶
func ParseControlAccessKey(value string) (ControlAccessKey, error)
func (*ControlAccessKey) EnvDecode ¶
func (k *ControlAccessKey) EnvDecode(_ context.Context, value string) error
func (ControlAccessKey) Format ¶
func (ControlAccessKey) Format(f fmt.State, _ rune)
Format redacts the credential for every fmt verb, including in logs.
func (ControlAccessKey) Validate ¶
func (k ControlAccessKey) Validate() error
type MemberAccessKey ¶
type MemberAccessKey struct {
// contains filtered or unexported fields
}
MemberAccessKey requires Member permission; Admin is not a substitute.
func ParseMemberAccessKey ¶
func ParseMemberAccessKey(value string) (MemberAccessKey, error)
func (*MemberAccessKey) EnvDecode ¶
func (k *MemberAccessKey) EnvDecode(_ context.Context, value string) error
func (MemberAccessKey) Validate ¶
func (k MemberAccessKey) Validate() error
type Option ¶
type Option func(*options)
func WithCTSURL ¶
WithCTSURL sends CTS exchanges and signing-key requests to ctsURL instead of the workspace region's CTS, and requires tokens to name it as their issuer. It must be an HTTPS URL, or HTTP to a loopback host, without credentials, query or fragment. Pass the same URL to manage.WithCTSURL.
func WithTransport ¶
func WithTransport(transport http.RoundTripper) Option
WithTransport sets the transport for CTS exchanges and signing-key requests. The token source still sets its User-Agent, a 10-second timeout per request and a no-redirect policy. The default is http.DefaultTransport.