The idea is to share token between jobs, in order to avoid duplicating
the step of the generated token,
- any risks on doing so ?
- Seems that I am losing the token
value in the others jobs, any ideas?
name: My Workflow
on: push:
branches:
- main
jobs:
generate-token:
runs-on: ubuntu-latest
outputs:
token: ${{ steps.github-app-token.outputs.token }}
steps:
- name: Generate Github App access token
id: github-app-token
uses: tibdex/github-app-token@021a2405c7f990db57f5eae5397423dcc554159c
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.PRIVATE_KEY }}
installation_id: ${{ secrets.INSTALLATION_ID }}
- name: Print access token
run: echo ${{ steps.github-app-token.outputs.token }}
my-job:
runs-on: ubuntu-latest
needs: generate-token
env:
APP_ACCESS_TOKEN: ${{ needs.generate-token.outputs.token }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Use Github API
run: |
curl -H "Authorization: Bearer $APP_ACCESS_TOKEN" https://api.github.com/user
Thank you for your help
3
Answers
What worked for me (but not sure if I will actually use it) a solution proposed in this article
PS, I had an issue with the expirationdate, but this is another problem
Your job
my-job
is missing theneeds
keyword. In order to use the output from a previous job you need to specify thatmy-job
depends ongenerate-token
by usingneeds
. Only then can you use${{ needs.generate-token.outputs.token }}
. Also I would suggest re-ordering your job in your workflows fail it will make it easier to understand.⚠️ Be VERY careful when passing secrets between jobs. The secret value will be visible in a number of cases, even if you apply the `::add-mask“ command diligently. Even if you encrypt the value, it may not be easily accessible, but the encrypted value will be logged and can be intercepted.
In a number of cases the runner will even fail to set the output variable altogether, it will log a warning, but won’t fail the build:
When a job runs in debug mode, even the first step will list all of the variables passed to it. They are logged in the debug logs plaintext and won’t be retroactively scrubbed when you register the secret using
::add-mask
in the script itself.Sample workflow:
In the debug logs:
⚠️ Even if you encrypt the secret using GPG or another tool, the encrypted text will be stored for anyone to see and could be reverse engineered. You can’t hide the text safely.
⚠️ Most auth-related actions will inject a post-job script which will revoke the token as soon as the job finishes. So you can’t rely on a token to survive the job.