actions / checkout

Action for checking out a repo
https://github.com/features/actions
MIT License
5.88k stars 1.74k forks source link

Remove `persist-credentials` or change the default to `false` #485

Open briansmith opened 3 years ago

briansmith commented 3 years ago

Currently one has to resort to explicitly specifying persist-credentials: false to avoid the credentials being persistent. My understanding is that persisting the credentials gives every step in the job that occurs after actions/checkout@v2 implicit access to the token. This is not what people expect and this leads people to write jobs that expose their repo to more risk than they otherwise would.

I propose the persist-credentials feature be removed completely and then v3 be released. Otherwise, if that's not practical, then at least the default should be changed to false.

haampie commented 3 years ago

I can't believe the default is to persist credentials and expose them to other jobs :( this is a major security issue.

Just as a heads up for anyone stumbling upon this issue:

  1. persist-credentials: false is only relevant when you use ssh authentication, because
  2. GITHUB_TOKEN is always exposed to all jobs, and by default has write access to your repo.

So if you want to harden security, apart from setting persist-credentials: false for ssh auth, make sure that GITHUB_TOKEN auth has no write permission to your repo.

See https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/ for reference.

fmg-dave commented 3 years ago

+1

eregon commented 2 years ago

Agreed this seems a severe security issue, because it means any workflow using actions/checkout basically leaks the token to any process/action in that workflow which can just read it from .git/config.

@haampie IIUC it is a problem also with no ssh authentication (the default). The GitHub token is given only to this action and maybe a few other actions/* actions (default: ${{ github.token }} only work for those AFAIK), but is otherwise given to no other action unless done explicitly (like with: token: ${{ github.token }}/${{ secrets.GITHUB_TOKEN }}). The token is not in the environment.

In other words, actions/checkout leaks the token to .git/config, making it very easy to read for anything running inside the workflow. If the token was not written to .git/config, then I think stealing the GitHub token would require (one of):

So, depending on whether the token is explicitly passed to some action:

I guess GitHub sees setting token permissions as the more general solution. If so, fine, but then the default should be secure and so the default workflow permissions should be just contents: read.

https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ also has a mention related to this, search for persist-credentials:

If the workflow uses actions/checkout and does not pass the optional parameter persist-credentials as false, it makes it even worse. The default for the parameter is true. It means that in any subsequent steps any running code can simply read the stored repository token from the disk.

mgoltzsche commented 1 year ago

+1

briansmith commented 1 year ago

I updated the issue title since v3 and v4 have already shipped, so asking for a new v3 doesn't make sense.

haampie commented 9 months ago

Fast forward to 2024, and we have https://johnstawinski.com/2024/01/11/playing-with-fire-how-we-executed-a-critical-supply-chain-attack-on-pytorch/

PyTorch had several workflows that used the actions/checkout step with a GITHUB_TOKEN that had write permissions. For example, by searching through workflow logs, we can see the periodic.yml workflow also ran on the jenkins-worker-rocm-amd-34 self-hosted runner. The logs confirmed that this workflow used a GITHUB_TOKEN with extensive write permissions.

@ericsciple could you please take this issue seriously and disable persisting credentials to disk?

swebb2066 commented 6 months ago

Not sure this is actually necessary. There seems to be a mismatch between the documentated default and the code

As I read the code, the 'persist-credentials' value will be false if the input does not contain a 'persist-credentials' entry.

The issue should be changed to a 'fix the documentation' if my understanding is correct.

joshmgross commented 5 months ago

Not sure this is actually necessary. There seems to be a mismatch between the documentated default and the code

That default: true in the action.yml is the default that's set by the Actions runner if no value is provided, it's more than just documentation.

https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs

swebb2066 commented 5 months ago

That default: true in the action.yml is the default that's set by the Actions runner if no value is provided, it's more than just documentation.

Is there some reference that says that Actons runner creates an environment variable when the item not required: true ? All I could see in the linked documentation is the following statement.

When you specify an input in a workflow file or use a default input value, GitHub creates an environment variable for the input