summaryrefslogtreecommitdiff
path: root/secrets/mv.sh
diff options
context:
space:
mode:
authorIgor Soarez <igor@soarez.org>2026-11-18 14:02:09 +0000
committerIgor Soarez <igor@soarez.org>2026-11-18 14:02:09 +0000
commit8f818a64f2f0f3a833fc842d52a675358ec64c9c (patch)
treeeac13a48cada4595c9073d62060c1145189c6344 /secrets/mv.sh
parent6444d6a508cdfdcf52cc6c83bab1e29a7e2a2e10 (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/mv.sh')
-rwxr-xr-xsecrets/mv.sh51
1 files changed, 51 insertions, 0 deletions
diff --git a/secrets/mv.sh b/secrets/mv.sh
new file mode 100755
index 0000000..d249ac1
--- /dev/null
+++ b/secrets/mv.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+set -euo pipefail
+
+if [[ "$#" -gt 0 && ("$1" == "-h" || "$1" == "--help") ]]; then
+ cat <<EOF
+mv: Move a secret to another bucket
+
+Decrypts it, encrypts it to the bucket's readers and the admins, and deletes
+the old file. A secret is never copied: when a host outside its bucket needs
+it, it moves to a bucket that has every reader who needs it.
+
+Usage:
+ mv <name> <bucket>
+ mv <bucket>/<name> <bucket>
+ mv -h|--help
+
+Needs an identity that can read it now. The plaintext goes through a pipe,
+never a file.
+EOF
+ exit 0
+fi
+
+this_dir="$(cd "$(dirname "$0")" && pwd)"
+source "${this_dir}/common.sh"
+
+[[ "$#" -eq 2 ]] || die "usage: szecret mv <name> <bucket>"
+[[ -n "${buckets}" ]] || die "no buckets on this machine"
+target="$2"
+[[ "${target}" =~ ${re_bucket} ]] || die "not a bucket's name: ${target}"
+
+from="$(find_secret "$1")" || exit 1
+name="$(basename "${from}" .age)"
+dir="${buckets}/${target}"
+to="${dir}/${name}.age"
+[[ "${from}" != "${to}" ]] || die "${name} is already in ${target}"
+# A name in two places is a mistake to sort out by hand, not to overwrite.
+[[ ! -e "${to}" ]] || die "${target}/${name} already exists; not overwriting it with $(where_is "${from}")"
+if [[ -n "${store}" && "$(dirname "${from}")" == "${store}" ]]; then
+ ensure_private_key
+fi
+
+set="$(bucket_set "${dir}")" || exit 1
+age_version_ok
+load_identities
+if ! age --decrypt "${ids[@]}" "${from}" | encrypt_to "${to}" "${set}"; then
+ rm -f "${to}"
+ die "could not move ${name}; $(where_is "${from}") is as it was"
+fi
+rm "${from}"
+>&2 echo "szecret: moved $(where_is "${to}"), from $(where_is "${from}")"