Skip to content
Hands-on IT IT Drills

Day 11: GitHub Actions

Goal: A GitHub workflow fetches secrets from OpenBao via OIDC, without a stored token, once with hashicorp/vault-action, once with bao and curl. · Duration: approx. 90 min · Prerequisite: Day 10

Briefing

  • With permissions: id-token: write, a job may request an OIDC JWT from GitHub. The issuer is https://token.actions.githubusercontent.com.
  • The sub claim depends on the context: environment beats branch, tag and pull request.
  • hashicorp/vault-action speaks the Vault HTTP API (/v1/auth/<path>/login) and therefore also works against OpenBao.
  • Without the action, two HTTP calls do the job: get the JWT from GitHub, redeem it at OpenBao.
  • A GitHub environment with reviewers is the approval. The role binds exactly this environment.
GitHub job ──(ACTIONS_ID_TOKEN_REQUEST_URL&audience=openbao)──▶ JWT
     │
     └── POST /v1/auth/jwt-github/login {role, jwt} ──▶ OpenBao ──▶ Token 5 min

Drill 1: Connecting the Real GitHub Issuer

OpenBao fetches the signing keys itself via OIDC discovery. For that, the OpenBao pod needs outbound HTTPS to GitHub.

mkdir -p ~/secrets-lab/tag11 && cd ~/secrets-lab/tag11
export BAO_ADDR=http://127.0.0.1:8200 BAO_TOKEN=root
bao auth enable -path=jwt-github jwt
bao write auth/jwt-github/config \
  oidc_discovery_url=https://token.actions.githubusercontent.com \
  bound_issuer=https://token.actions.githubusercontent.com
bao read -format=json auth/jwt-github/config \
  | jq '.data | {oidc_discovery_url, bound_issuer, status}'

Expected:

Success! Enabled jwt auth method at: jwt-github/
Success! Data written to: auth/jwt-github/config
{
  "oidc_discovery_url": "https://token.actions.githubusercontent.com",
  "bound_issuer": "https://token.actions.githubusercontent.com",
  "status": "valid"
}

The counterpart on the GitHub side is one role per repo and environment:

bao write auth/jwt-github/role/shop-prod - <<'EOF'
{
  "role_type": "jwt",
  "user_claim": "sub",
  "bound_audiences": ["openbao"],
  "bound_subject": "repo:acme/shop:environment:production",
  "bound_claims": {
    "repository_id": "100001",
    "workflow_ref": "acme/shop/.github/workflows/deploy.yml@refs/heads/main"
  },
  "claim_mappings": {"repository": "repository", "run_id": "run_id", "actor": "actor"},
  "token_policies": ["ci-deploy"],
  "token_ttl": "5m",
  "token_max_ttl": "10m"
}
EOF
bao write auth/jwt-github/login role=shop-prod \
  jwt="$(cd ../tag10 && ./mint-jwt.sh aud=openbao)" 2>&1 | tail -1

Expected:

Success! Data written to: auth/jwt-github/role/shop-prod
* error validating token: error verifying token signature: failed to verify id token
signature

That is correct: your lab JWT is not signed by GitHub. From here on you therefore replay the flow on jwt-ci/ with your lab issuer from Day 10.

Save your progress? Sign up for free

Drill 2: Claims and sub Formats

The most important claims in the GitHub token (per the GitHub docs):

Claim Example Bind for?
sub repo:acme/shop:environment:production Job context
repository / repository_id acme/shop / 100001 Repo; the ID survives renames
ref, ref_type refs/heads/main, branch Branch or tag
environment production only for jobs with environment:
workflow_ref acme/shop/.github/workflows/deploy.yml@refs/heads/main Workflow file
job_workflow_ref acme/ci/.github/workflows/deploy.yml@refs/heads/main Reusable workflow
repository_owner acme Organization
runner_environment github-hosted / self-hosted Runner type

The sub formats:

repo:acme/shop:environment:production   job with environment: (takes precedence)
repo:acme/shop:ref:refs/heads/main      branch, without environment
repo:acme/shop:ref:refs/tags/v1.4.0     tag, without environment
repo:acme/shop:pull_request             pull request, without environment

Warning: Repos created, renamed or transferred after July 15, 2026 (or by opt-in) get the immutable format repo:acme@<owner-id>/shop@<repo-id>:…. Check the real sub of your organization before you set bound_subject. With include_claim_keys you can additionally customize the format.

By default, the audience is the owner’s URL (https://github.com/acme). Set your own in the workflow, here openbao, so that a token meant for AWS does not work at OpenBao.

Save your progress? Sign up for free

Drill 3: Recreating Role shop-prod in the Lab

The same role as in Drill 1, just on the lab mount:

cp ../tag10/{mint-jwt.sh,ci-issuer.key} .
bao write auth/jwt-ci/role/shop-prod - <<'EOF'
{
  "role_type": "jwt",
  "user_claim": "sub",
  "bound_audiences": ["openbao"],
  "bound_subject": "repo:acme/shop:environment:production",
  "bound_claims": {
    "repository_id": "100001",
    "workflow_ref": "acme/shop/.github/workflows/deploy.yml@refs/heads/main"
  },
  "claim_mappings": {"repository": "repository", "run_id": "run_id", "actor": "actor"},
  "token_policies": ["ci-deploy"],
  "token_ttl": "5m",
  "token_max_ttl": "10m"
}
EOF
PROD="sub=repo:acme/shop:environment:production environment=production"
for args in "$PROD" \
  "sub=repo:acme/shop:pull_request event_name=pull_request" \
  "$PROD workflow_ref=acme/shop/.github/workflows/evil.yml@refs/heads/feat"; do
  BAO_TOKEN= bao write -field=token_policies auth/jwt-ci/login role=shop-prod \
    jwt="$(./mint-jwt.sh $args)" 2>&1 | tail -1; echo
done

Expected:

Success! Data written to: auth/jwt-ci/role/shop-prod
[ci-deploy default]
* error validating token: invalid subject (sub) claim
* error validating claims: claim "workflow_ref" does not match any associated bound
claim values

Why workflow_ref? Without that binding, anyone allowed to push a branch in acme/shop could write their own workflow with environment: production. Only the environment rule “only main” plus workflow_ref closes that gap. If you call central reusable workflows, bind job_workflow_ref instead of workflow_ref.

Save your progress? Sign up for free

Drill 4: Variant A – hashicorp/vault-action

The workflow as it would live in acme/shop (.github/workflows/deploy.yml). The action is currently at major version v4 (Node 24 runtime).

mkdir -p .github/workflows
cat > .github/workflows/deploy.yml <<'EOF'
name: deploy
on:
  push:
    branches: [main]
permissions:
  contents: read
  id-token: write   # no OIDC token without this
jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production   # sub = repo:acme/shop:environment:production
    steps:
      - uses: actions/checkout@v7
      - name: Secrets aus OpenBao
        id: bao
        uses: hashicorp/vault-action@v4
        with:
          url: https://openbao.example.com
          method: jwt
          path: jwt-github
          role: shop-prod
          jwtGithubAudience: openbao
          secrets: |
            secret/data/ci/deploy registry_password | REGISTRY_PASSWORD ;
            secret/data/ci/deploy kubeconfig_token | KUBE_TOKEN
      - name: Registry-Login
        run: |
          echo "$REGISTRY_PASSWORD" | docker login registry.example.com \
            -u ci --password-stdin
EOF

Important: KV v2 needs the full API path with data/. The action automatically masks every value it reads and exports it as an environment variable (exportEnv: true is the default). Run on GitHub, the log looks like this (abridged, may differ depending on version):

Run hashicorp/vault-action@v4
Get Vault Secrets
  ✔ secret/data/ci/deploy => outputs.REGISTRY_PASSWORD | env.REGISTRY_PASSWORD
  ✔ secret/data/ci/deploy => outputs.KUBE_TOKEN | env.KUBE_TOKEN
Run echo "$REGISTRY_PASSWORD" | docker login registry.example.com ...
Login Succeeded

Save your progress? Sign up for free

Drill 5: Testing the Action Locally Against OpenBao

The action is a single Node script. It reads its inputs from INPUT_* and the OIDC token from ACTIONS_ID_TOKEN_REQUEST_URL. A small mock plays this GitHub endpoint and signs with your lab issuer (requires Node.js 24 or newer).

cat > fake-oidc.py <<'EOF'
#!/usr/bin/env python3
"""Lab mock of the GitHub OIDC token endpoint (ACTIONS_ID_TOKEN_REQUEST_URL).

Responds like GitHub with {"value": "<JWT>"}; signing is done by mint-jwt.sh (Day 10).
Additional claims come from the environment variable CLAIMS (e.g. "environment=prod").
Lab only!
"""
import json, os, subprocess, sys
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import parse_qs, urlparse

BEARER = os.environ.get("REQUEST_TOKEN", "lab-request-token")
MINT = os.environ.get("MINT", "./mint-jwt.sh")


class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        if self.headers.get("Authorization", "").lower() != f"bearer {BEARER}":
            self.send_error(401, "bad request token")
            return
        query = parse_qs(urlparse(self.path).query)
        aud = query.get("audience", ["https://github.com/acme"])[0]
        args = [MINT, f"aud={aud}"] + os.environ.get("CLAIMS", "").split()
        jwt = subprocess.run(args, check=True, capture_output=True, text=True).stdout
        body = json.dumps({"value": jwt.strip()}).encode()
        self.send_response(200)
        self.send_header("Content-Type", "application/json")
        self.end_headers()
        self.wfile.write(body)
        print(f"Token ausgestellt, aud={aud}", file=sys.stderr)

    def log_message(self, *args):
        pass


HTTPServer(("127.0.0.1", int(os.environ.get("PORT", "8299"))), Handler).serve_forever()
EOF
CLAIMS="sub=repo:acme/shop:environment:production environment=production" \
  python3 fake-oidc.py 2>fake-oidc.log &
export ACTIONS_ID_TOKEN_REQUEST_URL="http://127.0.0.1:8299/token?api-version=2.0"
export ACTIONS_ID_TOKEN_REQUEST_TOKEN=lab-request-token
curl -sSfLo vault-action.js \
  https://raw.githubusercontent.com/hashicorp/vault-action/v4.0.0/dist/index.js

Now run the action with the same inputs as in the workflow, just against your lab:

: > gh-output; : > gh-env
env -u BAO_TOKEN GITHUB_OUTPUT=$PWD/gh-output GITHUB_ENV=$PWD/gh-env \
  INPUT_URL=$BAO_ADDR INPUT_METHOD=jwt INPUT_PATH=jwt-ci INPUT_ROLE=shop-prod \
  INPUT_JWTGITHUBAUDIENCE=openbao INPUT_EXPORTENV=true \
  INPUT_SECRETS='secret/data/ci/deploy registry_password | REGISTRY_PASSWORD' \
  node vault-action.js | cut -c1-80
echo "---"; grep -A1 '^REGISTRY_PASSWORD' gh-env

Expected:

::group::Get Vault Secrets
::debug::ID token url is http://127.0.0.1:8299/token?api-version=2.0&audience=o
::add-mask::eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImxhYi1jaS0xIn0.eyJpc3Mi
::debug::Retrieving Vault Token from v1/auth/jwt-ci/login endpoint
::debug::✔ Vault Token successfully retrieved
::group::Token Info
::debug::Operating under policies: ["ci-deploy","default"]
::debug::Token Metadata: {"actor":"zachmann","repository":"acme/shop","role":"sh
::endgroup::
::add-mask::s.1KuV01SfzTf0JvDvra05AIYD
::add-mask::lab-reg-pw
::debug::✔ secret/data/ci/deploy => outputs.REGISTRY_PASSWORD | env.REGISTRY_PAS
::endgroup::
---
REGISTRY_PASSWORD<<ghadelimiter_179d4f2a-2955-46d8-b6a8-71ceec142682
lab-reg-pw

You see the workflow commands in raw format: the action masks the JWT, the OpenBao token and every secret value via ::add-mask:: before using it. The OpenBao token is not revoked at the end; it expires after token_ttl. Hence the 5 minutes.

Save your progress? Sign up for free

Drill 6: Variant B – Fetching the Token Yourself with curl and bao

No action, full control. This is the run step in the workflow; here it runs against your mock. Otherwise GitHub sets the variables itself.

cat > get-secrets.sh <<'EOF'
#!/usr/bin/env bash
# GitHub Actions step: get the OIDC JWT, redeem it at OpenBao, read the secret
set -euo pipefail
JWT=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
  "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=openbao" | jq -r .value)
echo "::add-mask::$JWT"
BAO_TOKEN=$(bao write -field=token "auth/$BAO_AUTH_PATH/login" \
  role=shop-prod jwt="$JWT")
echo "::add-mask::$BAO_TOKEN"
export BAO_TOKEN
PW=$(bao kv get -field=registry_password secret/ci/deploy)
echo "::add-mask::$PW"
echo "REGISTRY_PASSWORD=$PW" >> "$GITHUB_ENV"
bao token revoke -self >/dev/null
echo "✔ Secret übergeben, OpenBao-Token widerrufen"
EOF
chmod +x get-secrets.sh
: > gh-env
env -u BAO_TOKEN GITHUB_ENV=$PWD/gh-env BAO_AUTH_PATH=jwt-ci ./get-secrets.sh \
  | cut -c1-60
cat gh-env

Expected:

::add-mask::eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImxhYi1j
::add-mask::s.7MIGoeu4CNYFfCRKtYn50XKW
::add-mask::lab-reg-pw
✔ Secret übergeben, OpenBao-Token widerrufen
REGISTRY_PASSWORD=lab-reg-pw

In the workflow, the installation of bao with a checksum comes before it, and the usage after it (not executed):

cat > .github/workflows/deploy-cli.yml <<'EOF'
name: deploy-cli
on:
  push:
    branches: [main]
permissions:
  contents: read
  id-token: write
jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production
    env:
      BAO_ADDR: https://openbao.example.com
      BAO_AUTH_PATH: jwt-github
      BAO_VERSION: 2.7.1
    steps:
      - uses: actions/checkout@v7
      - name: bao installieren
        run: |
          base=https://github.com/openbao/openbao/releases/download/v$BAO_VERSION
          curl -sSfLO "$base/openbao_${BAO_VERSION}_linux_amd64.tar.gz"
          curl -sSfLO "$base/checksums.txt"
          sha256sum --ignore-missing -c checksums.txt
          tar xzf "openbao_${BAO_VERSION}_linux_amd64.tar.gz" bao
          sudo install bao /usr/local/bin/bao
      - name: Secrets holen
        run: ./ci/get-secrets.sh
      - name: Registry-Login
        run: |
          echo "$REGISTRY_PASSWORD" | docker login registry.example.com \
            -u ci --password-stdin
EOF

Security: ::add-mask:: only takes effect from the line where it appears, and only for exactly this string. Never print values beforehand, no set -x, and mask derived forms (Base64, URL-encoded) separately.

Save your progress? Sign up for free

Drill 7: Environments as Protection

The environment production in GitHub gets “Required reviewers” and “Deployment branches: main”. Only after approval does the job start, and only then is there a token with environment:production in the sub. Verify that a job on main without an environment cannot get at production secrets:

BAO_TOKEN= bao write auth/jwt-ci/login role=shop-prod \
  jwt="$(./mint-jwt.sh)" 2>&1 | tail -1
pkill -f fake-oidc.py

Expected:

* error validating token: invalid subject (sub) claim

The sub is then repo:acme/shop:ref:refs/heads/main. This makes the approval in the GitHub environment the only door to the role shop-prod.

Save your progress? Sign up for free

Checkpoint

cat > check.sh <<'EOF'
#!/usr/bin/env bash
cd ~/secrets-lab/tag11
export BAO_ADDR="${BAO_ADDR:-http://127.0.0.1:8200}"
login() { BAO_TOKEN= bao write -field=token auth/jwt-ci/login role=shop-prod \
  jwt="$(./mint-jwt.sh "$@")" >/dev/null 2>&1; }
[ "$(BAO_TOKEN=root bao read -field=status auth/jwt-github/config)" = valid ] \
  && echo "✔ jwt-github per Discovery" || echo "✘ jwt-github-Config"
login sub=repo:acme/shop:environment:production && echo "✔ Environment-Login" \
  || echo "✘ Environment-Login"
login sub=repo:acme/shop:pull_request && echo "✘ PR kommt rein" \
  || echo "✔ PR abgewiesen"
login sub=repo:acme/shop:environment:production repository_id=999 \
  && echo "✘ fremde repository_id" || echo "✔ fremde repository_id abgewiesen"
grep -q 'id-token: write' .github/workflows/deploy.yml \
  && echo "✔ Workflow fordert id-token an" || echo "✘ permissions fehlt"
EOF
bash check.sh

Expected:

✔ jwt-github per Discovery
✔ Environment-Login
✔ PR abgewiesen
✔ fremde repository_id abgewiesen
✔ Workflow fordert id-token an

Challenge

Pull requests should run integration tests against a test database, but only from the repo itself, never from forks. Create a role shop-pr with the policy ci-test (read on secret/data/ci/test) and test it with your lab issuer.

Hint: Bind event_name=pull_request. pull_request_target runs with the permissions of the target repo and must never get at secrets.

Solution

export BAO_TOKEN=root
bao kv put secret/ci/test db_password=lab-test-db >/dev/null
bao policy write ci-test - <<'HCL'
path "secret/data/ci/test" {
  capabilities = ["read"]
}
HCL
bao write auth/jwt-ci/role/shop-pr - <<'EOF'
{
  "role_type": "jwt", "user_claim": "sub", "bound_audiences": ["openbao"],
  "bound_subject": "repo:acme/shop:pull_request",
  "bound_claims": {"repository_id": "100001", "event_name": "pull_request"},
  "token_policies": ["ci-test"], "token_ttl": "10m"
}
EOF
PR="sub=repo:acme/shop:pull_request event_name=pull_request"
T=$(BAO_TOKEN= bao write -field=token auth/jwt-ci/login role=shop-pr \
  jwt="$(./mint-jwt.sh $PR)")
BAO_TOKEN=$T bao kv get -field=db_password secret/ci/test; echo
BAO_TOKEN=$T bao kv get secret/ci/deploy 2>&1 | grep -m1 denied
BAO_TOKEN= bao write auth/jwt-ci/login role=shop-pr \
  jwt="$(./mint-jwt.sh $PR event_name=pull_request_target)" 2>&1 | tail -1

Expected:

lab-test-db
    * permission denied
* error validating claims: claim "event_name" does not match any associated bound
claim values

Fork PRs run in the context of the target repo, so repository does not help. The protection comes from GitHub: fork PRs do not get id-token: write unless you explicitly allow it in the repo settings.

Save your progress? Sign up for free

Enterprise Note

  • GitHub-hosted runners come from the internet: OpenBao then needs a publicly reachable endpoint (WAF, only /v1/auth/jwt-github/login and the required paths). Otherwise use self-hosted runners in the internal network and bind runner_environment=self-hosted.
  • Pin actions by commit SHA (hashicorp/vault-action@<sha>), not by tag. The action sees all of the job’s secrets.
  • One contract per repo: repository_id, environment, workflow_ref or job_workflow_ref. Never only repository_owner for write or prod permissions.
  • Set a fixed sub format org-wide via include_claim_keys and manage the matching roles as code (OpenTofu, Day 13).
  • Revoke the OpenBao token in the last step (bao token revoke -self), even on failures, via if: always().