Skip to content

Commit a37499a

Browse files
committed
Auto merge of #101332 - sashashura:patch-1, r=pietroalbini
GitHub Workflows security hardening This PR adds explicit [permissions section](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions) to workflows. This is a security best practice because by default workflows run with [extended set of permissions](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token) (except from `on: pull_request` [from external forks](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/)). 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](https://securitylab.github.com/research/github-actions-untrusted-input/) or compromised third party tool or action) is restricted. It is recommended to have [most strict permissions on the top level](https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions) and grant write permissions on [job level](https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs) case by case.
2 parents 4af79cc + bd5aad3 commit a37499a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

.github/workflows/ci.yml

+8
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ name: CI
2525
pull_request:
2626
branches:
2727
- "**"
28+
permissions:
29+
contents: read
2830
defaults:
2931
run:
3032
shell: bash
3133
jobs:
3234
pr:
35+
permissions:
36+
actions: write
3337
name: PR
3438
env:
3539
CI_JOB_NAME: "${{ matrix.name }}"
@@ -142,6 +146,8 @@ jobs:
142146
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}"
143147
if: "success() && !env.SKIP_JOB && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')"
144148
auto:
149+
permissions:
150+
actions: write
145151
name: auto
146152
env:
147153
CI_JOB_NAME: "${{ matrix.name }}"
@@ -547,6 +553,8 @@ jobs:
547553
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}"
548554
if: "success() && !env.SKIP_JOB && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')"
549555
try:
556+
permissions:
557+
actions: write
550558
name: try
551559
env:
552560
CI_JOB_NAME: "${{ matrix.name }}"

src/ci/github-actions/ci.yml

+9
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ on:
264264
branches:
265265
- "**"
266266

267+
permissions:
268+
contents: read
269+
267270
defaults:
268271
run:
269272
# On Linux, macOS, and Windows, use the system-provided bash as the default
@@ -273,6 +276,8 @@ defaults:
273276

274277
jobs:
275278
pr:
279+
permissions:
280+
actions: write # for rust-lang/simpleinfra/github-actions/cancel-outdated-builds
276281
<<: *base-ci-job
277282
name: PR
278283
env:
@@ -293,6 +298,8 @@ jobs:
293298
<<: *job-linux-xl
294299

295300
auto:
301+
permissions:
302+
actions: write # for rust-lang/simpleinfra/github-actions/cancel-outdated-builds
296303
<<: *base-ci-job
297304
name: auto
298305
env:
@@ -719,6 +726,8 @@ jobs:
719726
<<: *job-windows-xl
720727

721728
try:
729+
permissions:
730+
actions: write # for rust-lang/simpleinfra/github-actions/cancel-outdated-builds
722731
<<: *base-ci-job
723732
name: try
724733
env:

0 commit comments

Comments
 (0)