Skip to content

chore: tighten GitHub workflow permissions #15282

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

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
chore: tighten GitHub workflow permissions
Align permissions with OpenSSF scorecard recommendations to enhance
security. Move permissions to specific jobs to grant only what's
necessary.
  • Loading branch information
matifali committed Oct 30, 2024
commit ee25db4e8e48ff9efecd31b00dc0942ae593c035
9 changes: 5 additions & 4 deletions .github/workflows/docker-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ on:

permissions:
contents: read
# Necessary to push docker images to ghcr.io.
packages: write
# Necessary for depot.dev authentication.
id-token: write

# Avoid running multiple jobs for the same commit.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-docker-base

jobs:
build:
permissions:
# Necessary for depot.dev authentication.
id-token: write
# Necessary to push docker images to ghcr.io.
packages: write
runs-on: ubuntu-latest
if: github.repository_owner == 'coder'
steps:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/nightly-gauntlet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
# Every day at midnight
- cron: "0 0 * * *"
workflow_dispatch:

permissions:
contents: read

jobs:
go-race:
# While GitHub's toaster runners are likelier to flake, we want consistency
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pr-cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ on:
description: "PR number"
required: true

permissions:
packages: write

jobs:
cleanup:
runs-on: "ubuntu-latest"
permissions:
# Necessary to delete docker images from ghcr.io.
packages: write
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/pr-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ env:

permissions:
contents: read
packages: write
pull-requests: write # needed for commenting on PRs

jobs:
check_pr:
Expand Down Expand Up @@ -171,6 +169,8 @@ jobs:
needs: get_info
if: needs.get_info.outputs.BUILD == 'true' || github.event.inputs.deploy == 'true'
runs-on: "ubuntu-latest"
permissions:
pull-requests: write # needed for commenting on PRs
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
Expand Down Expand Up @@ -205,6 +205,9 @@ jobs:
# Run build job only if there are changes in the files that we care about or if the workflow is manually triggered with --build flag
if: needs.get_info.outputs.BUILD == 'true'
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
permissions:
# Necessary to push docker images to ghcr.io.
packages: write
# This concurrency only cancels build jobs if a new build is triggred. It will avoid cancelling the current deployemtn in case of docs chnages.
concurrency:
group: build-${{ github.workflow }}-${{ github.ref }}-${{ needs.get_info.outputs.BUILD }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
tags:
- "v*"

permissions:
contents: read

jobs:
network-performance:
runs-on: ubuntu-latest
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ on:
default: false

permissions:
# Required to publish a release
contents: write
# Necessary to push docker images to ghcr.io.
packages: write
# Necessary for GCP authentication (https://github.com/google-github-actions/setup-gcloud#usage)
id-token: write
contents: read

concurrency: ${{ github.workflow }}-${{ github.ref }}

Expand All @@ -40,6 +35,13 @@ jobs:
release:
name: Build and publish
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
permissions:
# Required to publish a release
contents: write
# Necessary to push docker images to ghcr.io.
packages: write
# Necessary for GCP authentication (https://github.com/google-github-actions/setup-gcloud#usage)
id-token: write
env:
# Necessary for Docker manifest
DOCKER_CLI_EXPERIMENTAL: "enabled"
Expand Down
15 changes: 13 additions & 2 deletions .github/workflows/stale.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
name: Stale Issue, Banch and Old Workflows Cleanup
name: Stale Issue, Branch and Old Workflows Cleanup
on:
schedule:
# Every day at midnight
- cron: "0 0 * * *"
workflow_dispatch:

permissions:
contents: read

jobs:
issues:
runs-on: ubuntu-latest
permissions:
# Needed to close issues.
issues: write
# Needed to close PRs.
pull-requests: write
actions: write
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
Expand Down Expand Up @@ -86,6 +91,9 @@ jobs:

branches:
runs-on: ubuntu-latest
permissions:
# Needed to delete branches.
contents: write
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
Expand All @@ -105,6 +113,9 @@ jobs:
exclude_open_pr_branches: true
del_runs:
runs-on: ubuntu-latest
permissions:
# Needed to delete workflow runs.
actions: write
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
Expand Down