Skip to content

Commit 975efb0

Browse files
committed
Example CI job for GitHub Actions OIDC authenticated notary
Token is not available within pull_request context. Related: slsa-framework/slsa-github-generator#131 Related: slsa-framework/slsa-github-generator#358 Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
1 parent b40b5ee commit 975efb0

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

.github/workflows/notarize.yml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: "SCITT Notary"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- '**.md'
9+
workflow_dispatch:
10+
inputs:
11+
scitt-url:
12+
description: 'URL of SCITT instance'
13+
type: string
14+
payload:
15+
description: 'Payload for claim'
16+
default: ''
17+
type: string
18+
workflow_call:
19+
inputs:
20+
scitt-url:
21+
description: 'URL of SCITT instance'
22+
type: string
23+
payload:
24+
description: 'Payload for claim'
25+
type: string
26+
27+
jobs:
28+
notarize:
29+
runs-on: ubuntu-latest
30+
permissions:
31+
id-token: write
32+
env:
33+
SCITT_URL: '${{ inputs.scitt-url || github.event.inputs.scitt-url }}'
34+
PAYLOAD: '${{ inputs.payload || github.event.inputs.payload }}'
35+
steps:
36+
- name: Set defaults if env vars not set (as happens with on.push trigger)
37+
run: |
38+
if [[ "x${SCITT_URL}" = "x" ]]; then
39+
echo "SCITT_URL=http://localhost:8080" >> "${GITHUB_ENV}"
40+
fi
41+
if [[ "x${PAYLOAD}" = "x" ]]; then
42+
echo 'PAYLOAD={"key": "value"}' >> "${GITHUB_ENV}"
43+
fi
44+
- uses: actions/checkout@v4
45+
- name: Set up Python 3.8
46+
uses: actions/setup-python@v4
47+
with:
48+
python-version: 3.8
49+
- name: Install SCITT API Emulator
50+
run: |
51+
pip install -U pip setuptools wheel
52+
pip install .[oidc]
53+
- name: Install github-script dependencies
54+
run: |
55+
npm install @actions/core
56+
- name: Get OIDC token to use as bearer token for auth to SCITT
57+
uses: actions/github-script@v6
58+
id: github-oidc
59+
with:
60+
script: |
61+
const {SCITT_URL} = process.env;
62+
core.setOutput('token', await core.getIDToken(SCITT_URL));
63+
- name: Create claim
64+
run: |
65+
scitt-emulator client create-claim --issuer did:web:example.org --content-type application/json --payload "${PAYLOAD}" --out claim.cose
66+
- name: Submit claim
67+
env:
68+
OIDC_TOKEN: '${{ steps.github-oidc.outputs.token }}'
69+
run: |
70+
# Create the middleware config file
71+
cat > oidc-middleware-config.json <<EOF
72+
{
73+
"issuer": "https://token.actions.githubusercontent.com",
74+
"audience": "${SCITT_URL}"
75+
}
76+
EOF
77+
# Start SCITT using the `OIDCAuthMiddleware` and associated config.
78+
if [[ "x${SCITT_URL}" = "xhttp://localhost:8080" ]]; then
79+
scitt-emulator server --port 8080 --workspace workspace/ --tree-alg CCF \
80+
--middleware scitt_emulator.oidc:OIDCAuthMiddleware \
81+
--middleware-config-path oidc-middleware-config.json &
82+
fi
83+
# Submit the claim using OIDC token as auth
84+
scitt-emulator client submit-claim --token "${OIDC_TOKEN}" --url "${SCITT_URL}" --claim claim.cose --out claim.receipt.cbor

0 commit comments

Comments
 (0)