auth

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package auth provides credential storage and a small grant-based authorization model for the S3 server. It is deliberately a table, not a policy engine: each access key maps to a secret and a set of (bucket-pattern → permission) grants, and buckets may be flagged public-read.

The zero value is not useful; construct a Store with NewStore and swap its snapshot atomically via Set for hot reload.

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyExists = errors.New("access key already exists")

ErrKeyExists reports an access key that already exists.

View Source
var ErrKeyImmutable = errors.New("access key is defined in config and cannot be modified at runtime")

ErrKeyImmutable reports an attempt to modify a config-defined credential.

View Source
var ErrKeyNotFound = errors.New("access key not found")

ErrKeyNotFound reports an unknown managed access key.

Functions

func NewAccessKey added in v0.8.0

func NewAccessKey() string

NewAccessKey returns an AWS-style 20-character access key ID.

func NewSecretKey added in v0.8.0

func NewSecretKey() string

NewSecretKey returns a 40-character secret access key.

Types

type Action

type Action int

Action is the access level a request requires, derived from its method.

const (
	// ActionRead is required by GET/HEAD.
	ActionRead Action = iota
	// ActionWrite is required by PUT/POST/DELETE.
	ActionWrite
)

type Config

type Config struct {
	// Keys are the credentials the server accepts.
	Keys []Key
	// PublicReadBuckets may be read anonymously (unsigned GET/HEAD/list).
	PublicReadBuckets []string
}

Config is the declarative auth configuration, suitable for loading from a file or building programmatically.

func (Config) Validate

func (c Config) Validate() error

Validate checks the configuration for empty/duplicate access keys and empty secrets.

type CreateInput

type CreateInput struct {
	AccessKey string
	SecretKey string
	Grants    []Grant
}

CreateInput describes a credential to create. AccessKey and SecretKey are generated when empty.

type Created

type Created struct {
	AccessKey string
	SecretKey string
	Grants    []Grant
	CreatedAt time.Time
}

Created is a newly created credential, including the secret — returned only once, at creation.

type Grant

type Grant struct {
	Pattern    string
	Permission Permission
}

Grant authorizes an access key for buckets matching Pattern (a glob using path.Match semantics; "*" matches all buckets) up to Permission.

type Identity added in v0.10.0

type Identity struct {
	// UserID is the canonical user ID. Defaults to the access key.
	UserID string
	// DisplayName is the human-readable owner name. Defaults to UserID.
	DisplayName string
}

Identity is the S3 owner a credential acts as. It appears as the <Owner> of buckets, objects and ACLs; S3 clients compare these values to decide what a caller owns, so they must be stable for a given credential.

type Key

type Key struct {
	AccessKey string
	SecretKey string
	// UserID is the canonical owner ID reported for objects this key writes.
	// Empty means "use the access key".
	UserID string
	// DisplayName is the human-readable owner name. Empty means "use UserID".
	DisplayName string
	Grants      []Grant
}

Key is a credential: an access/secret pair, the identity it acts as, and its grants.

type KeyInfo

type KeyInfo struct {
	AccessKey string
	Grants    []Grant
	Source    Source
	CreatedAt time.Time
}

KeyInfo describes a credential without exposing its secret. It is what the admin API lists.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager owns the live auth Store and adds runtime CRUD over credentials. Config/env credentials form a read-only base; runtime-created credentials are persisted to a JSON file and merged over the base. Every mutation rebuilds the Store snapshot atomically, so live requests immediately see the change.

func NewManager

func NewManager(base Config, path string) (*Manager, error)

NewManager builds a Manager from a base Config (config/env credentials) and a persistence path for runtime-created credentials. It loads any previously persisted credentials and applies the merged set to a new Store. path may be empty to keep runtime credentials in memory only.

func (*Manager) Create

func (m *Manager) Create(in CreateInput) (*Created, error)

Create adds a runtime credential, generating the access key and/or secret when not supplied, persists it, and applies it to the live Store. The returned Created carries the secret (the only time it is exposed).

func (*Manager) Delete

func (m *Manager) Delete(accessKey string) error

Delete removes a runtime credential. Config credentials cannot be deleted.

func (*Manager) List

func (m *Manager) List() []KeyInfo

List returns every credential (config + managed), secrets omitted, sorted by access key.

func (*Manager) Reload

func (m *Manager) Reload(base Config) error

Reload re-reads the static base credentials (e.g. after a SIGHUP config reload) while keeping runtime-created credentials, and re-applies the merged set to the Store.

func (*Manager) Store

func (m *Manager) Store() *Store

Store returns the live auth Store to wire into the server.

type Permission

type Permission int

Permission is an access level. Higher levels include lower ones: Admin ⊇ Write ⊇ Read.

const (
	// Read allows GET/HEAD/list operations.
	Read Permission = iota
	// Write allows Read plus PUT/POST/DELETE (including bucket create/delete).
	Write
	// Admin allows everything Write does, and is the level future admin-only
	// operations will require.
	Admin
)

func ParsePermission added in v0.8.0

func ParsePermission(s string) (Permission, error)

ParsePermission is the inverse of Permission.String. It rejects any spelling other than "read", "write" or "admin".

func (Permission) String added in v0.8.0

func (p Permission) String() string

String returns the canonical name of a permission ("read", "write" or "admin"), the spelling used in config and the admin API.

type Sealer added in v0.8.0

type Sealer struct {
	// contains filtered or unexported fields
}

Sealer seals and opens credential secrets with an AES-256-GCM key derived from the cluster secret via HKDF-SHA256. It exists so credentials stored in the cluster control plane (etcd) are encrypted at rest: a leaked etcd backup or a compromised control plane yields only ciphertext, not usable secret keys. The cluster secret is the sole key material; it never touches etcd.

A Sealer is safe for concurrent use.

func NewSealer added in v0.8.0

func NewSealer(clusterSecret []byte) (*Sealer, error)

NewSealer derives the sealing key from clusterSecret and returns a Sealer. clusterSecret must be non-empty (the cluster secret is validated to be at least 16 bytes upstream).

func (*Sealer) Open added in v0.8.0

func (s *Sealer) Open(blob string) (string, error)

Open reverses Seal. It fails if the blob is malformed, was sealed with a different cluster secret, or was tampered with (GCM authentication).

func (*Sealer) Seal added in v0.8.0

func (s *Sealer) Seal(plaintext string) (string, error)

Seal encrypts plaintext and returns a base64 (raw std) blob of nonce ‖ ciphertext. A fresh random nonce is used per call, so sealing the same secret twice yields different blobs.

type Source

type Source string

Source identifies where a credential came from.

const (
	// SourceConfig is a credential defined in the static config/env (read-only
	// at runtime).
	SourceConfig Source = "config"
	// SourceManaged is a credential created at runtime through the admin API
	// (editable and deletable, persisted to disk).
	SourceManaged Source = "managed"
)

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store holds the active auth configuration behind an atomic pointer, so Set hot-reloads it without locking readers.

func NewStore

func NewStore(cfg Config) (*Store, error)

NewStore builds a Store from cfg after validating it.

func (*Store) Allow

func (s *Store) Allow(accessKey, bucket string, action Action) bool

Allow reports whether the access key may perform action on bucket. A bucket of "" (e.g. ListBuckets) is allowed for any known key. Unknown keys are denied.

func (*Store) Owner added in v0.10.0

func (s *Store) Owner(accessKey string) (Identity, bool)

Owner returns the identity an access key acts as. Unknown keys report false.

func (*Store) PublicRead

func (s *Store) PublicRead(bucket string) bool

PublicRead reports whether bucket permits anonymous reads.

func (*Store) Secret

func (s *Store) Secret(accessKey string) (string, bool)

Secret returns the secret key for an access key, matching sigv4.SecretKeyFunc.

func (*Store) Set

func (s *Store) Set(cfg Config) error

Set atomically replaces the active configuration (hot reload).

Jump to

Keyboard shortcuts

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