-
Notifications
You must be signed in to change notification settings - Fork 0
Add GitHub Actions OIDC workflow for Pomerium verification #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
06eefe2
Initial plan
Copilot e5ac9b7
Add GitHub OIDC Pomerium workflow
Copilot 1f70fcc
Fix fatal redeclaration of core in the github-script step
ssveta7ak 9ac4153
Potential fix for pull request finding
ssveta7ak 11df61c
Bump github-script to v9 and scope the push trigger to main
ssveta7ak 82d3830
Print the OIDC token's header and claims
ssveta7ak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| name: Verify Pomerium with GitHub OIDC | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
| inputs: | ||
| url: | ||
| description: URL to open with the GitHub OIDC JWT | ||
| required: false | ||
| default: https://verify.sv.sandbox.pomerium.io | ||
| audience: | ||
| description: Audience to request for the GitHub OIDC JWT | ||
| required: false | ||
| default: https://verify.sv.sandbox.pomerium.io | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| jobs: | ||
| verify: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Authenticate to Pomerium with GitHub OIDC | ||
| uses: actions/github-script@v9 | ||
| env: | ||
| DEFAULT_POMERIUM_URL: https://verify.sv.sandbox.pomerium.io | ||
| DEFAULT_POMERIUM_AUDIENCE: https://verify.sv.sandbox.pomerium.io | ||
| INPUT_URL: ${{ inputs.url }} | ||
| INPUT_AUDIENCE: ${{ inputs.audience }} | ||
| with: | ||
| script: | | ||
| const targetUrl = process.env.INPUT_URL || process.env.DEFAULT_POMERIUM_URL; | ||
| const audience = process.env.INPUT_AUDIENCE || process.env.DEFAULT_POMERIUM_AUDIENCE; | ||
|
|
||
| core.info(`Requesting GitHub OIDC token for audience: ${audience}`); | ||
| const idToken = await core.getIDToken(audience); | ||
| core.setSecret(idToken); | ||
|
|
||
| // Print the token's header and claims, never the token itself: the | ||
| // signature is what makes it usable, and this repository's logs are public. | ||
| const decodeSegment = (segment) => | ||
| JSON.parse(Buffer.from(segment, 'base64url').toString('utf8')); | ||
| const [rawHeader, rawPayload] = idToken.split('.'); | ||
| const header = decodeSegment(rawHeader); | ||
| const claims = decodeSegment(rawPayload); | ||
|
|
||
| core.startGroup('GitHub OIDC token - header'); | ||
| core.info(JSON.stringify(header, null, 2)); | ||
| core.endGroup(); | ||
|
|
||
| core.startGroup('GitHub OIDC token - claims'); | ||
| core.info(JSON.stringify(claims, null, 2)); | ||
| core.endGroup(); | ||
|
|
||
| const asUTC = (s) => new Date(s * 1000).toISOString(); | ||
| core.info(`Signed with ${header.alg} (key id ${header.kid})`); | ||
| core.info(`iss=${claims.iss}`); | ||
| core.info(`aud=${claims.aud}`); | ||
| core.info(`sub=${claims.sub}`); | ||
| core.info(`repository=${claims.repository} ref=${claims.ref} event=${claims.event_name}`); | ||
| core.info(`valid ${asUTC(claims.iat)} -> ${asUTC(claims.exp)} (${claims.exp - claims.iat}s)`); | ||
|
|
||
| core.info(`Opening ${targetUrl} with the GitHub OIDC JWT`); | ||
| const response = await fetch(targetUrl, { | ||
| headers: { | ||
| Authorization: `Bearer ${idToken}`, | ||
| Accept: 'application/json', | ||
| }, | ||
| redirect: 'manual', | ||
| }); | ||
|
|
||
| core.info(`Received ${response.status} ${response.statusText}`); | ||
|
|
||
| if (!response.ok) { | ||
| const location = response.headers.get('location'); | ||
| const body = (await response.text()).slice(0, 4000); | ||
| const redirectHint = location ? `\nRedirected to: ${location}` : ''; | ||
| core.setFailed(`Request to ${targetUrl} failed with ${response.status} ${response.statusText}${redirectHint}\n${body}`); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,17 @@ | ||
| # github-actions-jwt-test | ||
| # github-actions-jwt-test | ||
|
|
||
| This repository includes a GitHub Actions workflow that requests a GitHub OIDC JWT and uses it to open `https://verify.sv.sandbox.pomerium.io`. | ||
|
|
||
| ## Workflow | ||
|
|
||
| - Workflow file: `.github/workflows/pomerium-verify.yml` | ||
| - Triggered on every push and with manual `workflow_dispatch` | ||
| - Requests `id-token: write` so the job can mint a GitHub OIDC JWT | ||
| - Sends the JWT in the `Authorization` header to the target URL | ||
|
|
||
| ## Manual run | ||
|
|
||
| You can run the workflow manually and optionally override: | ||
|
|
||
| - `url` (defaults to `https://verify.sv.sandbox.pomerium.io`) | ||
| - `audience` (defaults to `https://verify.sv.sandbox.pomerium.io`) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.