ci: authenticate artifactapi upload with a vault token #5

Merged
benvin merged 1 commits from benvin/artifactapi-upload-token into main 2026-10-25 23:00:32 +11:00
+8 -1
View File
@@ -54,10 +54,17 @@ steps:
echo "$$PATH_IN_REPO already published (HTTP $$code); skipping upload"
exit 0
fi
set -o pipefail
VAULT="https://vault.service.consul:8200"
AUTH=$$(mktemp)
VT=$$(jq -n --rawfile jwt /var/run/secrets/kubernetes.io/serviceaccount/token '{role:"woodpecker_artifactapi_writer",jwt:$$jwt}' \
| curl -sf -d @- "$$VAULT/v1/auth/k8s/au/syd1/login" | jq -er .auth.client_token) || exit 1
printf 'X-Vault-Token: %s\n' "$$VT" | curl -sf -H @- "$$VAULT/v1/identity/oidc/token/artifactapi-writer" \
| jq -er '"Authorization: Bearer " + .data.token' > "$$AUTH" || exit 1
echo "Uploading $$ZIP to $$REPO/$$PATH_IN_REPO (existence probe returned $$code)"
curl -f -X PUT \
"$$HOST/api/v2/remotes/$$REPO/files/$$PATH_IN_REPO" \
-H "Content-Type: application/zip" \
-H "Content-Type: application/zip" -H @"$$AUTH" \
--data-binary @"$$ZIP"
echo
sha256sum "$$ZIP"