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

Add token permissions for code-scanning/trivy.yml #1348

Merged
merged 3 commits into from
Jan 28, 2022
Merged

Add token permissions for code-scanning/trivy.yml #1348

merged 3 commits into from
Jan 28, 2022

Conversation

Devils-Knight
Copy link
Contributor

@Devils-Knight Devils-Knight commented Jan 13, 2022

This PR adds token permissions for code-scanning/trivy.yml. The permissions were added using https://app.stepsecurity.io/.

Pre-requisites

  • Prior to submitting a new workflow, please apply to join the GitHub Technology Partner Program: partner.github.com/apply.

Please note that at this time we are only accepting new starter workflows for Code Scanning. Updates to existing starter workflows are fine.


Tasks

For all workflows, the workflow:

  • Should be contained in a .yml file with the language or platform as its filename, in lower, kebab-cased format (for example, docker-image.yml). Special characters should be removed or replaced with words as appropriate (for example, "dotnet" instead of ".NET").
  • Should use sentence case for the names of workflows and steps (for example, "Run tests").
  • Should be named only by the name of the language or platform (for example, "Go", not "Go CI" or "Go Build").
  • Should include comments in the workflow for any parts that are not obvious or could use clarification.

For CI workflows, the workflow:

  • Should be preserved under the ci directory.
  • Should include a matching ci/properties/*.properties.json file (for example, ci/properties/docker-publish.properties.json).
  • Should run on push to branches: [ $default-branch ] and pull_request to branches: [ $default-branch ].
  • Packaging workflows should run on release with types: [ created ].
  • Publishing workflows should have a filename that is the name of the language or platform, in lower case, followed by "-publish" (for example, docker-publish.yml).

For Code Scanning workflows, the workflow:

  • Should be preserved under the code-scanning directory.
  • Should include a matching code-scanning/properties/*.properties.json file (for example, code-scanning/properties/codeql.properties.json), with properties set as follows:
    • name: Name of the Code Scanning integration.
    • organization: Name of the organization producing the Code Scanning integration.
    • description: Short description of the Code Scanning integration.
    • categories: Array of languages supported by the Code Scanning integration.
    • iconName: Name of the SVG logo representing the Code Scanning integration. This SVG logo must be present in the icons directory.
  • Should run on push to branches: [ $default-branch, $protected-branches ] and pull_request to branches: [ $default-branch ]. We also recommend a schedule trigger of cron: $cron-weekly (for example, codeql.yml).

Some general notes:

  • This workflow must only use actions that are produced by GitHub, in the actions organization, or
  • This workflow must only use actions that are produced by the language or ecosystem that the workflow supports. These actions must be published to the GitHub Marketplace. We require that these actions be referenced using the full 40 character hash of the action's commit instead of a tag. Additionally, workflows must include the following comment at the top of the workflow file:
    # This workflow uses actions that are not certified by GitHub.
    # They are provided by a third-party and are governed by
    # separate terms of service, privacy policy, and support
    # documentation.
    
  • Automation and CI workflows should not send data to any 3rd party service except for the purposes of installing dependencies.
  • Automation and CI workflows cannot be dependent on a paid service or product.

@Devils-Knight Devils-Knight requested a review from a team as a code owner January 13, 2022 05:48
@github-actions github-actions bot added the code-scanning Related to workflows that show on the Code Scanning setup page label Jan 13, 2022
@Devils-Knight Devils-Knight changed the title Update trivy.yml Add token permissions for code-scanning/trivy.yml Jan 13, 2022
Comment on lines 17 to 23
permissions: read-all

jobs:
build:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, thanks for the PR!

Could you explain what you're aiming for with these changes? It seems that the top-level permissions statement is superfluous given the more specific statement applied to the build job...?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @nickfyson, @knqyf263 these changes are part of #1299. @Devils-Knight and others from StepSecurity are fixing token permissions across the starter workflow templates, so they are secure by default. We have also setup a website https://app.stepsecurity.io that developers can use to set token permissions for their workflows.

@nickfyson to answer your question, ossf/scorecards recommends adding workflow level permissions, so that if developers add a new job to the workflow, it inherits the read-all permissions, and is secure-by-default.

@knqyf263 to answer your question, if job level permissions are granted, then any permission not specified is not granted to the job. So, if contents: read is removed, the build job will not have contents-read permission.

CC: @laurentsimon

Copy link
Contributor

@nickfyson nickfyson Jan 26, 2022

Choose a reason for hiding this comment

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

Ah, thanks for the context. 🙂

How come read-all though? Would it be even better to just give read to contents by default and nothing else?

Copy link
Contributor

Choose a reason for hiding this comment

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

@nickfyson yes, we got that feedback from multiple developers, and have updated the logic on https://app.stepsecurity.io/. This PR was created before that change though. @Devils-Knight can you please update this PR so that the workflow level permissions are set to contents: 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.

@varunsh-coder Thanks for explaining the changes 😇. Have updated the workflow level permission as requested by you please check it out.

Copy link
Contributor

Choose a reason for hiding this comment

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

@varunsh-coder Thanks for explaining the changes 😇. Have updated the workflow level permission as requested by you please check it out.

LGTM

jobs:
build:
permissions:
contents: read # for actions/checkout to fetch code
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, I'm a maintainer of Trivy. I'd like to know why this line is needed. Looks like read-all is granted in the top-level permissions.

Copy link
Contributor

@laurentsimon laurentsimon Jan 26, 2022

Choose a reason for hiding this comment

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

Good question. If you define permissions in the job, those you do not specify default to none, not to the ones defined at the top level. The top level permissions only serve as a fail-safe mechanism if a developer ever adds a new job and forget to set permissions explicitly... this happens :-)
See the doc in https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idpermissions If you specify the access for any of these scopes, all of those that are not specified are set to none

It was confusing to me a first as well.

Copy link
Contributor

@nickfyson nickfyson left a comment

Choose a reason for hiding this comment

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

Given the additional explanation I'm happy with these changes, and can appreciate the value of setting the global permissions also.

@knqyf263 As one of the tool maintainers, are you happy with these changes? If so I shall :shipit: 🙂

Copy link
Contributor

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

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

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-scanning Related to workflows that show on the Code Scanning setup page
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants