credential

package
v0.0.23 Latest Latest
Warning

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

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

func Lock added in v0.0.20

func Lock(key string) func()

Lock locks the key of a credential, in the process, and returns the function which unlocks it. A sign-in is stored under its key's lock, so code which reads a credential, and stores it again, such as a token which it refreshed, does so under the lock, and doesn't replace a sign-in which was stored after it read it. A credential which another process stores isn't locked.

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 CredentialAuthorization added in v0.0.22

type CredentialAuthorization struct {
	URL string `json:"url" help:"URL to sign in at, which expires after a while"`
}

CredentialAuthorization is the URL a person signs in at, in a browser, which redirects to the server's callback, which stores the sign-in

type CredentialAuthorize added in v0.0.22

type CredentialAuthorize struct {
	RedirectURI string   `` /* 181-byte string literal not displayed */
	Scopes      []string `json:"scopes,omitempty" help:"Scopes to ask for, such as those a sign-in error says"`
}

CredentialAuthorize asks for the URL a person signs in at, in a browser, with a server's web client, which redirects to the server's callback, rather than a loopback address, with the scopes which are asked for

type CredentialCode added in v0.0.20

type CredentialCode struct {
	Code         string `json:"code" help:"Code of the sign-in, which the authorization server redirected with"`
	CodeVerifier string `json:"code_verifier" help:"PKCE verifier of the code's challenge"`
	RedirectURI  string `json:"redirect_uri" help:"Loopback address the code was redirected to"`
}

CredentialCode is the code of a sign-in, which a client authorized, at a loopback address, with PKCE, which the server exchanges, with the client's secret, and stores the grant of, as the credential

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 CredentialSignIn added in v0.0.20

type CredentialSignIn struct {
	Key    string   `json:"key" help:"Credential key, of the sign-in"`
	Issuer string   `json:"issuer" help:"Authorization server which was signed in with"`
	Scopes []string `json:"scopes,omitempty" help:"Scopes the server granted, when it says"`
}

CredentialSignIn is a sign-in which is stored, as the credential, without its tokens

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
Package grant is the source of the access tokens of a sign-in, which is stored as a credential, such as by POST /credential/{key}/signin: the token is refreshed, with the secret of the client, which is another credential, and stored again, once it has expired.
Package grant is the source of the access tokens of a sign-in, which is stored as a credential, such as by POST /credential/{key}/signin: the token is refreshed, with the secret of the client, which is another credential, and stored again, once it has expired.
pg

Jump to

Keyboard shortcuts

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