Add fallback secret sources #2
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
heiko/secret#2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Allow specifying multiple secret sources in priority order, so that if the primary source is unavailable (e.g. an env variable is unset, a file does not exist), the next candidate is tried automatically.
Example use case: a secret can live either in an env variable (CI/containers) or a local file (developer workstation), without changing configuration between environments.
Proposed syntax options
Option A —
||separator (preferred)Inspired by shell "logical or". Split on
||before any other parsing; each token is a fully qualifiedscheme:valueentry and tried left-to-right. Stops at the first success.Pros: visually expressive ("or"), unambiguous (neither env names nor file paths contain
||), fits naturally into the existingscheme:valuegrammar without a new top-level scheme.Cons: two characters instead of one; YAML block scalars may need quoting (but they already need quoting for
:today).Option B — space-separated (original suggestion)
Whitespace as delimiter between fallback candidates.
Pros: terse, readable.
Cons: file paths can contain spaces, so this cannot safely support
file:sources with spaces; requires special-casing in the parser (split-before-cut).Option C — new
fallback:scheme with comma-separated listIntroduces an explicit top-level scheme that wraps multiple candidates.
Pros: opt-in, no impact on existing parsing paths.
Cons: nested colons make parsing tricky (how do you know where
env:SECRET_TOKENends?);,might conflict with comma-in-path edge cases; visually noisy.Option D —
?chaining operatorA
?after a source means "fall back to the next source on failure".Pros: compact, reads as "try this, maybe that".
Cons:
?is syntactically legal in file names on Linux; less obvious to new readers.Recommended approach
Option A (
||) is the cleanest fit:Get, before the existingstrings.Cut(s, ":"), splitson"||".Error semantics: return the last error if all candidates fail (mirrors how shells report the last pipeline exit code).
The
env:scheme currently unsets the variable after first access. For fallback chains, unsetting should only happen ifenv:is the winning candidate, not when it is tried and fails — otherwise a later retry in the same process would silently skip a valid variable.Open questions
plain:/raw:fallback at the end be allowed (to supply a hard-coded default)? That would make||a general "default value" mechanism, which seems useful.