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/enrol.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/enrol.sh')
| -rwxr-xr-x | secrets/enrol.sh | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/secrets/enrol.sh b/secrets/enrol.sh new file mode 100755 index 0000000..2f1d61e --- /dev/null +++ b/secrets/enrol.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +set -euo pipefail + +if [[ "$#" -gt 0 && ("$1" == "-h" || "$1" == "--help") ]]; then + cat <<EOF +enrol: Make this machine's identity, and print its public key + +The private key is made here and never leaves: in the TPM (--tpm), in the +Secure Enclave (--se), or in a file readable only by you. Its public key goes +in identity.pub beside it, and is printed for cloud-setup's szecret/hosts. + +Usage: + enrol [--tpm|--se] + enrol -h|--help + +Run again, it prints the same key and makes no second one. The old key, if +it is here, stays beside it until it is deleted. +EOF + exit 0 +fi + +this_dir="$(cd "$(dirname "$0")" && pwd)" +szecret_no_store_ok=1 +source "${this_dir}/common.sh" + +kind=file +case "${1:-}" in + "") ;; + --tpm) kind=tpm ;; + --se) kind=se ;; + *) die "usage: szecret enrol [--tpm|--se]" ;; +esac + +if [[ -e "${identity}" ]]; then + if [[ ! -s "${identity_pub}" ]]; then + die "${identity} exists, but ${identity_pub} is missing or empty: write its public key there" + fi + >&2 echo "szecret: this machine is already enrolled (${identity})" + keys_in "${identity_pub}" + exit 0 +fi + +mkdir -p "$(dirname "${identity}")" +chmod 700 "$(dirname "${identity}")" +tmp="$(mktemp "${identity}.XXXXXX")" +trap 'rm -f "${tmp}"' EXIT +rm -f "${tmp}" + +case "${kind}" in + file) + (umask 077 && age-keygen -o "${tmp}" 2>/dev/null) + pub="$(age-keygen -y "${tmp}")" + ;; + tpm) + exists age-plugin-tpm || die "--tpm needs age-plugin-tpm, which is not installed; no key made" + [[ -e /dev/tpmrm0 ]] || die "--tpm: no TPM here (/dev/tpmrm0); no key made" + (umask 077 && age-plugin-tpm --generate -o "${tmp}") || die "age-plugin-tpm could not make a key; no key made" + pub="$(age-plugin-tpm -y "${tmp}")" + ;; + se) + exists age-plugin-se || die "--se needs age-plugin-se, which is not installed; no key made" + (umask 077 && age-plugin-se keygen --access-control=none -o "${tmp}") \ + || die "age-plugin-se could not make a key (is there a Secure Enclave, and is the screen unlocked?); no key made" + pub="$(age-plugin-se recipients -i "${tmp}")" + ;; +esac + +[[ "${pub}" =~ ^age1[0-9a-z]+$ ]] || die "the new key's public half doesn't look like one: ${pub:-nothing}; no key made" +chmod 600 "${tmp}" +echo "${pub}" > "${identity_pub}.tmp" +mv "${identity_pub}.tmp" "${identity_pub}" +mv "${tmp}" "${identity}" +>&2 echo "szecret: enrolled; add this machine's public key to cloud-setup's szecret/hosts:" +echo "${pub}" |
