diff options
| author | Igor Soarez <igor@soarez.org> | 2026-11-18 14:02:09 +0000 |
|---|---|---|
| committer | Igor Soarez <igor@soarez.org> | 2026-11-18 14:02:09 +0000 |
| commit | 8f818a64f2f0f3a833fc842d52a675358ec64c9c (patch) | |
| tree | eac13a48cada4595c9073d62060c1145189c6344 /secrets/get.sh | |
| parent | 6444d6a508cdfdcf52cc6c83bab1e29a7e2a2e10 (diff) | |
szecret: buckets beside the old store -- get/has/put/mv/rekey/list/check/enrol, admins from SZECRET_ADMINS_COMMAND; rotate retired (fleet hardening 12)
A bucket is a directory of secrets with one set of readers: its recipients file plus the admins, the full set recorded in .szecret by rekey. put refuses when the readers or admins drift from that set, or with no admins; a plain put of a new name goes to admin-only, one still in the old store is rewritten there. The old store keeps working throughout. link/claude.sh leaves out an MCP server whose secret is in a bucket this host doesn't read. Design: cloud-setup docs/proposal-secret-roles.md.
Diffstat (limited to 'secrets/get.sh')
| -rwxr-xr-x | secrets/get.sh | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/secrets/get.sh b/secrets/get.sh index d88b696..4b5b983 100755 --- a/secrets/get.sh +++ b/secrets/get.sh @@ -4,23 +4,17 @@ set -euo pipefail if [[ "$#" -gt 0 && ("$1" == "-h" || "$1" == "--help") ]]; then cat <<EOF -get: Retrieve and decrypt a secret from the store +get: Retrieve and decrypt a secret -Decrypts and outputs a secret value from the global secret store. +Decrypts a secret and writes it to stdout. Usage: - get <secret-name> + get <name> searches every bucket and the old store + get <bucket>/<name> reads that bucket only get -h|--help -Arguments: - secret-name Name of the secret to retrieve - -The command will: -1. Check if the secret exists in the store -2. Ensure the private key is available -3. Decrypt the secret using age and output to stdout - -Note: Exits with error if secret doesn't exist or decryption fails. +Fails, naming both, if <name> is in two places, and says so if this machine +isn't one of the bucket's readers. EOF exit 0 fi @@ -34,13 +28,19 @@ if [[ "$#" -lt 1 ]]; then fi name="$1" -file="$(file_for "${name}")" -if ! [[ -r "${file}" ]]; then - >&2 echo "ERROR: Secret '$name' not found" - exit 1 +file="$(find_secret "${name}")" || exit 1 + +if [[ -n "${store}" && "$(dirname "${file}")" == "${store}" ]]; then + # A machine that has moved to its own identity is not asked for the old key. + if [[ -r "${identity}" && ! -r "${private_key}" ]]; then + die "${name} is in the old store, and the old key is no longer on this machine" + fi + ensure_private_key +else + dir="$(dirname "${file}")" + if ! is_reader "${dir}"; then + die "$(basename "${file}" .age) is in bucket $(bucket_label "${dir}"); this machine isn't one of its readers" + fi fi -ensure_private_key - -age_decrypt "${private_key}" "${file}" - +decrypt "${file}" |
