Skip to content

Commit c464507

Browse files
committed
Use JWT to get GH Token
Previously I thought that we could use the JWT to as the token for github, but we actually need to use that to get the github token, and then everything else should work the same. I tried this by checking the auth status on a test run, and it seems to work.
1 parent b2d9b94 commit c464507

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

serverless/release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ if [ "$PROD_RELEASE" = true ] ; then
7171
git remote set-url origin https://github.com/DataDog/datadog-cloudformation-macro.git
7272

7373
echo "Checking git auth status"
74-
gh auth status
74+
gh auth status
7575

7676
git config --global user.name "gitlab-actions[bot]"
7777
git config --global user.email "gitlab-actions[bot]@users.noreply.github.com"

serverless/tools/get_secrets.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@ set -e
1010
# Get the JWT
1111
export GH_APP_ID=$(vault kv get -field="gh_app_id" kv/k8s/gitlab-runner/datadog-cloudformation-macro/secrets)
1212
export GH_PRIVATE_KEY=$(vault kv get -field="gh_private_key" kv/k8s/gitlab-runner/datadog-cloudformation-macro/secrets)
13+
export GH_INSTALLATION_ID=$(vault kv get -field="gh_installation_id" kv/k8s/gitlab-runner/datadog-cloudformation-macro/secrets)
14+
1315

1416
# Write private key to a temporary file
1517
PRIVATE_KEY_FILE=$(mktemp)
1618
echo "$GH_PRIVATE_KEY" > "$PRIVATE_KEY_FILE"
1719

1820
# Get the GH token
19-
export GH_TOKEN=$(bash serverless/tools/generate_jwt.sh $GH_APP_ID $PRIVATE_KEY_FILE)
21+
export JWT_TOKEN=$(bash serverless/tools/generate_jwt.sh $GH_APP_ID $PRIVATE_KEY_FILE)
22+
23+
export GH_TOKEN=$(curl -s -X POST \
24+
-H "Authorization: Bearer $JWT_TOKEN" \
25+
-H "Accept: application/vnd.github.v3+json" \
26+
"https://api.github.com/app/installations/$GH_INSTALLATION_ID/access_tokens" | jq -r '.token')
2027

2128

2229
if [ -z "$EXTERNAL_ID_NAME" ]; then

0 commit comments

Comments
 (0)