From 8f818a64f2f0f3a833fc842d52a675358ec64c9c Mon Sep 17 00:00:00 2001 From: Igor Soarez Date: Wed, 18 Nov 2026 14:02:09 +0000 Subject: 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. --- secrets/put.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 14 deletions(-) (limited to 'secrets/put.sh') diff --git a/secrets/put.sh b/secrets/put.sh index 2675066..b060255 100755 --- a/secrets/put.sh +++ b/secrets/put.sh @@ -4,24 +4,20 @@ set -euo pipefail if [[ "$#" -gt 0 && ("$1" == "-h" || "$1" == "--help") ]]; then cat < - echo "secret-value" | put + echo "value" | put / + echo "value" | put the admin-only bucket, the narrowest set put -h|--help -Arguments: - secret-name Name to store the secret under - -The command will: -1. Read data from stdin -2. Encrypt the data using age with the public key -3. Store the encrypted data in the store as .age - -Note: Will overwrite existing secrets with the same name. +Overwrites where it already is. Refuses if is in another bucket +(it moves with mv, never copies), if the bucket's readers or the admins changed +since its last rekey, or if there are no admins. A still in the old +store is rewritten there until it moves. On a machine with no buckets, +goes to the old store, as before buckets. EOF exit 0 fi @@ -36,5 +32,44 @@ fi name="$1" ensure_age -age_encrypt "${public_key}" "$(file_for "${name}")" +# Before buckets: the old store, as it always was. +if [[ -z "${buckets}" ]]; then + [[ "${name}" != */* ]] || die "no buckets on this machine: ${name}" + age_encrypt "${public_key}" "$(file_for "${name}")" + exit 0 +fi + +if [[ "${name}" == */* ]]; then + bucket="${name%%/*}" + name="${name#*/}" + [[ "${bucket}" =~ ${re_bucket} ]] || die "not a bucket's name: ${bucket}" +else + bucket="" +fi +[[ "${name}" =~ ${re_secret} ]] || die "not a secret's name: ${name}" + +found="$(locate "${name}")" +if [[ -z "${bucket}" ]]; then + if [[ -n "${store}" && "${found}" == "${store}/${name}.age" ]]; then + >&2 echo "szecret: ${name} is still in the old store; rewriting it there" + age_encrypt "${public_key}" "${found}" + exit 0 + fi + if [[ -z "${found}" ]]; then + bucket="admin-only" + >&2 echo "szecret: storing ${name} in admin-only (put /${name} for another bucket)" + fi +fi +while read -r f; do + [[ -n "${f}" && "${f}" != "${buckets}/${bucket}/${name}.age" ]] || continue + if [[ -n "${store}" && "$(dirname "${f}")" == "${store}" ]]; then + die "${name} is in the old store; szecret mv ${name} ${bucket:-} moves it" + fi + die "${name} is in $(bucket_label "$(dirname "${f}")"); use $(where_is "${f}")" +done <<<"${found}" + +dir="${buckets}/${bucket}" +set="$(bucket_set "${dir}")" || exit 1 +age_version_ok +encrypt_to "${dir}/${name}.age" "${set}" -- cgit v1.2.3