Skip to content

Commit dc3084a

Browse files
committed
Auto merge of #2938 - sashashura:patch-2, r=JohnTitor
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 a4c1846 + af330ad commit dc3084a

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

.github/workflows/bors.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ on:
66
- auto-libc
77
- try
88

9+
permissions: {}
910
jobs:
1011
docker_linux_tier1:
12+
permissions:
13+
actions: write # to cancel workflows (rust-lang/simpleinfra/github-actions/cancel-outdated-builds)
14+
contents: read # to fetch code (actions/checkout)
15+
1116
name: Docker Linux Tier1
1217
runs-on: ubuntu-22.04
1318
strategy:
@@ -28,6 +33,10 @@ jobs:
2833
run: LIBC_CI=1 sh ./ci/run-docker.sh ${{ matrix.target }}
2934

3035
macos:
36+
permissions:
37+
actions: write # to cancel workflows (rust-lang/simpleinfra/github-actions/cancel-outdated-builds)
38+
contents: read # to fetch code (actions/checkout)
39+
3140
name: macOS
3241
runs-on: macos-12
3342
strategy:
@@ -47,6 +56,10 @@ jobs:
4756
run: LIBC_CI=1 sh ./ci/run.sh ${{ matrix.target }}
4857

4958
windows:
59+
permissions:
60+
actions: write # to cancel workflows (rust-lang/simpleinfra/github-actions/cancel-outdated-builds)
61+
contents: read # to fetch code (actions/checkout)
62+
5063
name: Windows
5164
runs-on: windows-2022
5265
env:
@@ -83,6 +96,10 @@ jobs:
8396
shell: bash
8497

8598
style_check:
99+
permissions:
100+
actions: write # to cancel workflows (rust-lang/simpleinfra/github-actions/cancel-outdated-builds)
101+
contents: read # to fetch code (actions/checkout)
102+
86103
name: Style check
87104
runs-on: ubuntu-22.04
88105
steps:
@@ -96,6 +113,10 @@ jobs:
96113
run: sh ci/style.sh
97114

98115
docker_linux_tier2:
116+
permissions:
117+
actions: write # to cancel workflows (rust-lang/simpleinfra/github-actions/cancel-outdated-builds)
118+
contents: read # to fetch code (actions/checkout)
119+
99120
name: Docker Linux Tier2
100121
needs: [docker_linux_tier1, style_check]
101122
runs-on: ubuntu-22.04
@@ -154,6 +175,10 @@ jobs:
154175
# These targets are tier 3 or otherwise need to have CI build std via -Zbuild-std.
155176
# Because of this, only the nightly compiler can be used on these targets.
156177
docker_linux_build_std:
178+
permissions:
179+
actions: write # to cancel workflows (rust-lang/simpleinfra/github-actions/cancel-outdated-builds)
180+
contents: read # to fetch code (actions/checkout)
181+
157182
if: ${{ false }} # This is currently broken
158183
name: Docker Linux Build-Std Targets
159184
needs: [docker_linux_tier1, style_check]
@@ -177,6 +202,10 @@ jobs:
177202

178203
# devkitpro's pacman needs to be connected from Docker.
179204
docker_switch:
205+
permissions:
206+
actions: write # to cancel workflows (rust-lang/simpleinfra/github-actions/cancel-outdated-builds)
207+
contents: read # to fetch code (actions/checkout)
208+
180209
name: Docker Switch
181210
needs: [docker_linux_tier1, style_check]
182211
runs-on: ubuntu-22.04
@@ -191,6 +220,10 @@ jobs:
191220
run: LIBC_CI=1 sh ./ci/run-docker.sh switch
192221

193222
build_channels_linux:
223+
permissions:
224+
actions: write # to cancel workflows (rust-lang/simpleinfra/github-actions/cancel-outdated-builds)
225+
contents: read # to fetch code (actions/checkout)
226+
194227
name: Build Channels Linux
195228
needs: docker_linux_tier2
196229
runs-on: ubuntu-22.04
@@ -221,6 +254,9 @@ jobs:
221254
run: LIBC_CI=1 TOOLCHAIN=${{ matrix.toolchain }} sh ./ci/build.sh
222255

223256
build_channels_macos:
257+
permissions:
258+
contents: read # to fetch code (actions/checkout)
259+
224260
name: Build Channels macOS
225261
needs: macos
226262
# FIXME: Use macOS 11 for now as CI failed with a linker error on macOS 12 image:
@@ -255,6 +291,9 @@ jobs:
255291
run: LIBC_CI=1 TOOLCHAIN=${{ matrix.toolchain }} sh ./ci/build.sh
256292

257293
build_channels_windows:
294+
permissions:
295+
contents: read # to fetch code (actions/checkout)
296+
258297
name: Build Channels Windows
259298
runs-on: windows-2022
260299
env:
@@ -305,6 +344,10 @@ jobs:
305344
run: sh ci/semver.sh macos
306345

307346
docs:
347+
permissions:
348+
actions: write # to cancel workflows (rust-lang/simpleinfra/github-actions/cancel-outdated-builds)
349+
contents: read # to fetch code (actions/checkout)
350+
308351
name: Generate documentation
309352
runs-on: ubuntu-22.04
310353
needs: docker_linux_tier2

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
branches:
88
- master
99

10+
permissions:
11+
contents: read # to fetch code (actions/checkout)
12+
1013
jobs:
1114
docker_linux_tier1:
1215
name: Docker Linux Tier1

0 commit comments

Comments
 (0)