auth

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 22 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func ZeroKMSURL(token *oauth2.Token) (*url.URL, error)

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) Format

func (AdminAccessKey) Format(f fmt.State, _ rune)

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 ParseCRN

func ParseCRN(value string) (CRN, error)

ParseCRN accepts a workspace CRN in a supported CTS region.

func (CRN) CTSURL

func (c CRN) CTSURL() string

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) EnvDecode

func (c *CRN) EnvDecode(_ context.Context, value string) error

func (CRN) String

func (c CRN) String() string

func (CRN) Validate

func (c CRN) Validate() error

Validate rejects the zero value, such as an unset configuration field. ParseCRN is the only way to make a nonzero CRN.

func (CRN) WorkspaceID

func (c CRN) WorkspaceID() string

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) Format

func (MemberAccessKey) Format(f fmt.State, _ rune)

func (MemberAccessKey) Validate

func (k MemberAccessKey) Validate() error

type Option

type Option func(*options)

func WithCTSURL

func WithCTSURL(ctsURL *url.URL) Option

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL