Skip to content

Commit c83b5db

Browse files
authored
Merge pull request #3696 from grafana/vldmr/update-help-repo-vault-secrets
Allow update-helm-repo workflow to retrieve app secrets from Vault
2 parents d86c20e + d801fbc commit c83b5db

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

.github/workflows/update-helm-repo.yaml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ on:
3030
github_app_pem:
3131
description: GitHub APP pem to authenticate with
3232
required: false
33+
vault_repo_secret_name:
34+
description: Vault secret name that holds repository's GitHub App credentials to authenticate with
35+
required: false
3336
helm_repo_token:
3437
description: GitHub api token to use against the helm-charts repository
3538
required: false
@@ -96,26 +99,41 @@ jobs:
9699
needs: [setup]
97100
runs-on: ubuntu-latest
98101
permissions:
102+
id-token: write # allows GitHub App to generate id-token from Github's OIDC
99103
contents: write # allows GITHUB_TOKEN to push chart release, create release, and push tags to github
100104
packages: write # allows GITHUB_TOKEN to push package to ghcr
101105
env:
102-
github_app_id: ${{ secrets.github_app_id }}
106+
# APP_ID and PRIVATE_KEY are overwritten by credentials from vault, if configured
107+
GITHUB_APP_ID: ${{ secrets.github_app_id }}
108+
PRIVATE_KEY: ${{ secrets.github_app_pem }}
109+
VAULT_REPO_SECRET_NAME: ${{ secrets.vault_repo_secret_name }}
103110
if: needs.setup.outputs.changed == 'true'
104111
steps:
105-
- name: Create a GitHub App installation access token
106-
if: env.github_app_id != ''
107-
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
112+
- name: Retrieve GitHub App credentials from Vault
113+
if: env.VAULT_REPO_SECRET_NAME != ''
114+
id: get-secrets
115+
uses: grafana/shared-workflows/actions/get-vault-secrets@28361cdb22223e5f1e34358c86c20908e7248760 # v1.1.0
116+
with:
117+
repo_secrets: |
118+
GITHUB_APP_ID=${{ env.VAULT_REPO_SECRET_NAME }}:app-id
119+
PRIVATE_KEY=${{ env.VAULT_REPO_SECRET_NAME }}:private-key
120+
121+
- name: Generate GitHub App Token
122+
if: env.GITHUB_APP_ID != ''
108123
id: app-token
124+
uses: actions/create-github-app-token@v1
109125
with:
110-
app_id: ${{ env.github_app_id }}
111-
private_key: ${{ secrets.github_app_pem }}
126+
# Variables generated by the previous step get-secrets
127+
app-id: ${{ env.GITHUB_APP_ID }}
128+
private-key: ${{ env.PRIVATE_KEY }}
129+
owner: ${{ github.repository_owner }}
112130

113131
- name: Set the correct token (Github App or PAT)
114132
env:
115133
HELM_REPO_TOKEN: ${{ secrets.helm_repo_token }}
116134
APP_TOKEN: ${{ steps.app-token.outputs.token }}
117135
run: |
118-
if [[ "${github_app_id}" == '' ]]; then
136+
if [[ "${GITHUB_APP_ID}" == '' ]]; then
119137
echo "AUTHTOKEN=${HELM_REPO_TOKEN}" >> $GITHUB_ENV
120138
else
121139
echo "AUTHTOKEN=${APP_TOKEN}" >> $GITHUB_ENV

0 commit comments

Comments
 (0)