Documentation
¶
Overview ¶
Package tokensvc does the I/O for token management: it finds the token config, reads and writes the five target files (Composer's auth.json, .npmrc, Docker's config.json, the git credential store and .netrc), and keeps every write inside the sandbox in dev mode. The formats themselves live in internal/core/tokens.
What it records is metadata only: the audit log and history get the target, the host and the file, never a secret.
Index ¶
- Constants
- Variables
- func Builtin() *tokens.Config
- func Delegated(configText string, hosts []string) map[string]string
- func DockerModes() []string
- func HasDockerDelegation(set *tokens.Set, path string) bool
- func LoadConfig(path string) (*tokens.Config, error)
- func ValidDockerMode(m string) bool
- type AliasStatus
- type CatalogSource
- type ConfigSource
- type DockerModeFunc
- type DockerResult
- type Env
- func (e Env) Checkup(set *tokens.Set, project string) (out []Finding, failed bool)
- func (e Env) Find(target, host, project string) (tokens.Installed, bool)
- func (e Env) FindConfig(explicit string) (ConfigSource, error)
- func (e Env) Forget(target, host, project string) (bool, error)
- func (e Env) Getenv(k string) string
- func (e Env) Guard(path string) error
- func (e Env) HomeFiles(fix bool) (out []Finding, failed bool, fixed []string)
- func (e Env) Host() tokens.Host
- func (e Env) Import(from string, dryRun bool) (src, to string, err error)
- func (e Env) Inventory(project string, reveal bool) []tokens.Installed
- func (e *Env) LoadEnvFile(path string) error
- func (e Env) Lookup(k string) (string, bool)
- func (e Env) Profile(file string, login bool) Profile
- func (e Env) ResolveConfig(explicit string) (cfg *tokens.Config, src ConfigSource, err error)
- func (e Env) SaveConfig(path string, c *tokens.Config) error
- func (e Env) Scaffold(dest string, targets []string) (string, error)
- func (e Env) SyncDocker(set *tokens.Set, path, mode string) (DockerResult, error)
- func (e Env) TargetPath(target, project string) string
- func (e Env) WriteAll(set *tokens.Set, targets []string, project string, mode DockerModeFunc, ...) error
- func (e Env) WriteTarget(set *tokens.Set, target, path string) ([]string, error)
- type Finding
- type Profile
Constants ¶
const ( ConfigEnv = envnames.TokensConfig LocalConfigName = "authama-tokens.json" LegacyConfigName = "auth-token-manager.json" )
Config file names and variables.
const ( // DockerLogin runs `docker login --password-stdin`, which stores the // credential where docker will actually read it. DockerLogin = "login" // DockerRefuse skips the host with a warning. DockerRefuse = "refuse" )
The docker credential-store modes.
const AliasBackupSuffix = ".authama.bak"
AliasBackupSuffix names the copy of a startup file taken before an edit.
const (
CatalogEnv = envnames.TokensCatalog
)
Catalog override variables. auth-token-manager read its catalog from $AUTH_TOKEN_MANAGER_CATALOG when set; authama reads $AUTHAMA_TOKENS_CATALOG first, then its pre-0.1.1 name $SSH_MANAGER_TOKENS_CATALOG, and still honours the oldest one.
const ConfigMode os.FileMode = 0o644
ConfigMode is the mode of a saved token config: it names variables, not secrets, so it is readable like any other config and safe to commit.
const SecretMode os.FileMode = 0o600
SecretMode is the mode every rendered credential file gets.
Variables ¶
var DockerLoginRunner = func(configDir, host, user, pass string) error { ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) defer cancel() cmd := exec.CommandContext(ctx, "docker", "--config", configDir, "login", host, "--username", user, "--password-stdin") cmd.Stdin = strings.NewReader(pass + "\n") out, err := cmd.CombinedOutput() if err != nil { return fmt.Errorf("docker login %s: %v: %s", host, err, strings.TrimSpace(string(out))) } return nil }
DockerLoginRunner runs docker login; tests replace it.
var ErrNoLegacyConfig = errors.New("no auth-token-manager config found")
ErrNoLegacyConfig means there is no auth-token-manager config to import.
var ErrOutsideSandbox = errors.New("is outside the dev-mode sandbox")
ErrOutsideSandbox is returned for a dev-mode write that would land outside the sandbox root.
Functions ¶
func Delegated ¶
Delegated reports which of hosts docker reads from a credential store or helper given the config text, and the helper that holds each.
func HasDockerDelegation ¶
HasDockerDelegation reports whether the docker config at path delegates any of set's docker hosts, so a caller can ask for a mode before writing.
func LoadConfig ¶
LoadConfig reads a token config.
func ValidDockerMode ¶
ValidDockerMode reports whether m is "", login or refuse.
Types ¶
type AliasStatus ¶
type AliasStatus struct {
File string
Exists bool
Present bool
Legacy bool // an auth-token-manager block is still there
Lines []string
}
AliasStatus is what a startup file holds.
type CatalogSource ¶
type CatalogSource struct {
// Path is the file in use; "" means the embedded catalog.
Path string
// Var is the variable that named it.
Var string
// Legacy is set when Var is auth-token-manager's name for it.
Legacy bool
// Warning is set when a variable named a file that is not there; the
// embedded catalog is used instead, as auth-token-manager did.
Warning string
// Err is set when the file is there but is not a usable catalog. The
// embedded catalog stays in use; the token commands refuse to run.
Err error
}
CatalogSource is the catalog a variable selected, if any.
type ConfigSource ¶
type ConfigSource struct {
Path string
// Legacy is set for an auth-token-manager location; the caller prints a
// deprecation notice pointing at `token import`.
Legacy bool
}
ConfigSource is where a token config came from.
type DockerModeFunc ¶
DockerModeFunc settles the credential-store mode for docker's file at dest. The CLI asks a person; the web and the TUI's callers pass a fixed answer.
func FixedDockerMode ¶
func FixedDockerMode(m string) DockerModeFunc
FixedDockerMode always answers m, refusing when m is empty.
type DockerResult ¶
type DockerResult struct {
Written []string // inline auths merged into config.json
LoggedIn []string // stored through docker login
Skipped []string // delegated and refused
Warnings []string
}
DockerResult says what happened to each docker host.
type Env ¶
type Env struct {
Paths paths.Paths
// Home is the directory the targets resolve under: the real home, or the
// sandbox's home in dev mode.
Home string
// Cwd anchors ./authama-tokens.json and the .gitignore check.
Cwd string
Windows bool
MacOS bool
// Catalog says where the token catalog came from when a variable
// replaced the embedded one; see CatalogEnv.
Catalog CatalogSource
// contains filtered or unexported fields
}
Env is where one invocation's token work happens.
func NewEnv ¶
NewEnv builds the token environment for a resolved layout. getenv and lookup read the process environment when nil.
In dev mode the variables that relocate a target file (COMPOSER_HOME, DOCKER_CONFIG, NETRC, ...) are hidden, so a sandboxed run resolves every target under the sandbox no matter what the shell exports. Secret variables are still read: a sandbox needs real values to render.
func (Env) Checkup ¶
Checkup reports, for each target (the set's, or all five), whether its file exists and is owner-only, that a present auth.json overrides $COMPOSER_AUTH, and whether .gitignore covers the files that hold secrets. failed is set when anything needs fixing.
func (Env) FindConfig ¶
func (e Env) FindConfig(explicit string) (ConfigSource, error)
FindConfig discovers the token config: --config, then $AUTHAMA_TOKENS_CONFIG, ./authama-tokens.json, <config home>/tokens.json, and then, deprecated, auth-token-manager's own locations. It returns a zero ConfigSource when there is none.
func (Env) Forget ¶
Forget deletes the credential for host from target's file, rewritten atomically and owner-only. It reports whether host was there.
func (Env) Guard ¶
Guard refuses, in dev mode, a write to a path outside the sandbox or to a symlink (which could point anywhere).
func (Env) HomeFiles ¶
HomeFiles is the doctor's view of the token files: each per-user target file that exists, and whether it is owner-only. With fix, a file that is not is chmod'ed to SecretMode first (inside the sandbox in dev mode), and fixed names it. The project-scoped .gitignore check stays in Checkup: the doctor runs from any directory and has no project to judge.
func (Env) Import ¶
Import copies a token config to <config home>/tokens.json: from, when given, else the first auth-token-manager config it finds, so the deprecated locations stop being read. The file is parsed first, so a broken one is refused rather than copied; the original is left in place, and an existing tokens.json is never overwritten. With dryRun nothing is written.
func (Env) Inventory ¶
Inventory lists every credential installed in the target files. Secrets are blanked unless reveal is set.
func (*Env) LoadEnvFile ¶
LoadEnvFile reads VAR=value lines into the lookup, without overriding variables that are already set, as --source did.
func (Env) Profile ¶
Profile picks the startup file: file when given, else the shell's rc (or login profile with login).
func (Env) ResolveConfig ¶
ResolveConfig finds the token config the way `token apply` does - explicit, then $AUTHAMA_TOKENS_CONFIG (or $SSH_MANAGER_TOKENS_CONFIG), ./authama-tokens.json, tokens.json in the config home, the legacy locations - and falls back to the built-in default. note says which of the last two it used, for the caller to show.
func (Env) SaveConfig ¶
SaveConfig writes a token config atomically.
func (Env) Scaffold ¶
Scaffold writes a starter config to dest, never over an existing file: the chosen targets' templates, or the all-targets example.
func (Env) SyncDocker ¶
SyncDocker writes the docker entries. Hosts docker reads inline are merged into config.json; hosts delegated to a credential store follow mode, which must already be resolved to login or refuse.
func (Env) TargetPath ¶
TargetPath is the file a target reads, optionally scoped to a project.
func (Env) WriteAll ¶
func (e Env) WriteAll(set *tokens.Set, targets []string, project string, mode DockerModeFunc, out, errw io.Writer) error
WriteAll writes each target's entries into its file, saying where on out and warning on errw. Every front end writes through here, so `token set`, `token apply`, the TUI and the web report a write the same way.
type Profile ¶
type Profile struct {
File string
// contains filtered or unexported fields
}
Profile is a shell startup file the aliases go in.
func (Profile) Install ¶
Install writes the block into the file (replacing an old one, and an auth-token-manager block). updated is set when a block was already there.
func (Profile) Remove ¶
Remove deletes the block from the file; removed is false when there was none.
func (Profile) Status ¶
func (pr Profile) Status() AliasStatus
Status reports the alias block in the file.