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

GitHub Workflows security hardening #1162

Merged
merged 1 commit into from
Dec 12, 2022
Merged

Conversation

sashashura
Copy link
Contributor

What:
This PR adds explicit permissions section to workflows.

Why:
This is a security best practice because by default workflows run with extended set of permissions (except from on: pull_request from external forks). By specifying any permission explicitly all others are set to none. By using the principle of least privilege the damage a compromised workflow can do (because of an injection or compromised third party tool or action) is restricted.

How:
It is recommended to have most strict permissions on the top level and grant write permissions on job level case by case.

Checklist:

  • Documentation added to the
    docs site N/A
  • Tests N/A
  • TypeScript definitions updated N/A
  • Ready to be merged

Signed-off-by: Alex <aleksandrosansan@gmail.com>
@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 8, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 8e1855e:

Sandbox Source
React Configuration
react-testing-library-examples Configuration

@codecov
Copy link

codecov bot commented Dec 8, 2022

Codecov Report

Merging #1162 (8e1855e) into main (801ad37) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##              main     #1162   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines          181       181           
  Branches        36        36           
=========================================
  Hits           181       181           
Flag Coverage Δ
experimental 100.00% <ø> (ø)
latest 100.00% <ø> (ø)
next 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -12,6 +12,10 @@ on:
- 'alpha'
- '!all-contributors/**'
pull_request: {}
permissions:
actions: write # to cancel/stop running workflows (styfle/cancel-workflow-action)
Copy link
Member

Choose a reason for hiding this comment

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

Could you include a summary of the permissions before and after for each change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before the change for all jobs (as seen here https://github.com/testing-library/react-testing-library/actions/runs/3633193928/jobs/6129924592):

GITHUB_TOKEN Permissions
  Actions: write
  Checks: write
  Contents: write
  Deployments: write
  Discussions: write
  Issues: write
  Metadata: read
  Packages: write
  Pages: write
  PullRequests: write
  RepositoryProjects: write
  SecurityEvents: write
  Statuses: write

After the change
For the release job (not mention permissions are none):

GITHUB_TOKEN Permissions
  Actions: write
  Contents: write
  Metadata: read

For all others:

GITHUB_TOKEN Permissions
  Actions: write
  Contents: read
  Metadata: read

Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

Sweet, thanks!

@eps1lon eps1lon merged commit c43512a into testing-library:main Dec 12, 2022
@eps1lon
Copy link
Member

eps1lon commented Feb 16, 2023

This was missing issues: write for semantic-release. Fixing in #1176

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants