{"modulePath":"github.com/GoCodeAlone/workflow","version":"v0.87.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package secrets\n\nPackage secrets provides secret storage backends (Provider), secret:// reference resolution (Resolver), and two complementary redaction utilities.\n\n### Two redaction categories — pick the right one {#hdr-Two_redaction_categories___pick_the_right_one}\n\nThe package offers two DISTINCT ways to scrub secret material, addressing two different threat shapes. They are NOT interchangeable:\n\n  - KEY-name masking — MaskSensitiveOutputs (masking.go). Given a structured outputs map (e.g. a step's key/value results) and a set of sensitive KEY names (\"password\", \"token\", \"connection\\_string\", ...), it replaces the VALUES of those keys with \"(sensitive)\". It never scans free text and never needs to know the secret's value — only its key. Use it for structured maps whose key set is known and trusted.\n\n  - VALUE scanning — Redactor (redactor.go). Given an arbitrary blob of free text (a log line, a chat message, an LLM prompt body) and a set of previously-seen secret VALUES, it replaces every substring equal to a known value with \"\\[REDACTED:label]\". It does not care about KEY names in the text; it matches purely on value. Use it when the secret may appear anywhere in free text and only its value is known.\n\nA typical engine integration arms a Redactor from a Provider (List+Get) at startup and on hot-swap, then runs Redact over every message/transcript body before it leaves the process. Structured step outputs flow through MaskSensitiveOutputs instead.\n\n### Redactor graceful-degrade contract {#hdr-Redactor_graceful_degrade_contract}\n\nRedactor.LoadFromProvider is designed to be wired BEFORE its backing provider is reachable. If the provider's List call fails (read-only-without-list, not-yet-started, temporarily unavailable) LoadFromProvider returns nil and leaves the existing known-value set UNTOUCHED — it never panics and never empties the redactor on a List error. This lets a caller register a Redactor at construction time and re-arm it once the provider comes online (lazy resolve + hot-swap) without risking a window where the redactor is empty.\n\nAddValue is the additive path: it merges a single value into the set without disturbing the rest. LoadFromProvider is the bulk/full-replace path: it swaps the entire set from the provider's current state. The two compose — callers may seed a few values via AddValue and then refresh from a provider.\n\n## Constants\n\n```go\nconst SecretPrefix = \"secret://\"\n```\nSecretPrefix is the URI scheme used in config values to reference secrets.\n\n## Variables\n\n```go\nvar (\n\tErrNotFound     = errors.New(\"secrets: secret not found\")\n\tErrUnsupported  = errors.New(\"secrets: operation not supported\")\n\tErrInvalidKey   = errors.New(\"secrets: invalid key\")\n\tErrProviderInit = errors.New(\"secrets: provider initialization failed\")\n)\n```\nCommon errors.\n\n## Functions\n\n```go\nfunc DefaultSensitiveKeys() []string\n```\nDefaultSensitiveKeys returns the default set of output keys considered sensitive.\n\n```go\nfunc GenerateSecret(ctx context.Context, genType string, config map[string]any) (string, error)\n```\nGenerateSecret produces a secret value based on genType and config. Supported types: \"random\\_hex\", \"random\\_base64\", \"random\\_alphanumeric\", \"provider\\_credential\". For \"provider\\_credential\", the returned string is a JSON-encoded map.\n\n```go\nfunc MaskSensitiveOutputs(outputs map[string]any, sensitiveKeys []string) map[string]any\n```\nMaskSensitiveOutputs returns a copy of outputs with sensitive values replaced by \"(sensitive)\". sensitiveKeys is the merged set of keys to mask.\n\n```go\nfunc MergeSensitiveKeys(driverKeys []string) []string\n```\nMergeSensitiveKeys combines driver-specific keys with the defaults, deduplicating.\n\n## Types\n\n```go\ntype AWSConfig struct {\n\tRegion          string `json:\"region\" yaml:\"region\"`\n\tAccessKeyID     string `json:\"accessKeyId,omitempty\" yaml:\"accessKeyId,omitempty\"`\n\tSecretAccessKey string `json:\"secretAccessKey,omitempty\" yaml:\"secretAccessKey,omitempty\"`\n}\n```\nAWSConfig holds configuration for AWS Secrets Manager.\n\n```go\ntype AWSSecretsManagerProvider struct {\n\t// contains filtered or unexported fields\n}\n```\nAWSSecretsManagerProvider reads secrets from AWS Secrets Manager using the HTTP API with AWS Signature V4 signing. No external AWS SDK is required.\n\n```go\nfunc NewAWSSecretsManagerProvider(cfg AWSConfig) (*AWSSecretsManagerProvider, error)\n```\nNewAWSSecretsManagerProvider creates a new AWS Secrets Manager provider. If AccessKeyID/SecretAccessKey are empty, it falls back to the environment variables AWS\\_ACCESS\\_KEY\\_ID and AWS\\_SECRET\\_ACCESS\\_KEY.\n\n```go\nfunc NewAWSSecretsManagerProviderWithClient(cfg AWSConfig, client HTTPClient) *AWSSecretsManagerProvider\n```\nNewAWSSecretsManagerProviderWithClient creates an AWS provider with a custom HTTP client (for testing).\n\n```go\nfunc (p *AWSSecretsManagerProvider) CheckAccess(ctx context.Context) error\n```\nCheckAccess implements AccessChecker. It performs a lightweight check by attempting to list secrets. Errors never contain credential material.\n\n```go\nfunc (p *AWSSecretsManagerProvider) Config() AWSConfig\n```\nConfig returns the provider's AWS configuration.\n\n```go\nfunc (p *AWSSecretsManagerProvider) Delete(_ context.Context, _ string) error\n```\n\n```go\nfunc (p *AWSSecretsManagerProvider) Get(ctx context.Context, key string) (string, error)\n```\n\n```go\nfunc (p *AWSSecretsManagerProvider) List(ctx context.Context) ([]string, error)\n```\nList returns the names of all secrets using the ListSecrets API with pagination.\n\n```go\nfunc (p *AWSSecretsManagerProvider) Name() string\n```\n\n```go\nfunc (p *AWSSecretsManagerProvider) SecretTarget() ProviderTarget\n```\nSecretTarget describes the AWS Secrets Manager region namespace.\n\n```go\nfunc (p *AWSSecretsManagerProvider) Set(_ context.Context, _ string, _ string) error\n```\n\n```go\nfunc (p *AWSSecretsManagerProvider) StatAll(ctx context.Context) ([]SecretMeta, error)\n```\nStatAll implements MetadataProvider on a best-effort basis. It lists secret names from AWS Secrets Manager and returns them with Exists=true and zero UpdatedAt (LastChangedDate is not fetched to avoid N+1 API calls). Returns ErrUnsupported when listing is not available.\n\n```go\ntype AccessChecker interface {\n\tCheckAccess(ctx context.Context) error\n}\n```\nAccessChecker is optional: verify the store is reachable + usable for setup. CheckAccess MUST NOT leak credential material in its error.\n\n```go\ntype DevVaultConfig struct {\n\t// RootToken is the root token for the dev server. Default: \"dev-root-token\".\n\tRootToken string\n\t// ListenAddr is the address to listen on. Default: \"127.0.0.1:0\" (random port).\n\tListenAddr string\n\t// MountPath is the KV v2 mount path. Default: \"secret\".\n\tMountPath string\n}\n```\nDevVaultConfig holds configuration for a managed Vault dev server.\n\n```go\ntype DevVaultProvider struct {\n\t*VaultProvider\n\t// contains filtered or unexported fields\n}\n```\nDevVaultProvider manages a Vault dev server subprocess and provides a real VaultProvider connected to it. This is useful for local development and integration testing without requiring an external Vault server.\n\n```go\nfunc NewDevVaultProvider(cfg DevVaultConfig) (*DevVaultProvider, error)\n```\nNewDevVaultProvider starts a Vault dev server and returns a provider connected to it. It finds the vault binary on PATH, starts it with -dev mode, waits for readiness, and returns a fully functional VaultProvider.\n\nThe caller must call Close() to stop the subprocess.\n\nReturns an error if the vault binary is not found or the server fails to start.\n\n```go\nfunc (p *DevVaultProvider) Addr() string\n```\nAddr returns the listen address of the dev server.\n\n```go\nfunc (p *DevVaultProvider) Close() error\n```\nClose stops the Vault dev server subprocess and cleans up.\n\n```go\ntype EnvProvider struct {\n\t// contains filtered or unexported fields\n}\n```\nEnvProvider reads secrets from environment variables. Keys are converted to uppercase with dots replaced by underscores. For example, \"database.password\" becomes \"DATABASE\\_PASSWORD\".\n\n```go\nfunc NewEnvProvider(prefix string) *EnvProvider\n```\nNewEnvProvider creates a new environment variable secret provider. If prefix is non-empty, it is prepended to all key lookups (e.g., prefix \"APP\\_\" + key \"db\\_pass\" -\u003e \"APP\\_DB\\_PASS\").\n\n```go\nfunc (p *EnvProvider) CheckAccess(_ context.Context) error\n```\nCheckAccess implements AccessChecker. For EnvProvider, access is always available.\n\n```go\nfunc (p *EnvProvider) Delete(_ context.Context, key string) error\n```\n\n```go\nfunc (p *EnvProvider) Get(_ context.Context, key string) (string, error)\n```\n\n```go\nfunc (p *EnvProvider) List(_ context.Context) ([]string, error)\n```\n\n```go\nfunc (p *EnvProvider) Name() string\n```\n\n```go\nfunc (p *EnvProvider) SecretTarget() ProviderTarget\n```\nSecretTarget describes the current process environment namespace.\n\n```go\nfunc (p *EnvProvider) Set(_ context.Context, key, value string) error\n```\n\n```go\nfunc (p *EnvProvider) StatAll(_ context.Context) ([]SecretMeta, error)\n```\nStatAll implements MetadataProvider. It lists env vars that match the prefix (same logic as List) and returns SecretMeta with Exists=true and zero UpdatedAt (env vars have no last-modified timestamp).\n\n```go\ntype EnvironmentManager interface {\n\tListEnvironments(ctx context.Context) ([]ProviderEnvironment, error)\n\tValidateEnvironment(ctx context.Context, name string) (ProviderEnvironment, error)\n\tEnsureEnvironment(ctx context.Context, name string) (ProviderEnvironment, error)\n}\n```\nEnvironmentManager is optional: providers implement it when they can inspect and create environment-like namespaces used by scoped secrets.\n\nValidateEnvironment must return an error wrapping ErrNotFound when the named environment is absent, and an error wrapping ErrInvalidKey when name is empty or invalid for the provider. EnsureEnvironment must be idempotent: it returns existing environment metadata when present, creates the environment when it is absent, and returns provider metadata for the resulting environment.\n\n```go\ntype FileProvider struct {\n\t// contains filtered or unexported fields\n}\n```\nFileProvider reads secrets from files in a directory. Each file name is the secret key, and the file content is the value. This is compatible with Kubernetes secret volume mounts.\n\n```go\nfunc NewFileProvider(dir string) *FileProvider\n```\nNewFileProvider creates a file-based secret provider rooted at dir.\n\n```go\nfunc (p *FileProvider) CheckAccess(_ context.Context) error\n```\nCheckAccess implements AccessChecker. It verifies the directory exists and is writable by attempting to create (then remove) a probe file.\n\n```go\nfunc (p *FileProvider) Delete(_ context.Context, key string) error\n```\n\n```go\nfunc (p *FileProvider) Get(_ context.Context, key string) (string, error)\n```\n\n```go\nfunc (p *FileProvider) List(_ context.Context) ([]string, error)\n```\n\n```go\nfunc (p *FileProvider) Name() string\n```\n\n```go\nfunc (p *FileProvider) SecretTarget() ProviderTarget\n```\nSecretTarget describes the directory-backed file secret namespace.\n\n```go\nfunc (p *FileProvider) Set(_ context.Context, key, value string) error\n```\n\n```go\nfunc (p *FileProvider) StatAll(_ context.Context) ([]SecretMeta, error)\n```\nStatAll implements MetadataProvider. It returns SecretMeta for every file in the directory, using the file's modification time as UpdatedAt.\n\n```go\ntype GitHubOrgVisibility string\n```\nGitHubOrgVisibility controls who can pull an org-scoped secret. Mirrors GitHub's API field; one of \"all\", \"selected\", \"private\".\n\n```go\nconst (\n\tOrgVisibilityAll      GitHubOrgVisibility = \"all\"\n\tOrgVisibilitySelected GitHubOrgVisibility = \"selected\"\n\tOrgVisibilityPrivate  GitHubOrgVisibility = \"private\"\n)\n```\n\n```go\ntype GitHubSecretScope string\n```\nGitHubSecretScope selects which GitHub secret namespace a provider writes to. Default zero value = repo (backwards-compat).\n\n\tGitHubScopeRepo → /repos/{owner}/{repo}/actions/secrets/...\n\tGitHubScopeEnv  → /repos/{owner}/{repo}/environments/{env}/secrets/...\n\tGitHubScopeOrg  → /orgs/{org}/actions/secrets/...\n\n```go\nconst (\n\tGitHubScopeRepo GitHubSecretScope = \"repo\"\n\tGitHubScopeEnv  GitHubSecretScope = \"env\"\n\tGitHubScopeOrg  GitHubSecretScope = \"org\"\n)\n```\n\n```go\ntype GitHubSecretsProvider struct {\n\t// contains filtered or unexported fields\n}\n```\nGitHubSecretsProvider manages GitHub Actions secrets at repo, env, or org scope. Secrets are write-only on GitHub, so Get() returns ErrUnsupported.\n\n```go\nfunc NewGitHubOrgSecretsProvider(org string, tokenEnvVar string, visibility GitHubOrgVisibility, selectedRepoIDs []int64) (*GitHubSecretsProvider, error)\n```\nNewGitHubOrgSecretsProvider creates an org-scoped provider. visibility is one of OrgVisibilityAll / Selected / Private. selectedRepoIDs is required iff visibility=Selected.\n\nRequires the token to have admin:org scope.\n\n```go\nfunc NewGitHubSecretsProvider(repo string, tokenEnvVar string) (*GitHubSecretsProvider, error)\n```\nNewGitHubSecretsProvider creates a repo-scoped provider for the given \"owner/repo\". tokenEnvVar is the name of the environment variable holding the GitHub token. Backwards-compatible — sets scope=repo.\n\n```go\nfunc (p *GitHubSecretsProvider) CheckAccess(ctx context.Context) error\n```\nCheckAccess implements AccessChecker. It verifies the configured credentials have at least read access by fetching the public key. Errors never contain credential material.\n\n```go\nfunc (p *GitHubSecretsProvider) CheckVariable(ctx context.Context, key string) (VariableMeta, error)\n```\nCheckVariable reports whether a GitHub Actions variable exists without returning its value.\n\n```go\nfunc (p *GitHubSecretsProvider) Delete(ctx context.Context, key string) error\n```\nDelete removes a GitHub Actions secret.\n\n```go\nfunc (p *GitHubSecretsProvider) DeleteVariable(ctx context.Context, key string) error\n```\nDeleteVariable removes a GitHub Actions variable.\n\n```go\nfunc (p *GitHubSecretsProvider) EnsureEnvironment(ctx context.Context, name string) (ProviderEnvironment, error)\n```\nEnsureEnvironment creates the GitHub Actions environment when it is missing.\n\n```go\nfunc (p *GitHubSecretsProvider) Environment() string\n```\nEnvironment returns the configured GitHub Actions environment scope.\n\n```go\nfunc (p *GitHubSecretsProvider) Get(_ context.Context, _ string) (string, error)\n```\nGet always returns ErrUnsupported because GitHub secrets are write-only.\n\n```go\nfunc (p *GitHubSecretsProvider) List(ctx context.Context) ([]string, error)\n```\nList returns the names of all GitHub Actions secrets for the repo.\n\n```go\nfunc (p *GitHubSecretsProvider) ListEnvironments(ctx context.Context) ([]ProviderEnvironment, error)\n```\nListEnvironments returns the GitHub Actions environments defined for the configured repository.\n\n```go\nfunc (p *GitHubSecretsProvider) ListVariables(ctx context.Context) ([]VariableMeta, error)\n```\nListVariables returns metadata for GitHub Actions variables in the configured repo, environment, or organization scope. Returned values are redacted.\n\n```go\nfunc (p *GitHubSecretsProvider) Name() string\n```\n\n```go\nfunc (p *GitHubSecretsProvider) Scope() GitHubSecretScope\n```\nScope reports the current scope.\n\n```go\nfunc (p *GitHubSecretsProvider) SecretTarget() ProviderTarget\n```\nSecretTarget describes the GitHub Actions secret namespace represented by this provider: repository, environment, or organization.\n\n```go\nfunc (p *GitHubSecretsProvider) Set(ctx context.Context, key, value string) error\n```\nSet encrypts value with the repo's public key and stores it as a secret.\n\n```go\nfunc (p *GitHubSecretsProvider) SetEnvironment(environment string)\n```\nSetEnvironment scopes subsequent operations to a GitHub Actions environment. Empty scope means repository-level secrets. Calling SetEnvironment with a non-empty value flips scope to env.\n\n```go\nfunc (p *GitHubSecretsProvider) SetVariable(ctx context.Context, key, value string) error\n```\nSetVariable creates or updates a GitHub Actions variable in the configured repo, environment, or organization scope.\n\n```go\nfunc (p *GitHubSecretsProvider) StatAll(ctx context.Context) ([]SecretMeta, error)\n```\nStatAll implements MetadataProvider. It returns presence + timestamp for every secret visible to the configured token. UpdatedAt is the updated\\_at field from GitHub, falling back to created\\_at when updated\\_at is zero.\n\n```go\nfunc (p *GitHubSecretsProvider) ValidateEnvironment(ctx context.Context, name string) (ProviderEnvironment, error)\n```\nValidateEnvironment verifies that a GitHub Actions environment exists for the configured repository.\n\n```go\ntype HTTPClient interface {\n\tDo(req *http.Request) (*http.Response, error)\n}\n```\nHTTPClient is an interface for HTTP requests (allows testing). Used by the AWS Secrets Manager provider.\n\n```go\ntype KeychainProvider struct {\n\t// contains filtered or unexported fields\n}\n```\nKeychainProvider implements Provider using the OS credential store (macOS Keychain, Linux Secret Service, Windows Credential Manager).\n\nAll keys are namespaced under a single \"service\" string so multiple workflow services on the same machine don't collide.\n\nOn Linux, requires a running Secret Service implementation (libsecret, gnome-keyring, or KWallet). Headless servers without one should use FileProvider or VaultProvider instead.\n\nKeychainProvider is safe for concurrent use. mu guards all access to trackedKeys.\n\n```go\nfunc NewKeychainProvider(service string) (*KeychainProvider, error)\n```\nNewKeychainProvider returns a provider namespaced to the given service name. Service must not be empty — an empty service stores secrets in a shared namespace where they can collide across applications.\n\n```go\nfunc (p *KeychainProvider) Delete(ctx context.Context, key string) error\n```\nDelete removes the secret stored under key from the OS keychain.\n\n```go\nfunc (p *KeychainProvider) Get(ctx context.Context, key string) (string, error)\n```\nGet retrieves the secret stored under the given key from the OS keychain.\n\n```go\nfunc (p *KeychainProvider) List(ctx context.Context) ([]string, error)\n```\nList returns all keys that have been set during the lifetime of this provider instance.\n\n```go\nfunc (p *KeychainProvider) Name() string\n```\nName returns the provider identifier \"keychain\".\n\n```go\nfunc (p *KeychainProvider) SecretTarget() ProviderTarget\n```\nSecretTarget describes the OS keychain service namespace.\n\n```go\nfunc (p *KeychainProvider) Set(ctx context.Context, key, value string) error\n```\nSet stores the given value under key in the OS keychain.\n\n```go\ntype MetadataProvider interface {\n\tProvider\n\tStatAll(ctx context.Context) ([]SecretMeta, error)\n}\n```\nMetadataProvider is optional: stores that can report which keys exist and when they changed.\n\n```go\ntype MultiResolver struct {\n\t// contains filtered or unexported fields\n}\n```\nMultiResolver resolves secret references in configuration values using multiple providers identified by URI scheme. It is backward-compatible: bare ${VAR\\_NAME} references (without a scheme) default to env resolution.\n\n```go\nfunc NewMultiResolver() *MultiResolver\n```\nNewMultiResolver creates a new MultiResolver. An EnvProvider is registered by default under the \"env\" scheme.\n\n```go\nfunc (m *MultiResolver) Expand(ctx context.Context, input string) (string, error)\n```\nExpand replaces all ${...} patterns in input with resolved values.\n\nSupported formats:\n\n  - ${vault:secret/path#field} — uses \"vault\" provider with key \"secret/path#field\"\n  - ${aws-sm:secret-name} — uses \"aws-sm\" provider with key \"secret-name\"\n  - ${env:VAR\\_NAME} — uses \"env\" provider with key \"VAR\\_NAME\"\n  - ${VAR\\_NAME} — backward-compatible, uses \"env\" provider (os.LookupEnv via EnvProvider)\n\n```go\nfunc (m *MultiResolver) Provider(scheme string) Provider\n```\nProvider returns the provider for a given scheme, or nil if not found.\n\n```go\nfunc (m *MultiResolver) Register(scheme string, provider Provider)\n```\nRegister adds or replaces a provider for a given scheme.\n\n```go\nfunc (m *MultiResolver) Schemes() []string\n```\nSchemes returns the list of registered provider schemes.\n\n```go\nfunc (m *MultiResolver) Unregister(scheme string)\n```\nUnregister removes a provider for the given scheme.\n\n```go\ntype Provider interface {\n\t// Name returns the provider identifier.\n\tName() string\n\t// Get retrieves a secret value by key.\n\tGet(ctx context.Context, key string) (string, error)\n\t// Set stores a secret. Returns ErrUnsupported if read-only.\n\tSet(ctx context.Context, key, value string) error\n\t// Delete removes a secret. Returns ErrUnsupported if read-only.\n\tDelete(ctx context.Context, key string) error\n\t// List returns all available secret keys. Returns ErrUnsupported if not supported.\n\tList(ctx context.Context) ([]string, error)\n}\n```\nProvider defines the interface for secret storage backends.\n\n```go\ntype ProviderEnvironment struct {\n\tProvider string\n\tName     string\n\tLabel    string\n\tExists   bool\n\tSource   string\n}\n```\nProviderEnvironment describes a provider-owned environment or namespace used as a secret target. It is intentionally metadata-only and must never include secret values or credential material.\n\n```go\ntype ProviderTarget struct {\n\tProvider string\n\tScope    string\n\tSubject  string\n\tLabel    string\n}\n```\nProviderTarget describes the concrete provider namespace a Provider instance reads or writes. It is intentionally value-only and must not include secret values or credential material.\n\n```go\nfunc DescribeTarget(provider Provider) ProviderTarget\n```\nDescribeTarget returns a safe provider-owned target description. Providers that do not implement TargetDescriber fall back to their Name.\n\n```go\ntype Redactor struct {\n\t// contains filtered or unexported fields\n}\n```\nRedactor is a concurrency-safe, free-text VALUE scanner that replaces any occurrence of a known secret value inside an arbitrary string with the token \"\\[REDACTED:label]\". It is the engine's shared utility for scrubbing secret material out of human-facing text (logs, transcripts, agent messages, LLM prompts) where the secret's KEY is not known ahead of time — only its VALUE.\n\n### VALUE-scan (Redactor) vs KEY-mask (MaskSensitiveOutputs) {#hdr-VALUE_scan__Redactor__vs_KEY_mask__MaskSensitiveOutputs_}\n\nThe secrets package provides two DISTINCT redaction categories; do not conflate them:\n\n  - MaskSensitiveOutputs (masking.go) is a KEY-name mask: given a structured outputs map, it replaces the VALUES of a fixed set of sensitive KEYS (\"password\", \"token\", ...) with the literal \"(sensitive)\". It does not scan free text and does not need to know the secret value.\n\n  - Redactor (this type) is a VALUE scan: given an arbitrary blob of text, it finds substrings equal to a previously-seen secret VALUE and replaces them. It does not care about KEY names in the text; it matches on value.\n\nUse MaskSensitiveOutputs for structured key/value maps whose key set is known. Use Redactor when the secret may appear anywhere in free text (chat messages, log lines, prompt bodies) and only its value is known.\n\n### Graceful-degrade contract {#hdr-Graceful_degrade_contract}\n\nLoadFromProvider degrades gracefully: if the provider's List call fails (for example because the provider is read-only-without-list, unavailable, or not yet started) LoadFromProvider returns nil and leaves the existing known-value set untouched rather than panicking or emptying the redactor. This lets a caller wire a Redactor before its backing provider is reachable and re-arm it once the provider comes online. A nil Redactor is also safe to call: NewRedactor is not required for zero-value usage, but the helper makes the intent explicit and pre-allocates the map.\n\n```go\nfunc NewRedactor() *Redactor\n```\nNewRedactor returns a ready-to-use Redactor with an empty known-value set. The returned value is safe for concurrent use immediately.\n\n```go\nfunc (r *Redactor) AddValue(label, value string)\n```\nAddValue registers a single secret value under the given label and merges it additively into the existing known-value set. Subsequent calls to Redact will replace every occurrence of value with \"\\[REDACTED:label]\".\n\nIf value is the empty string the call is a no-op: empty values cannot be meaningfully scanned for as substrings and would over-match.\n\nAddValue is concurrency-safe and may be called concurrently with Redact and LoadFromProvider.\n\n```go\nfunc (r *Redactor) LoadFromProvider(ctx context.Context, p Provider) error\n```\nLoadFromProvider performs a FULL-REPLACE of the known-value set from a secrets.Provider: it enumerates the provider's keys via List, resolves each via Get, builds a fresh map off-lock, then swaps it in under a single write lock. Any value previously added via AddValue that is not present in the provider is dropped.\n\nLoadFromProvider degrades gracefully (see the graceful-degrade contract on Redactor): if List returns an error the call returns nil and leaves the existing known-value set untouched — it does NOT panic and does NOT empty the redactor. Individual Get errors for a key skip that key but do not fail the whole load. Empty-string values from the provider are skipped.\n\nA nil Redactor is tolerated: LoadFromProvider is a no-op.\n\n```go\nfunc (r *Redactor) Redact(text string) string\n```\nRedact returns text with every occurrence of each known secret value replaced by \"\\[REDACTED:label]\". The scan is a plain substring match (not a regexp): it is safe to use on untrusted input but callers should not rely on it for canonicalization — only for scrubbing.\n\nRedact is concurrency-safe and may be called concurrently with AddValue and LoadFromProvider. A nil Redactor returns the input text unchanged.\n\nValues are applied longest-first so a shorter secret that is a substring of a longer one cannot shadow it (which would leave the longer value partially unredacted). The known set is snapshotted under the read lock, then the substring scan runs lock-free over the snapshot, giving deterministic output independent of map iteration order.\n\n```go\nfunc (r *Redactor) RedactMessage(content string) (string, bool)\n```\nRedactMessage redacts content and reports whether any substitution occurred. It is the convenience wrapper for callers (e.g. message pipelines) that want to know whether a message was altered without diffing the strings. A nil Redactor returns (content, false).\n\n```go\ntype Resolver struct {\n\t// contains filtered or unexported fields\n}\n```\nResolver resolves secret:// references in configuration values.\n\n```go\nfunc NewResolver(provider Provider) *Resolver\n```\nNewResolver creates a resolver backed by the given provider.\n\n```go\nfunc (r *Resolver) Provider() Provider\n```\nProvider returns the underlying provider.\n\n```go\nfunc (r *Resolver) Resolve(ctx context.Context, value string) (string, error)\n```\nResolve replaces a value containing a secret:// reference with the actual secret. If the value does not start with SecretPrefix, it is returned as-is.\n\n```go\nfunc (r *Resolver) ResolveMap(ctx context.Context, m map[string]any) (map[string]any, error)\n```\nResolveMap resolves all secret:// references in a string map.\n\n```go\ntype Result struct {\n\tReachable bool\n\tReason    string\n}\n```\nResult holds the outcome of a Reachability check.\n\nReachable is true when the secrets provider can be reached from the given execution environment. Reason is empty when Reachable is true, and contains a human-readable (non-credential-leaking) explanation when Reachable is false.\n\n```go\nfunc Reachability(ctx context.Context, p Provider, execEnv string) Result\n```\nReachability determines whether the secrets referenced by a plan can be read from the given execution environment (execEnv). It is designed to be fail-safe: when the answer is uncertain and the exec-env is remote, it returns unreachable rather than failing open.\n\nctx bounds any backend probe (AccessChecker.CheckAccess). Callers MUST pass a deadline-bearing context (e.g. the pipeline/route ctx) so a slow or unreachable remote backend cannot hang the pre-flight (vault default ~60s, aws ~10s) past the request deadline.\n\nClassification uses a concrete type-switch rather than Name() string-matching. Name() is a config-assigned identifier that operators may override; the concrete type is the authoritative signal for capability detection.\n\nRules (in order):\n\n 1. \\*EnvProvider, \\*FileProvider, \\*KeychainProvider — host-local backends. Reachable ONLY when execEnv is local (\"\" | \"local\" | \"local-docker\"). For a REMOTE exec-env these are fail-safe UNREACHABLE: under the agent-side-resolution model (ADR 0017), a remote exec-env resolves secrets with the remote agent's OWN provider, so the engine cannot vouch that the engine-host's env vars / files / OS keychain exist on the remote runner (e.g. a macOS keychain entry is not present on a remote Linux runner). This is intentionally conservative: it is the safe default until the agent-probe hardening filed in ADR 0017 lands.\n\n 2. \\*GitHubSecretsProvider — short-circuited to unreachable BEFORE any AccessChecker call.  GitHub secrets are write-only: Get() returns ErrUnsupported and values are only injected at CI-job startup. No exec-env can read them at runtime. CheckAccess on the GitHub provider would succeed (it probes the public key endpoint, not Get), so probing it would give a false \"reachable\" verdict.\n\n 3. All other providers that implement AccessChecker — call CheckAccess(ctx). Reachable iff CheckAccess returns nil.\n\n 4. Providers that do NOT implement AccessChecker + remote execEnv — fail-safe unreachable (\"reachability unknown for remote exec-env; assuming unreachable\"). We never fail open for an unknown/unclassified backend in a remote context.\n\n 5. Providers that do NOT implement AccessChecker + local execEnv — treat as reachable (local operation; the runtime will surface access errors if any).\n\n```go\ntype RotationProvider interface {\n\tProvider\n\t// Rotate generates a new secret value and stores it, returning the new value.\n\tRotate(ctx context.Context, key string) (string, error)\n\t// GetPrevious retrieves the previous version of a rotated secret (for grace periods).\n\tGetPrevious(ctx context.Context, key string) (string, error)\n}\n```\nRotationProvider extends Provider with key rotation capabilities.\n\n```go\ntype SecretMeta struct {\n\tName      string\n\tExists    bool\n\tUpdatedAt time.Time // zero when the store doesn't expose it\n}\n```\nSecretMeta is presence + freshness for one key. Never carries a value.\n\n```go\ntype TargetDescriber interface {\n\tSecretTarget() ProviderTarget\n}\n```\nTargetDescriber is optional: providers implement it when they can describe their concrete namespace, such as GitHub repo/env/org or AWS region.\n\n```go\ntype VariableMeta struct {\n\tName      string\n\tValue     string\n\tExists    bool\n\tUpdatedAt time.Time\n}\n```\nVariableMeta is presence + freshness for one non-secret configuration variable. Value is intentionally optional and callers should usually leave it empty in status displays; provider variables are not credentials, but they can still carry operational details that do not belong in logs.\n\n```go\ntype VariableProvider interface {\n\tName() string\n\tSetVariable(ctx context.Context, key, value string) error\n\tDeleteVariable(ctx context.Context, key string) error\n\tListVariables(ctx context.Context) ([]VariableMeta, error)\n\tCheckVariable(ctx context.Context, key string) (VariableMeta, error)\n}\n```\nVariableProvider is the provider-side analog to Provider for non-sensitive setup values such as GitHub Actions variables. It must not be used for credential material; sensitive plugin requirements belong in Provider.\n\n```go\ntype VaultConfig struct {\n\tAddress   string `json:\"address\" yaml:\"address\"`\n\tToken     string `json:\"token\" yaml:\"token\"`\n\tMountPath string `json:\"mount_path\" yaml:\"mount_path\"`\n\tNamespace string `json:\"namespace,omitempty\" yaml:\"namespace,omitempty\"`\n}\n```\nVaultConfig holds configuration for HashiCorp Vault.\n\n```go\ntype VaultProvider struct {\n\t// contains filtered or unexported fields\n}\n```\nVaultProvider implements a HashiCorp Vault secret provider using the official vault/api client library. It supports KV v2 operations: Get, Set, Delete, and List.\n\n```go\nfunc NewVaultProvider(cfg VaultConfig) (*VaultProvider, error)\n```\nNewVaultProvider creates a new Vault provider using the official vault/api client. It validates the config, creates an api.Client, sets the token and namespace.\n\n```go\nfunc NewVaultProviderFromClient(client *vault.Client, cfg VaultConfig) *VaultProvider\n```\nNewVaultProviderFromClient creates a VaultProvider from an existing vault/api client. This is useful for testing or when you need custom client configuration.\n\n```go\nfunc NewVaultProviderHTTP(cfg VaultConfig) (*VaultProvider, error)\n```\nNewVaultProviderHTTP is a deprecated alias for NewVaultProvider. It exists for backward compatibility.\n\nDeprecated: Use NewVaultProvider instead.\n\n```go\nfunc (p *VaultProvider) CheckAccess(ctx context.Context) error\n```\nCheckAccess implements AccessChecker. It performs a lightweight check by attempting to list the mount's metadata root. The returned error never wraps the raw vault error, which may carry the address or secret path.\n\n```go\nfunc (p *VaultProvider) Client() *vault.Client\n```\nClient returns the underlying vault/api client for advanced use.\n\n```go\nfunc (p *VaultProvider) Config() VaultConfig\n```\nConfig returns the provider's Vault configuration.\n\n```go\nfunc (p *VaultProvider) Delete(ctx context.Context, key string) error\n```\nDelete removes a secret from Vault KV v2.\n\n```go\nfunc (p *VaultProvider) Get(ctx context.Context, key string) (string, error)\n```\nGet retrieves a secret value from Vault KV v2. The key can be in the format \"path\" or \"path#field\". If #field is specified, returns that specific field from the secret data. Otherwise, returns the entire data as JSON.\n\n```go\nfunc (p *VaultProvider) GetPrevious(ctx context.Context, key string) (string, error)\n```\nGetPrevious retrieves version N-1 of the secret at the given key from Vault KV v2. It reads the current version metadata to determine N, then fetches version N-1. Returns ErrNotFound if the secret has only one version or does not exist.\n\n```go\nfunc (p *VaultProvider) List(ctx context.Context) ([]string, error)\n```\nList returns all secret keys under the mount path. It uses the Vault logical LIST operation on the metadata path.\n\n```go\nfunc (p *VaultProvider) Name() string\n```\n\n```go\nfunc (p *VaultProvider) Rotate(ctx context.Context, key string) (string, error)\n```\nRotate generates a new random 32-byte hex-encoded secret and stores it at the given key, creating a new version in Vault KV v2. It returns the newly generated value.\n\n```go\nfunc (p *VaultProvider) SecretTarget() ProviderTarget\n```\nSecretTarget describes the Vault KV namespace used by this provider.\n\n```go\nfunc (p *VaultProvider) Set(ctx context.Context, key, value string) error\n```\nSet stores a secret value in Vault KV v2. The value is stored as {\"value\": val} in the secret data map.\n\n```go\nfunc (p *VaultProvider) StatAll(ctx context.Context) ([]SecretMeta, error)\n```\nStatAll implements MetadataProvider on a best-effort basis. If the Vault client is wired and the mount is reachable, it returns entries from the KV v2 metadata list. Otherwise it returns ErrUnsupported so callers can fall back.\n\n","path":"github.com/GoCodeAlone/workflow/secrets","name":"secrets","synopsis":"Package secrets provides secret storage backends (Provider), secret:// reference resolution (Resolver), and two complementary redaction utilities.","isRedistributable":true}
