Day 10: Pipeline Identity
Goal: Your pipeline logs in with a short-lived, signed JWT instead of a static token, and legacy CI gets AppRole with response wrapping. · Duration: approx. 90 min · Prerequisite: Day 2
Briefing
- A static CI token is a bearer secret without context: whoever has it is “the pipeline”, no matter which repo, branch or fork they come from.
- Modern CI systems issue a signed JWT per job (OIDC). OpenBao checks
the signature, issuer, audience, expiry and claims such as
repositoryorref. - The role decides which claim value gets which policy, and for how long.
- Today you play the CI issuer yourself: an RSA key plus a script that signs GitHub-style tokens. Days 11 and 12 only swap out the issuer.
- Anyone who cannot do OIDC (an old Jenkins) uses AppRole. The secret ID is handed over only wrapped and usable once.
CI job ── JWT (iss, aud, sub, repository, ref …) ──▶ auth/jwt-ci/login role=deploy-main
│ signature? aud? exp? claims?
▼
Token (5 min, policy ci-deploy) ──▶ secret/ci/deploy
Drill 1: The Problem with Static Tokens
First create the lab data for Part C. This is an admin step, hence the root token.
mkdir -p ~/secrets-lab/tag10 && cd ~/secrets-lab/tag10
export BAO_ADDR=http://127.0.0.1:8200 BAO_TOKEN=root
bao kv put secret/ci/deploy registry_password=lab-reg-pw \
kubeconfig_token=lab-kube-token >/dev/null
bao policy write ci-deploy - <<'HCL'
path "secret/data/ci/deploy" {
capabilities = ["read"]
}
HCLExpected:
Success! Uploaded policy: ci-deploy
This is what CI used to look like: a long-lived token as a “Jenkins credential”.
OLD=$(bao token create -policy=ci-deploy -period=768h \
-display-name=jenkins-legacy -field=token)
bao token lookup "$OLD" | grep -E 'display_name|^meta|period|policies|^ttl'
bao token revoke "$OLD"Expected:
display_name token-jenkins-legacy
meta <nil>
period 768h
policies [ci-deploy default]
ttl 768h
Success! Revoked token (if it existed)
Why is that bad? Valid for 32 days, renewable, no metadata. In the audit log you never see which repo or branch used it.
Save your progress? Sign up for free
Drill 2: Building a Lab CI Issuer
A key pair plays the signing key of GitHub or GitLab. The script
builds the header and payload, signs with RS256 and needs only
openssl and python3.
openssl genrsa -out ci-issuer.key 2048
openssl rsa -in ci-issuer.key -pubout -out ci-issuer.pub
cat > mint-jwt.sh <<'EOF'
#!/usr/bin/env bash
# Lab CI issuer: signs a JWT (RS256) with GitHub-style claims. Lab only!
# Usage: ./mint-jwt.sh [claim=value ...] (an empty value deletes the claim)
# Special case ttl=<sec>: lifetime from now, negative = already expired
# BASE=<file.json> replaces the GitHub-style default claims (Day 12)
set -euo pipefail
KEY="${KEY:-ci-issuer.key}"
b64url() { openssl base64 -A | tr '+/' '-_' | tr -d '='; }
payload=$(python3 - "$@" <<'PY'
import json, os, sys, time
now = int(time.time())
c = json.load(open(os.environ["BASE"])) if os.environ.get("BASE") else {
"iss": "https://ci.lab.example", "aud": "openbao",
"sub": "repo:acme/shop:ref:refs/heads/main",
"repository": "acme/shop", "repository_owner": "acme", "repository_id": "100001",
"ref": "refs/heads/main", "ref_type": "branch", "actor": "zachmann",
"workflow": "deploy", "event_name": "push", "run_id": "4711",
"workflow_ref": "acme/shop/.github/workflows/deploy.yml@refs/heads/main",
"job_workflow_ref": "acme/shop/.github/workflows/deploy.yml@refs/heads/main",
}
ttl = 300
for arg in sys.argv[1:]:
k, _, v = arg.partition("=")
if k == "ttl":
ttl = int(v)
elif v == "":
c.pop(k, None)
else:
c[k] = v
iat = min(now, now + ttl - 300)
c.update(iat=iat, nbf=iat, exp=now + ttl)
print(json.dumps(c, separators=(",", ":")))
PY
)
header=$(printf '{"alg":"RS256","typ":"JWT","kid":"lab-ci-1"}' | b64url)
body=$(printf '%s' "$payload" | b64url)
sig=$(printf '%s.%s' "$header" "$body" \
| openssl dgst -sha256 -sign "$KEY" -binary | b64url)
printf '%s.%s.%s\n' "$header" "$body" "$sig"
EOF
chmod +x mint-jwt.shTo read the claims, a small shell function (Base64url → JSON):
claims() { jq -R 'split(".")[1] | gsub("-";"+") | gsub("_";"/")
| @base64d | fromjson'; }
./mint-jwt.sh | claimsExpected (abridged):
{
"iss": "https://ci.lab.example",
"aud": "openbao",
"sub": "repo:acme/shop:ref:refs/heads/main",
"repository": "acme/shop",
"repository_owner": "acme",
"repository_id": "100001",
"ref": "refs/heads/main",
...
"iat": 1791785367,
"nbf": 1791785367,
"exp": 1791785667
}
Security: In the lab,
ci-issuer.keyis the “CI provider”. Anyone with this key can issue themselves any pipeline identity. In real life it exists only at the CI system.
Save your progress? Sign up for free
Drill 3: The JWT Auth Mount
jwt-ci/
OpenBao gets only the public key and the expected issuer.
bao auth enable -path=jwt-ci jwt
bao write auth/jwt-ci/config [email protected] \
bound_issuer=https://ci.lab.example
bao read -format=json auth/jwt-ci/config \
| jq '.data | {bound_issuer, jwks_url, oidc_discovery_url, status}'Expected:
Success! Enabled jwt auth method at: jwt-ci/
Success! Data written to: auth/jwt-ci/config
{
"bound_issuer": "https://ci.lab.example",
"jwks_url": "",
"oidc_discovery_url": "",
"status": "valid"
}
Why jwt_validation_pubkeys? Your lab issuer has no
discovery endpoint. Real CI providers are configured via
oidc_discovery_url or jwks_url (Day 11,
12).
Save your progress? Sign up for free
Drill 4: Role deploy-main and
the First Login
The role binds the audience and claims. Only pushes to
main from acme/shop get in.
bao write auth/jwt-ci/role/deploy-main - <<'EOF'
{
"role_type": "jwt",
"user_claim": "sub",
"bound_audiences": ["openbao"],
"bound_claims_type": "string",
"bound_claims": {
"repository": "acme/shop",
"ref": "refs/heads/main"
},
"token_policies": ["ci-deploy"],
"token_ttl": "5m",
"token_max_ttl": "10m"
}
EOF
unset BAO_TOKEN
bao write auth/jwt-ci/login role=deploy-main jwt="$(./mint-jwt.sh)"Expected:
Success! Data written to: auth/jwt-ci/role/deploy-main
Key Value
--- -----
token s.7886d9X54gUgGKkHLprJx9Ym
token_accessor s44GnLsjBqAEgcAOhLGQvwBS
token_duration 5m
token_renewable true
token_policies ["ci-deploy" "default"]
identity_policies []
policies ["ci-deploy" "default"]
token_meta_role deploy-main
This is how a pipeline step uses the token:
export BAO_TOKEN=$(bao write -field=token auth/jwt-ci/login role=deploy-main \
jwt="$(./mint-jwt.sh)")
bao kv get -field=registry_password secret/ci/deploy; echo
bao kv get secret/shop/api 2>&1 | grep -m1 deniedExpected:
lab-reg-pw
* permission denied
Why user_claim=sub? The value becomes the name of the
entity alias. The audit log then shows
repo:acme/shop:ref:refs/heads/main instead of “some CI
token”.
Save your progress? Sign up for free
Drill 5: Negative Tests
Every binding has to turn red once. The script changes exactly one claim per run.
unset BAO_TOKEN
for args in ref=refs/heads/feature-x repository=acme/other aud=github \
iss=https://evil.example ttl=-60 ref=; do
echo "== $args"
bao write auth/jwt-ci/login role=deploy-main \
jwt="$(./mint-jwt.sh $args)" 2>&1 | tail -1
doneExpected:
== ref=refs/heads/feature-x
* error validating claims: claim "ref" does not match any associated bound claim values
== repository=acme/other
* error validating claims: claim "repository" does not match any associated bound
claim values
== aud=github
* error validating token: invalid audience (aud) claim: audience claim does not match
any expected audience
== iss=https://evil.example
* error validating token: invalid issuer (iss) claim
== ttl=-60
* error validating token: invalid expiration time (exp) claim: token is expired
== ref=
* error validating claims: claim "ref" is missing
And a token signed with a foreign key, i.e. a forged issuer:
openssl genrsa -out evil.key 2048 2>/dev/null
bao write auth/jwt-ci/login role=deploy-main \
jwt="$(KEY=evil.key ./mint-jwt.sh)" 2>&1 | tail -1Expected:
* error validating token: error verifying token signature: no known key successfully
validated the token signature
Warning: A JWT can be used any number of times until
exp. OpenBao tolerates about 60 s of clock skew (clock_skew_leeway). Short token lifetimes at the CI provider are therefore part of the security.
Save your progress? Sign up for free
Drill 6: Glob Binding and
claim_mappings
Release branches and version tags should be allowed to deploy via one role. Claims also end up as metadata on the token and in the audit log.
export BAO_TOKEN=root
bao write auth/jwt-ci/role/deploy-release - <<'EOF'
{
"role_type": "jwt",
"user_claim": "sub",
"bound_audiences": ["openbao"],
"bound_claims_type": "glob",
"bound_claims": {
"repository": "acme/shop",
"ref": ["refs/heads/release-*", "refs/tags/v*"]
},
"claim_mappings": {
"repository": "repository",
"ref": "ref",
"actor": "actor",
"run_id": "run_id"
},
"token_policies": ["ci-deploy"],
"token_ttl": "5m",
"token_max_ttl": "10m"
}
EOF
for r in refs/heads/release-1.4 refs/tags/v1.4.0 refs/heads/main \
refs/heads/my-release-x; do
printf '%-26s ' "$r"
BAO_TOKEN= bao write -field=token_policies auth/jwt-ci/login role=deploy-release \
jwt="$(./mint-jwt.sh ref=$r sub=repo:acme/shop:ref:$r)" 2>&1 | tail -1
echo
doneExpected:
Success! Data written to: auth/jwt-ci/role/deploy-release
refs/heads/release-1.4 [ci-deploy default]
refs/tags/v1.4.0 [ci-deploy default]
refs/heads/main * error validating claims: claim "ref" does not match any
associated bound claim values
refs/heads/my-release-x * error validating claims: claim "ref" does not match any
associated bound claim values
Several values in a list are an OR, several claims are an AND. The
glob * also matches across /, so always work
with a fixed prefix.
T=$(BAO_TOKEN= bao write -field=token auth/jwt-ci/login role=deploy-release \
jwt="$(./mint-jwt.sh ref=refs/tags/v1.4.0 sub=repo:acme/shop:ref:refs/tags/v1.4.0)")
bao token lookup -format=json "$T" | jq '.data | {display_name, meta, ttl}'Expected:
{
"display_name": "jwt-ci-repo:acme/shop:ref:refs/tags/v1.4.0",
"meta": {
"actor": "zachmann",
"ref": "refs/tags/v1.4.0",
"repository": "acme/shop",
"role": "deploy-release",
"run_id": "4711"
},
"ttl": 300
}
Save your progress? Sign up for free
Drill 7: AppRole for Legacy CI
An old Jenkins cannot do OIDC. It gets an AppRole: the role ID is the “username”, the secret ID the short-lived, single-use “password”.
bao auth enable approle
bao write auth/approle/role/jenkins-deploy \
token_policies=ci-deploy token_ttl=10m token_max_ttl=30m \
secret_id_ttl=15m secret_id_num_uses=1 \
secret_id_bound_cidrs=127.0.0.1/32 token_bound_cidrs=127.0.0.1/32
bao read -field=role_id auth/approle/role/jenkins-deploy/role-id; echoExpected:
Success! Enabled approle auth method at: approle/
Success! Data written to: auth/approle/role/jenkins-deploy
67d3f71b-a0ff-da1b-cb2b-ce241424caa6
Secret IDs are generated by a “trusted orchestrator”, for example a seed job. Its policy allows only this one endpoint and enforces wrapping:
bao policy write approle-issuer - <<'HCL'
path "auth/approle/role/jenkins-deploy/secret-id" {
capabilities = ["update"]
min_wrapping_ttl = "1s"
max_wrapping_ttl = "300s"
}
HCL
ISSUER=$(bao token create -policy=approle-issuer -ttl=1h -field=token)
BAO_TOKEN=$ISSUER bao write -f auth/approle/role/jenkins-deploy/secret-id 2>&1 \
| grep -m1 deniedExpected:
Success! Uploaded policy: approle-issuer
* permission denied
Why? Without -wrap-ttl the secret ID would come back in
plain text. The policy does not even allow that.
Save your progress? Sign up for free
Drill 8: Handing Over the Secret ID via Response Wrapping
The orchestrator only passes on a wrapping token. The Jenkins agent unwraps it once and logs in.
WRAP=$(BAO_TOKEN=$ISSUER bao write -wrap-ttl=120s -field=wrapping_token \
-f auth/approle/role/jenkins-deploy/secret-id)
bao write -format=json sys/wrapping/lookup token="$WRAP" | jq -r .data.creation_path
ROLE_ID=$(bao read -field=role_id auth/approle/role/jenkins-deploy/role-id)
SECRET_ID=$(BAO_TOKEN=$WRAP bao unwrap -field=secret_id)
BAO_TOKEN= bao write auth/approle/login role_id="$ROLE_ID" secret_id="$SECRET_ID"Expected:
auth/approle/role/jenkins-deploy/secret-id
Key Value
--- -----
token s.9BmC0AWMqAbrO9QAb5NnC4Yd
token_accessor av6dQpi8euMs2trPCygMI6SR
token_duration 10m
token_renewable true
token_policies ["ci-deploy" "default"]
identity_policies []
policies ["ci-deploy" "default"]
token_meta_role_name jenkins-deploy
The recipient checks creation_path before unwrapping:
does the package really come from the expected endpoint? Now all three
locks:
echo "== Wrapping-Token zweites Mal"
BAO_TOKEN=$WRAP bao unwrap 2>&1 | tail -1
echo "== Secret-ID zweites Mal"
BAO_TOKEN= bao write auth/approle/login role_id="$ROLE_ID" \
secret_id="$SECRET_ID" 2>&1 | tail -1
echo "== falsches Quellnetz"
bao write auth/approle/role/jenkins-deploy secret_id_bound_cidrs=10.20.0.0/16 >/dev/null
WRAP=$(BAO_TOKEN=$ISSUER bao write -wrap-ttl=120s -field=wrapping_token \
-f auth/approle/role/jenkins-deploy/secret-id)
SECRET_ID=$(BAO_TOKEN=$WRAP bao unwrap -field=secret_id)
BAO_TOKEN= bao write auth/approle/login role_id="$ROLE_ID" \
secret_id="$SECRET_ID" 2>&1 | tail -1
bao write auth/approle/role/jenkins-deploy secret_id_bound_cidrs=127.0.0.1/32 >/dev/nullExpected:
== Wrapping-Token zweites Mal
* wrapping token is not valid or does not exist
== Secret-ID zweites Mal
* invalid role or secret ID
== falsches Quellnetz
* source address "127.0.0.1" unauthorized by CIDR restrictions on the role: %!w(<nil>)
If unwrapping fails for the real recipient, someone has already
opened the package: raise the alarm, do not retry. Through the
port-forward, OpenBao sees 127.0.0.1 as the source; in
production these are the agent networks.
Save your progress? Sign up for free
Checkpoint
cat > check.sh <<'EOF'
#!/usr/bin/env bash
cd ~/secrets-lab/tag10
export BAO_ADDR="${BAO_ADDR:-http://127.0.0.1:8200}"
login() { BAO_TOKEN= bao write -field=token auth/jwt-ci/login role=$1 \
jwt="$(./mint-jwt.sh "${@:2}")" 2>/dev/null; }
T=$(login deploy-main)
[ "$(BAO_TOKEN=$T bao kv get -field=registry_password secret/ci/deploy 2>/dev/null)" \
= lab-reg-pw ] && echo "✔ main darf secret/ci/deploy lesen" || echo "✘ main-Login"
login deploy-main ref=refs/heads/dev >/dev/null && echo "✘ dev-Branch kommt rein" \
|| echo "✔ dev-Branch abgewiesen"
login deploy-main ttl=-120 >/dev/null && echo "✘ abgelaufenes JWT akzeptiert" \
|| echo "✔ abgelaufenes JWT abgewiesen"
login deploy-release ref=refs/tags/v2.0.0 >/dev/null && echo "✔ Tag-Release per Glob" \
|| echo "✘ Glob-Rolle"
[ "$(BAO_TOKEN=root bao read -field=secret_id_num_uses \
auth/approle/role/jenkins-deploy)" = 1 ] && echo "✔ Secret-ID einmalig" \
|| echo "✘ secret_id_num_uses"
EOF
bash check.shExpected:
✔ main darf secret/ci/deploy lesen
✔ dev-Branch abgewiesen
✔ abgelaufenes JWT abgewiesen
✔ Tag-Release per Glob
✔ Secret-ID einmalig
Challenge
A role build-any should serve all repos of the
organization acme. But each repo may read only its own
secrets under secret/ci/repos/<repo>/, controlled by
a templated policy.
Hint: Template values must not contain
/, so acme/shop is out. Use the stable claim
repository_id.
Solution
export BAO_TOKEN=root
ACC=$(bao auth list -format=json | jq -r '."jwt-ci/".accessor')
P="identity.entity.aliases.${ACC}.metadata.repository_id"
bao policy write ci-repo - <<EOF
path "secret/data/ci/repos/{{${P}}}/*" {
capabilities = ["read"]
}
EOF
bao kv put secret/ci/repos/100001/sonar token=lab-sonar-1 >/dev/null
bao kv put secret/ci/repos/100002/sonar token=lab-sonar-2 >/dev/null
bao write auth/jwt-ci/role/build-any - <<'EOF'
{
"role_type": "jwt", "user_claim": "sub", "bound_audiences": ["openbao"],
"bound_claims": {"repository_owner": "acme"},
"claim_mappings": {"repository_id": "repository_id"},
"token_policies": ["ci-repo"], "token_ttl": "5m"
}
EOF
T=$(BAO_TOKEN= bao write -field=token auth/jwt-ci/login role=build-any \
jwt="$(./mint-jwt.sh)")
BAO_TOKEN=$T bao kv get -field=token secret/ci/repos/100001/sonar; echo
BAO_TOKEN=$T bao kv get -field=token secret/ci/repos/100002/sonar 2>&1 \
| grep -m1 deniedExpected:
lab-sonar-1
* permission denied
With metadata.repository instead of
repository_id, the server log reports
template substitution contains forbidden value: "/", and
every access ends with a 403.
Save your progress? Sign up for free
Enterprise Note
- One role per repo/environment, always bound to an immutable ID
(
repository_id,project_id), not just to names that can be renamed. - Tie
token_ttlto the job duration (5–15 min), settoken_max_ttlfirmly; the pipeline revokes at the end withbao token revoke -self. - AppRole only as a transitional solution: role ID and secret ID through separate channels, secret ID single-use, wrapped, with a CIDR binding; the orchestrator token itself short-lived.
- Alert on
auth/jwt-ci/loginerrors in the audit log: ifdoes not matcherrors pile up, someone is trying foreign branches or forks (Day 14). - Key rotation at the CI provider: use
jwks_url/discovery instead of hard-coded public keys, otherwise the login breaks on every key change.