No description
Find a file
Heiko Schlittermann (HS12-RIPE) 4c7a7a7b5e fix: quoted values skip whitespace trimming (as-is semantics)
Previously, quoting only protected values from || splitting but
TrimSpace was still applied. Now quoted plain:/file: values preserve
their content verbatim, matching user expectation that quotes mean
"take literally".
2026-05-07 11:08:57 +02:00
cmd/secret fix: quoted values skip whitespace trimming (as-is semantics) 2026-05-07 11:08:57 +02:00
.gogogo.conf new: add .gogogo.conf for release 2025-06-12 08:50:03 +02:00
.golangci.yml fix: replace deprecated wsl linter with wsl_v5 2026-05-07 00:43:10 +02:00
CLAUDE.md new: implement netrc scheme for reading secrets from ~/.netrc 2026-05-07 00:51:26 +02:00
go.mod chore: update to Go 1.26.2 and latest dependencies 2026-05-07 00:44:37 +02:00
go.sum chore: update to Go 1.26.2 and latest dependencies 2026-05-07 00:44:37 +02:00
LICENSE.txt initial commit 2024-10-04 09:43:17 +02:00
netrc.go new: implement netrc scheme for reading secrets from ~/.netrc 2026-05-07 00:51:26 +02:00
netrc_test.go new: implement netrc scheme for reading secrets from ~/.netrc 2026-05-07 00:51:26 +02:00
README.md new: add fallback sources with || separator and value quoting 2026-05-07 10:28:04 +02:00
secret.go fix: quoted values skip whitespace trimming (as-is semantics) 2026-05-07 11:08:57 +02:00
secret_test.go new: add fallback sources with || separator and value quoting 2026-05-07 10:28:04 +02:00

secret

Go Reference

This package allows simple "encoding" of secret values in configuration files:

user: hans
pass: env:USERPASS

The secret value consists of a schema, and one or more values. Currently supported schemes are:

  • plain, pass: the value itself is the secret, with whitespace trimmed
  • raw: the value itself is the secret
  • env: the actual value is taken literally from the referenced environment variable. The variable is unset after first access.
  • file: the actual value is taken from the referenced file, with whitespace trimmed. The file must have 0600 or 0400 permissions.
  • rawfile: as file, but literally
  • netrc: the value is read from a ~/.netrc file (override via $NETRC_FILE). Format: netrc:[<login>@]<machine>[/<field>] where field is one of password (default), login, or account.

Autodetection of schema is attempted for absolute path names (as file) and for environment variables (prefix $).

Fallback

Multiple specs can be chained with || — candidates are tried left-to-right, the first success wins:

pass: env:SECRET_TOKEN||file:/run/secrets/token||plain:default

Whitespace around || is allowed:

pass: env:TOKEN || file:/run/secrets/token || plain:default

Quoting

Values may be quoted with single or double quotes (identical behavior) to protect literal || or surrounding whitespace:

pass: plain:"has || inside"||env:FALLBACK
pass: file:'/path with spaces/secret'
pass: raw:" preserve leading/trailing spaces "

Quotes wrap only the value, not the scheme prefix.