sops: harden binary install

This commit is contained in:
alessandrovitali committed 2026-10-10 06:08:10 +02:00
1 parent 4878a62fb3
commit d4ee61aee7
1 file changed
+16 -9
+16 -9
View File
@@ -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)