credential

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package credential manages named project tokens without exposing secret values through its metadata API. Encryption protects a database copy without its local key; cooperative processes running as the same user can access managed files.

Index

Constants

View Source
const (
	StatusPending              = "pending"
	StatusAvailable            = "available"
	StatusReplacementRequested = "replacement-requested"
	StatusInvalidated          = "invalidated"
	StatusExpired              = "expired"
	StatusRemovalPending       = "removal-pending"
)
View Source
const MaxMetadataBytes = 32 * 1024
View Source
const MaxMetadataEntries = 64
View Source
const MaxMetadataValueBytes = 4096
View Source
const MaxSecretBytes = 64 * 1024

Variables

View Source
var (
	ErrProjectNotFound     = errors.New("project not found")
	ErrProjectArchived     = errors.New("archived projects cannot mutate tokens")
	ErrTokenNotFound       = errors.New("token not found")
	ErrInvalidIdentifier   = errors.New("token identifier must use 1 to 128 ASCII letters, digits, dots, underscores or hyphens, start with a letter or digit, and cannot be request or list")
	ErrInvalidSecret       = errors.New("token must contain 1 to 65536 bytes without line breaks or NUL")
	ErrInvalidMetadata     = errors.New("token metadata is invalid or exceeds its size limits")
	ErrProtection          = errors.New("credential protection or materialization failed; no ready path is available")
	ErrCleanup             = errors.New("credential cleanup failed; the prior plaintext file may remain")
	ErrUnavailable         = errors.New("credential is unavailable")
	ErrUnsupportedPlatform = errors.New("credential protection is unsupported on this platform")
	ErrPersistence         = errors.New("credential persistence failed")
)

Functions

This section is empty.

Types

type RequestResult

type RequestResult struct {
	Status string `json:"status"`
	Path   string `json:"path,omitempty"`
	Token  Token  `json:"token"`
}

type Store

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

func Open

func Open(ctx context.Context, dbPath string) (*Store, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) Invalidate

func (s *Store) Invalidate(ctx context.Context, reference, id, by string) error

Invalidate discards ciphertext before attempting deletion; retries can only clean up the owned file and cannot reactivate the credential.

func (*Store) List

func (s *Store) List(ctx context.Context, reference string) ([]Token, error)

List returns metadata only, including pending replacement requests on invalidated identifiers.

func (*Store) Metadata added in v0.31.0

func (s *Store) Metadata(ctx context.Context, reference, id string) (map[string]string, error)

Metadata returns user-provided context only through this explicit read path.

func (*Store) Remove

func (s *Store) Remove(ctx context.Context, reference, id, by string) error

Remove retains a removal-pending tombstone until owned-file cleanup succeeds.

func (*Store) RemoveMetadata added in v0.31.0

func (s *Store) RemoveMetadata(ctx context.Context, reference, id, key, by string) error

RemoveMetadata deletes one key without recording its name or value in audits.

func (*Store) Request

func (s *Store) Request(ctx context.Context, reference, id string, refresh bool, by string) (RequestResult, error)

Request idempotently requests replacement or materializes the current value. Every mutation and file operation shares a native process lock so a request holding an old revision cannot recreate it after invalidation completes.

func (*Store) Set

func (s *Store) Set(ctx context.Context, reference, id string, secret []byte, expiry *time.Time, by string) (Token, error)

Set explicitly establishes a new usable revision. A materialization error may follow a committed encrypted value; a later Request repairs the file.

func (*Store) SetMetadata added in v0.31.0

func (s *Store) SetMetadata(ctx context.Context, reference, id, key, value, by string) error

SetMetadata stores one user-provided string value without adding it to audits.

func (*Store) Status

func (s *Store) Status(ctx context.Context, reference, id string) (Token, error)

type Token

type Token struct {
	ProjectID   int64      `json:"projectId"`
	Identifier  string     `json:"identifier"`
	Status      string     `json:"status"`
	Revision    int        `json:"revision"`
	ExpiresAt   *time.Time `json:"expiresAt,omitempty"`
	RequestedAt *time.Time `json:"requestedAt,omitempty"`
	CreatedAt   time.Time  `json:"createdAt"`
	UpdatedAt   time.Time  `json:"updatedAt"`
}

Jump to

Keyboard shortcuts

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