Skip to content

GitHub Workflows security hardening #101332

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 5 commits into from
Sep 18, 2022
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
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ name: CI
pull_request:
branches:
- "**"
permissions:
contents: read
defaults:
run:
shell: bash
jobs:
pr:
permissions:
actions: write
name: PR
env:
CI_JOB_NAME: "${{ matrix.name }}"
Expand Down Expand Up @@ -142,6 +146,8 @@ jobs:
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}"
if: "success() && !env.SKIP_JOB && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')"
auto:
permissions:
actions: write
name: auto
env:
CI_JOB_NAME: "${{ matrix.name }}"
Expand Down Expand Up @@ -547,6 +553,8 @@ jobs:
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}"
if: "success() && !env.SKIP_JOB && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')"
try:
permissions:
actions: write
name: try
env:
CI_JOB_NAME: "${{ matrix.name }}"
Expand Down
9 changes: 9 additions & 0 deletions src/ci/github-actions/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ on:
branches:
- "**"

permissions:
contents: read
Comment on lines +267 to +268
Copy link
Member

Choose a reason for hiding this comment

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

There is an action that uses the actions: write permission in our workflow:

- name: configure GitHub Actions to kill the build when outdated
uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
with:
github_token: "${{ secrets.github_token }}"
if: success() && !env.SKIP_JOB && github.ref != 'refs/heads/try' && github.ref != 'refs/heads/try-perf'
<<: *step

That whole action can probably be replaced with the concurrency key though (we created the action before concurrency was introduced).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, I missed that. To keep one issue per pull request, I only added the permission for now.


defaults:
run:
# On Linux, macOS, and Windows, use the system-provided bash as the default
Expand All @@ -273,6 +276,8 @@ defaults:

jobs:
pr:
permissions:
actions: write # for rust-lang/simpleinfra/github-actions/cancel-outdated-builds
<<: *base-ci-job
name: PR
env:
Expand All @@ -293,6 +298,8 @@ jobs:
<<: *job-linux-xl

auto:
permissions:
actions: write # for rust-lang/simpleinfra/github-actions/cancel-outdated-builds
<<: *base-ci-job
name: auto
env:
Expand Down Expand Up @@ -719,6 +726,8 @@ jobs:
<<: *job-windows-xl

try:
permissions:
actions: write # for rust-lang/simpleinfra/github-actions/cancel-outdated-builds
<<: *base-ci-job
name: try
env:
Expand Down