From 13a194466b760a68a3aa0a68c2d38bc1003af780 Mon Sep 17 00:00:00 2001 From: Naveen <172697+naveensrinivasan@users.noreply.github.com> Date: Wed, 11 May 2022 02:51:15 -0500 Subject: [PATCH] chore: Set permissions for GitHub actions (#2555) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: Set permissions for GitHub actions Restrict the GitHub token permissions only to the required ones; this way, even if the attackers will succeed in compromising your workflow, they won’t be able to do much. - Included permissions for the action. https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs [Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> * Update docs-production-deploy.yml * added `packages: write` permissions this is apparently needed by GH so this repository can push new images. Co-authored-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com> Co-authored-by: Casper --- .github/workflows/default_on_push.yml | 4 ++++ .github/workflows/docs-preview-prepare.yml | 3 +++ .github/workflows/docs-production-deploy.yml | 4 ++++ .github/workflows/handle_stalled.yml | 6 ++++++ .github/workflows/linting.yml | 3 +++ .github/workflows/scheduled_builds.yml | 3 +++ .github/workflows/test_merge_requests.yml | 3 +++ 7 files changed, 26 insertions(+) diff --git a/.github/workflows/default_on_push.yml b/.github/workflows/default_on_push.yml index b390b3cd..5272fc22 100644 --- a/.github/workflows/default_on_push.yml +++ b/.github/workflows/default_on_push.yml @@ -14,6 +14,10 @@ on: tags: - '*.*.*' +permissions: + contents: read + packages: write + jobs: build-and-test-image: runs-on: ubuntu-20.04 diff --git a/.github/workflows/docs-preview-prepare.yml b/.github/workflows/docs-preview-prepare.yml index 975fb72f..003de47d 100644 --- a/.github/workflows/docs-preview-prepare.yml +++ b/.github/workflows/docs-preview-prepare.yml @@ -17,6 +17,9 @@ concurrency: # `pull_request` workflow is unreliable alone: Non-collaborator contributions lack access to secrets for security reasons. # A separate workflow (docs-preview-deploy.yml) handles the deploy after the potentially untrusted code is first run in this workflow. # See: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ +permissions: + contents: read + jobs: prepare-preview: name: 'Build Preview' diff --git a/.github/workflows/docs-production-deploy.yml b/.github/workflows/docs-production-deploy.yml index a1520f04..b32fa049 100644 --- a/.github/workflows/docs-production-deploy.yml +++ b/.github/workflows/docs-production-deploy.yml @@ -23,6 +23,8 @@ env: jobs: deploy: + permissions: + contents: write name: 'Deploy Docs' runs-on: ubuntu-20.04 steps: @@ -68,6 +70,8 @@ jobs: user_email: ${{ env.GIT_EMAIL }} add-version-to-docs: + permissions: + contents: write name: 'Update `versions.json` if necessary' runs-on: ubuntu-20.04 if: startsWith(github.ref, 'refs/tags/') diff --git a/.github/workflows/handle_stalled.yml b/.github/workflows/handle_stalled.yml index 2289a6e2..1972dc0d 100644 --- a/.github/workflows/handle_stalled.yml +++ b/.github/workflows/handle_stalled.yml @@ -4,8 +4,14 @@ on: schedule: - cron: "0 1 * * *" +permissions: + contents: read + jobs: stale: + permissions: + issues: write + pull-requests: write runs-on: ubuntu-20.04 steps: - name: Close stale issues diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index ca5501ef..bacf96b6 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -7,6 +7,9 @@ on: branches: - master +permissions: + contents: read + jobs: lint: runs-on: ubuntu-20.04 diff --git a/.github/workflows/scheduled_builds.yml b/.github/workflows/scheduled_builds.yml index c65aeecf..6f24a3cb 100644 --- a/.github/workflows/scheduled_builds.yml +++ b/.github/workflows/scheduled_builds.yml @@ -4,6 +4,9 @@ on: schedule: - cron: "0 0 * * 5" +permissions: + contents: read + jobs: publish: runs-on: ubuntu-20.04 diff --git a/.github/workflows/test_merge_requests.yml b/.github/workflows/test_merge_requests.yml index ce493c0a..1612ba82 100644 --- a/.github/workflows/test_merge_requests.yml +++ b/.github/workflows/test_merge_requests.yml @@ -11,6 +11,9 @@ on: - 'Dockerfile' - 'setup.sh' +permissions: + contents: read + jobs: build-and-test: runs-on: ubuntu-20.04