From d4ee61aee70f46f4a81a08021bd15cf81e295d74 Mon Sep 17 00:00:00 2001 From: alessandrovitali Date: Sat, 10 Oct 2026 06:08:10 +0200 Subject: [PATCH] sops: harden binary install --- sops/action.yml | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/sops/action.yml b/sops/action.yml index a24918b..0697166 100644 --- a/sops/action.yml +++ b/sops/action.yml @@ -22,12 +22,15 @@ runs: asset="sops-${SOPS_VERSION}.${os}.${arch}" url="https://github.com/getsops/sops/releases/download/${SOPS_VERSION}" - curl -fsSL -o "$asset" "${url}/${asset}" -o checksums.txt "${url}/sops-${SOPS_VERSION}.checksums.txt" - grep " ${asset}$" checksums.txt | shasum -a 256 -c - + tmp=$(mktemp -d) + trap 'rm -rf "$tmp"' EXIT - chmod +x "$asset" - sudo mv "$asset" /usr/local/bin/sops - rm checksums.txt + curl -fsSL -o "$tmp/$asset" "$url/$asset" \ + -o "$tmp/checksums.txt" "$url/sops-${SOPS_VERSION}.checksums.txt" + (cd "$tmp" && grep " ${asset}$" checksums.txt | shasum -a 256 -c -) + + chmod +x "$tmp/$asset" + sudo mv "$tmp/$asset" /usr/local/bin/sops - name: decrypt .sops files shell: bash @@ -38,16 +41,20 @@ runs: echo "searching for SOPS files to decrypt..." - ## decrypt every *.sops.* file (except .sops.yaml) while IFS= read -r -d '' file; do dir=$(dirname "$file"); base=$(basename "$file") output_file="$dir/${base/.sops/}" echo "decrypting '$file' to '$output_file'" - tmp=$(mktemp) - sops --decrypt "$file" > "$tmp" - [ -s "$tmp" ] || { echo "decryption of '$file' produced empty output" >&2; exit 1; } + tmp=$(mktemp "$dir/.sops-decrypt.XXXXXX") + + if ! sops --decrypt "$file" > "$tmp" || [ ! -s "$tmp" ]; then + echo "decryption of '$file' failed or produced empty output" >&2 + rm -f "$tmp" + exit 1 + fi + chmod 600 "$tmp" mv "$tmp" "$output_file" done < <(find . -type f -name "*.sops.*" -not -name ".sops.yaml" -print0)