octokit / request-action

A GitHub Action to send arbitrary requests to GitHub's REST API
https://github.com/marketplace/actions/GitHub-API-Request
MIT License
363 stars 48 forks source link

[BUG]: sensitive output (`actions/runners/registration-token`) can't be masked #213

Open dennisameling opened 1 year ago

dennisameling commented 1 year ago

What happened?

Consider the following Actions config:

   - name: Generate Actions Runner token
      uses: octokit/request-action@v2.x
      id: generate-actions-runner-token
      with:
        route: POST /repos/{owner}/{repo}/actions/runners/registration-token
        owner: ${{ env.ACTIONS_RUNNER_ORG }}
        repo: ${{ env.ACTIONS_RUNNER_REPO }}
      env:
        GITHUB_TOKEN: ${{ secrets.GH_API_PAT }}

   - name: Set and mask Actions Runner token for next steps
     run: |
        # We need to mask the token first before setting it to an env variable
        echo "::add-mask::${{ fromJson(steps.generate-actions-runner-token.outputs.data).token }}"
        ACTIONS_RUNNER_TOKEN=${{ fromJson(steps.generate-actions-runner-token.outputs.data).token }}
        echo ACTIONS_RUNNER_TOKEN=$ACTIONS_RUNNER_TOKEN >> $GITHUB_ENV    

This actually exposes the token to the CI logs, as also reported in this issue: https://github.com/actions/runner/issues/475

image

You might want to add a warning about this to the README of this action or find another solution to hide this sensitive data. Thanks!

Versions

octokit/request-action@v2.x

Relevant log output

See above

Code of Conduct

kfcampbell commented 1 year ago

@dennisameling thanks for your concern here! This does appear to be a bug with actions/runner upstream as you've linked; I can't find anywhere in this repository we have logic related to masking specifically.

I do think that a README update might be useful here. Is that something you have interest in creating?

dennisameling commented 1 year ago

Sorry for the late reply here!

I do think that a README update might be useful here. Is that something you have interest in creating?

Sure, please give me a few days to work through some other things first. Will link the PR to this issue when done 👍🏼

kfcampbell commented 9 months ago

Perhaps an enterprising Hacktoberfest contributor may want to take this on!