Skip to content

Commit

Permalink
Merge pull request #4311 from sashashura/patch-1
Browse files Browse the repository at this point in the history
GitHub Workflows security hardening
This PR adds explicit permissions section to workflows. 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.
It is recommended to have most strict permissions on the top level and grant write permissions on job level case by case.
  • Loading branch information
jedwards4b authored Oct 14, 2022
2 parents 60b3065 + 191ba7c commit a40f9e1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/bumpversion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ on:
push:
branches:
- master
permissions: {}
jobs:
build:
permissions:
contents: write # to create a tag (mathieudutour/github-tag-action)

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
branches:
- master

permissions:
contents: read
jobs:
check-changes:
name: Check for changes to documentation
Expand All @@ -25,6 +27,9 @@ jobs:
with:
files: doc
build-and-deploy:
permissions:
contents: write # for peaceiris/actions-gh-pages to push
pull-requests: write # to comment on pull requests
needs: check-changes
if: needs.check-changes.outputs.any_changed == 'true'
name: Build and deploy documentation
Expand Down Expand Up @@ -93,6 +98,8 @@ jobs:
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
cleanup:
permissions:
contents: write # for git push
needs: build-and-deploy
name: Cleanup branch previews
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
pre-commit:
runs-on: ubuntu-latest
Expand Down

0 comments on commit a40f9e1

Please sign in to comment.