Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare permissions #15493

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Declare permissions #15493

wants to merge 1 commit into from

Conversation

jsoref
Copy link
Contributor

@jsoref jsoref commented Jan 31, 2024

Repositories can be configured with Default access (restricted) https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token

Best practice says that workflows should declare the minimal permissions they require. Without declaring permissions, paranoid forks fail miserably.

closes #15462

@jsoref
Copy link
Contributor Author

jsoref commented Jan 31, 2024

To make the Check change note workflow happy, please add label:no-change-note-required

angelapwen
angelapwen previously approved these changes Jan 31, 2024
Copy link
Contributor

@angelapwen angelapwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at your fork of the repo, which has identical permissions and works 👍 thank you for the contribution!

csharp/actions/create-extractor-pack/action.yml Outdated Show resolved Hide resolved
Comment on lines +12 to +14
permissions:
contents: read

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been reminded to check that all of these permissions are necessary. Undoubtedly the security-events:write one for the QL-for-QL tests workflow is, as we saw elsewhere.

I tried this one in particular out on my own fork (where the current commit is main and where I've set the default token permissions to read-only) and it looks like this one passes without adding the extra permission. Is this because read is allowed with the least permissive setting?

These are the options I have:
Screenshot 2024-02-01 at 11 14 53 AM

It would be nice to confirm that all the added permissions are necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this looks like a grant, it's actually a restriction. By default you get some additional permissions:

  Contents: read
  Metadata: read
  Packages: read

By specifying contents: read, it's blocking packages: read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contents: read is theoretically needed for any workflow that uses actions/checkout (it might not realistically fail in public forks of a repository, but it would absolutely fail if someone made a private repository with the same contents).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should note that I do things like that regularly when I'm testing repositories looking for vulnerabilities.

(It isn't my day job, but I do it often enough. It's definitely considered best practice. Admittedly, w/o a GHES license w/ CodeQL it'd be a bit of a PITA here, but it's technically possible to manage if you used a second public repository with a PAT for the codeql bits. But the general idea here is to show best practices so that if people copy+paste they get best practices.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/check-spelling-sandbox/codeql/actions/runs/7820458947/job/21335230118

GITHUB_TOKEN Permissions
  Contents: read
  Metadata: read
Warning: CodeQL Action v2 will be deprecated on December 5th, 2024. Please update all occurrences of the CodeQL Action in your workflow files to v3. For more information, see https://github.blog/changelog/2024-01-12-code-scanning-deprecation-of-codeql-action-v2/
RequestError [HttpError]: Resource not accessible by integration
    at /home/runner/work/_actions/github/codeql-action/v2/node_modules/@octokit/request/dist-node/index.js:86:21
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async requestWithGraphqlErrorHandling (/home/runner/work/_actions/github/codeql-action/v2/node_modules/@octokit/plugin-retry/dist-node/index.js:71:20)
    at async Job.doExecute (/home/runner/work/_actions/github/codeql-action/v2/node_modules/bottleneck/light.js:405:18) {
  status: 403,
  response: {
    url: 'https://api.github.com/repos/check-spelling-sandbox/codeql/code-scanning/analysis/status',
    status: 403,

codeql-action/init currently requires a lot of stuff, that's currently github/codeql-action#2110

I guess I should try to polish that PR off before I finish this PR.

I can test this branch (as main to deal w/ all the frustrating checks that only run on main) with my hacked version of the codeql action to see how this would fare...

Copy link
Contributor

@angelapwen angelapwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking merge until the other comments are addressed 😄

Repositories can be configured with Default access (restricted)
https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token

Best practice says that workflows should declare the minimal permissions they require.
Without declaring permissions, paranoid forks fail miserably.
Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing this. I like that this narrows the permissions of all of our tokens.

I think .github/workflows/csv-coverage-update.yml is broken. I have a few other suggestions that will allow you to narrow the permissions. security-events is only required if we are reading or writing SARIF to or from code scanning.

I do have a concern that these jobs haven't been run. Are you able to trigger them in your fork to make sure all permissions are correct?

What we do in other repos and can do here (but best to wait for a followup PR) is to add a chunk that ensures the workflow file is run whenever the workflow file itself is modified.

eg-

  pull_request:
    paths:
      - '.github/workflows/csv-coverage-timeseries.yml'

(and similar for all other workflow files)

.github/workflows/csv-coverage-update.yml Show resolved Hide resolved
.github/workflows/ql-for-ql-tests.yml Show resolved Hide resolved
@@ -13,6 +13,10 @@ on:
- '.github/actions/fetch-codeql/action.yml'
- 'misc/scripts/generate-code-scanning-query-list.py'

permissions:
contents: read
security-events: read
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary?

Suggested change
security-events: read

.github/workflows/ruby-dataset-measure.yml Show resolved Hide resolved
@@ -29,6 +29,10 @@ defaults:
run:
working-directory: ruby

permissions:
contents: read
security-events: read
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Suggested change
security-events: read

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe?

I can't get ruby to build (I think I need larger runners or to try to kill a bunch of processes to get my runs more memory):
https://github.com/check-spelling-sandbox/codeql/actions/runs/7820458922/job/21335248948

We'll see what things look like when I update this PR.

@@ -33,6 +33,10 @@ on:
- rc/*
- codeql-cli-*

permissions:
contents: read
security-events: read
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Suggested change
security-events: read

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe?

This job consistently dies:
https://github.com/check-spelling-sandbox/codeql/actions/runs/7820458953/job/21335237762

We'll see what things look like when I update this PR.

But, I'd expect it to consistently die.

.github/workflows/validate-change-notes.yml Show resolved Hide resolved
@jsoref
Copy link
Contributor Author

jsoref commented Feb 7, 2024

@aeisenberg: the design of these workflows is really painful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note QL-for-QL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Workflows are missing permissions requests
3 participants