Skip to content

Commit 19a3caf

Browse files
committed
[ML] Add temporary workflow to test Vault OIDC for GitHub Actions
Made-with: Cursor
1 parent b0be7ea commit 19a3caf

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Test Vault OIDC
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
id-token: write
8+
contents: read
9+
10+
jobs:
11+
test-vault:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check Vault JWT auth endpoint
15+
run: |
16+
echo "=== Checking if Vault has a JWT auth method enabled ==="
17+
# This is a public, unauthenticated endpoint that returns config
18+
# if the JWT auth method exists. A 404 means it's not enabled.
19+
for path in jwt github-actions oidc; do
20+
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
21+
"https://vault-ci-prod.elastic.dev/v1/auth/${path}/.well-known/openid-configuration" 2>/dev/null)
22+
echo " auth/${path}: HTTP ${STATUS}"
23+
done
24+
25+
echo ""
26+
echo "=== Requesting GitHub OIDC token ==="
27+
if [ -n "$ACTIONS_ID_TOKEN_REQUEST_URL" ]; then
28+
OIDC_TOKEN=$(curl -sS -H "Authorization: bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" \
29+
"${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=https://vault-ci-prod.elastic.dev" | jq -r '.value')
30+
if [ -n "$OIDC_TOKEN" ] && [ "$OIDC_TOKEN" != "null" ]; then
31+
echo "Got OIDC token (first 20 chars): ${OIDC_TOKEN:0:20}..."
32+
33+
# Decode the JWT claims (middle segment) to see what info it carries.
34+
CLAIMS=$(echo "$OIDC_TOKEN" | cut -d. -f2 | base64 -d 2>/dev/null | jq . 2>/dev/null || echo "could not decode")
35+
echo ""
36+
echo "=== OIDC token claims ==="
37+
echo "$CLAIMS"
38+
39+
echo ""
40+
echo "=== Attempting Vault JWT login ==="
41+
for path in jwt github-actions oidc; do
42+
echo " Trying auth/${path}/login..."
43+
RESPONSE=$(curl -sS -X POST \
44+
"https://vault-ci-prod.elastic.dev/v1/auth/${path}/login" \
45+
-H "Content-Type: application/json" \
46+
-d "{\"jwt\": \"${OIDC_TOKEN}\", \"role\": \"\"}" 2>&1)
47+
echo " Response: $(echo "$RESPONSE" | jq -c '.errors // .auth.policies // .' 2>/dev/null || echo "$RESPONSE")"
48+
echo ""
49+
done
50+
else
51+
echo "Failed to get OIDC token"
52+
fi
53+
else
54+
echo "ACTIONS_ID_TOKEN_REQUEST_URL not set — id-token permission may be missing"
55+
fi

0 commit comments

Comments
 (0)