fix(vault-kms): pass pubkey response via tmpfile not string literal

Embedding $response as Python triple-quoted string caused json.loads()
to fail with 'Invalid control character' when Vault's JSON contained
\n sequences in the PEM public key (bash \n → Python newline → invalid
JSON control char).

Fix: write response to mktemp, pass path as argv, read with open().
This commit is contained in:
thanhnv
2026-07-01 18:36:11 +09:00
parent 4fdeca2009
commit 4bcc66d9db
@@ -106,11 +106,14 @@ vault_kms_pubkey() {
echo "vault-kms: pubkey fetch failed (key=$key)" >&2; exit 1
}
python3 - "$output" <<PY
local tmp_resp
tmp_resp=$(mktemp)
printf '%s' "$response" > "$tmp_resp"
python3 - "$output" "$tmp_resp" <<'PY'
import sys, json
output = sys.argv[1]
response = """$response"""
d = json.loads(response)
with open(sys.argv[2]) as f:
d = json.loads(f.read())
keys = d["data"]["keys"]
# keys is a dict; pick the latest version
latest = max(keys.keys(), key=lambda k: int(k))
@@ -119,6 +122,7 @@ with open(output, "w") as f:
f.write(pub if pub.endswith("\n") else pub + "\n")
print(f"vault-kms: public key written to {output}", file=sys.stderr)
PY
rm -f "$tmp_resp"
}
# ── Verify a signature ────────────────────────────────────────────────────