credential

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 3 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

Index

Constants

View Source
const (
	// ScopeCredentialRead grants permission to list credentials, and get
	// their metadata, without their values
	ScopeCredentialRead = "credential:read"

	// ScopeCredentialWrite grants permission to set, delete and rotate
	// credentials
	ScopeCredentialWrite = "credential:write"

	// ScopeCredentialDecrypt grants permission to get a credential's value,
	// with the passphrase it was encrypted with
	ScopeCredentialDecrypt = "credential:decrypt"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Credential

type Credential struct {
	Key         string    `json:"key"`
	Description string    `json:"description,omitempty"`
	UpdatedAt   time.Time `json:"updated_at,omitzero"`
	Rotate      bool      `json:"rotate,omitempty"`
}

Credential is a stored credential's key, its description, when it was last changed, and whether it needs rotating, as it's encrypted with an older passphrase than the latest, which only managers which encrypt with their own passphrases say, without its value

type CredentialDecrypter

type CredentialDecrypter interface {
	// Decrypt returns the credential for the key, as JSON, when the
	// passphrase is the one it was encrypted with. Returns ErrForbidden when
	// it isn't, or ErrNotFound when there's no credential for the key.
	Decrypt(ctx context.Context, key, passphrase string) (json.RawMessage, error)
}

CredentialDecrypter is a provider which encrypts credentials with its own passphrases, and returns a credential only to a caller who knows the passphrase it was encrypted with

type CredentialDescription

type CredentialDescription struct {
	Description string `json:"description" help:"Credential description, such as what it's for, which is removed when it's empty"`
}

CredentialDescription is a request to change a credential's description, without its value

type CredentialList

type CredentialList struct {
	Count uint64       `json:"count"`
	Body  []Credential `json:"body,omitempty"`
}

CredentialList is the stored credentials, without their values

type CredentialManager

type CredentialManager interface {
	CredentialProvider

	// List returns the stored credentials, in key order, without their
	// values. Credentials from the environment aren't listed.
	List(ctx context.Context) ([]Credential, error)

	// Describe sets the description of the stored credential for the key,
	// such as what it's for, or removes it, when it's empty, and returns
	// ErrNotFound when there isn't one. Descriptions aren't secret, and
	// List returns them.
	Describe(ctx context.Context, key, description string) error
}

CredentialManager is a provider which manages its stored credentials, and can list and describe them

type CredentialProvider

type CredentialProvider interface {
	// Expand expands the given value using the credential provider, substituting any
	// credentials $PLACEHOLDER or ${PLACEHOLDER} as needed.
	Expand(ctx context.Context, value string) (string, error)

	// Get returns the credential for the key, as JSON
	Get(ctx context.Context, key string) (json.RawMessage, error)

	// Set stores the credential for the key, which is JSON, replacing any
	// credential with the key
	Set(ctx context.Context, key string, value json.RawMessage) error

	// Delete removes the stored credential for the key, and returns
	// ErrNotFound when there isn't one, or ErrNotImplemented when the
	// provider can't store credentials, such as the environment. A
	// credential from the environment can't be deleted.
	Delete(ctx context.Context, key string) error
}

type CredentialRotator

type CredentialRotator interface {
	// Rotate re-encrypts the credential for the key with the latest
	// passphrase, and returns ErrNotModified when it already uses it, or
	// ErrNotFound when there isn't one
	Rotate(ctx context.Context, key string) error
}

CredentialRotator is a provider which encrypts credentials with its own passphrases, and can re-encrypt them with the latest one

type CredentialSet

type CredentialSet struct {
	Key         string          `json:"key" help:"Credential key, an identifier"`
	Credentials json.RawMessage `json:"credentials" help:"Credential value, which can be any JSON value"`
	Description *string         `` /* 143-byte string literal not displayed */
}

CredentialSet is a request to store a credential, replacing any credential with the key, and its description, when it's set

type Features

type Features struct {
	Backend string `json:"backend" help:"The manager's backend, such as file, pg, aws or bitwarden"`
	Decrypt bool   `json:"decrypt" help:"Whether a credential's value can be read, with the passphrase it was encrypted with"`
	Rotate  bool   `json:"rotate" help:"Whether a credential can be re-encrypted with the latest passphrase"`
}

Features is what a credential manager can do, beyond storing, listing and deleting credentials, which a server says in its configuration, so its web UI only offers what the manager can do

func FeaturesOf

func FeaturesOf(backend string, manager CredentialManager) Features

FeaturesOf returns what the manager of the backend, such as file, can do, from the interfaces it implements: CredentialDecrypter, and CredentialRotator, which the file and pg managers do, and the others don't, as they encrypt with their own keys

Directories

Path Synopsis
pg

Jump to

Keyboard shortcuts

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