Skip to content

Commit 16a9508

Browse files
ci: Add an action to get a lowrisc-ci app installation access token
Signed-off-by: Harry Callahan <hcallahan@lowrisc.org>
1 parent b89f549 commit 16a9508

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright lowRISC contributors (OpenTitan project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# NOTE.
6+
# Requires id-token: write in the workflow to get the JWT
7+
8+
name: Get lowrisc-ci app access token
9+
description: Obtain a lowrisc-ci GitHub App installation access token from the lowRISC CA
10+
11+
inputs:
12+
audience:
13+
description: intended audience for the requested JWT
14+
type: string
15+
default: "https://ca.lowrisc.org"
16+
ca_api_endpoint:
17+
description: lowRISC CA endpoint from which to try and obtain a token.
18+
type: string
19+
default: "https://ca.lowrisc.org/api/github/repos/${{ github.repository }}/token"
20+
21+
runs:
22+
using: "composite"
23+
steps:
24+
- name: Get and exchange tokens
25+
id: get_token
26+
run: |
27+
# First, manually request a JSON Web Token (JWT) from GitHub's OIDC provider for the workflow
28+
# - Set our CA as the intended audience
29+
ID_TOKEN=$(curl -sSf -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=${{ inputs.audience }}" | jq -r .value)
30+
echo "::add-mask::$ID_TOKEN"
31+
# Now use the JWT token to request the lowRISC CA to provide an lowrisc-ci app installation access token suitable for our action
32+
ACCESS_TOKEN=$(curl -sSf -X POST -H "Authorization: Bearer $ID_TOKEN" ${{ inputs.ca_api_endpoint }})
33+
echo "::add-mask::$ACCESS_TOKEN
34+
echo "token=$ACCESS_TOKEN" >> "$GITHUB_OUTPUT"
35+
36+
outputs:
37+
token:
38+
description: "Token"
39+
value: ${{ steps.get_token.outputs.token }}
40+

0 commit comments

Comments
 (0)