auth

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 13 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

This section is empty.

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 Key

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

Key is a credential: an access/secret pair 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
)

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