diff options
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}" |
