Skip to content

Commit 7464877

Browse files
committed
github: restrict workflow permissions
Removes all default permissions, and only adds needed permissions to the workflows that need it. - read contents: allows reading the repository, most workflows need this - write contents: allows to write to the repository. Needed to create releases - write pull-requests: allows to manipulate pull requests. Unfortunately this is needed to comment on PRs - read actions: allows reading the state of actions Signed-off-by: Pau Ruiz Safont <[email protected]>
1 parent 38d1595 commit 7464877

File tree

9 files changed

+75
-5
lines changed

9 files changed

+75
-5
lines changed

.github/workflows/1.249-lcm.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Build and test (1.249-lcm, scheduled)
22

3+
permissions: {}
4+
35
on:
46
schedule:
57
# run every Monday, this refreshes the cache
@@ -9,6 +11,8 @@ jobs:
911
python-test:
1012
name: Python tests
1113
runs-on: ubuntu-20.04
14+
permissions:
15+
contents: read
1216
strategy:
1317
fail-fast: false
1418
matrix:

.github/workflows/docs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Generate and upload docs
22

3+
permissions: {}
4+
35
on:
46
push:
57
branches: master
@@ -8,6 +10,8 @@ jobs:
810
ocaml:
911
name: Docs
1012
runs-on: ubuntu-22.04
13+
permissions:
14+
contents: read
1115
env:
1216
XAPI_VERSION: "v0.0.0-${{ github.sha }}"
1317
STORAGE_DOCDIR: .gh-pages-xapi-storage

.github/workflows/format.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Check format
22

3+
permissions: {}
4+
35
on:
46
pull_request:
57
branches:
@@ -12,6 +14,8 @@ jobs:
1214
ocaml-format:
1315
name: Ocaml files
1416
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
1519

1620
steps:
1721
- name: Checkout code

.github/workflows/generate-and-build-sdks.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Generate and Build SDKs
22

3+
permissions: {}
4+
35
on:
46
workflow_call:
57
inputs:
@@ -11,6 +13,9 @@ jobs:
1113
generate-sdk-sources:
1214
name: Generate SDK sources
1315
runs-on: ubuntu-22.04
16+
permissions:
17+
contents: read
18+
1419
steps:
1520
- name: Checkout code
1621
uses: actions/checkout@v4
@@ -25,7 +30,7 @@ jobs:
2530
run: opam exec -- make sdk
2631

2732
# sdk-ci runs some Go unit tests.
28-
# This setting ensures that SDK date time
33+
# This setting ensures that SDK date time
2934
# tests are run on a machine that
3035
# isn't using UTC
3136
- name: Set Timezone to Tokyo for datetime tests
@@ -77,6 +82,9 @@ jobs:
7782
name: Build C SDK
7883
runs-on: ubuntu-latest
7984
needs: generate-sdk-sources
85+
permissions:
86+
contents: read
87+
8088
steps:
8189
- name: Install dependencies
8290
run: sudo apt-get install libxml2-dev
@@ -103,6 +111,9 @@ jobs:
103111
name: Build Java SDK
104112
runs-on: ubuntu-latest
105113
needs: generate-sdk-sources
114+
permissions:
115+
contents: read
116+
106117
steps:
107118
- name: Install dependencies
108119
run: sudo apt-get install maven
@@ -120,9 +131,9 @@ jobs:
120131
distribution: 'temurin'
121132

122133
# Java Tests are run at compile time.
123-
# This setting ensures that SDK date time
134+
# This setting ensures that SDK date time
124135
# tests are run on a machine that
125-
# isn't using UTC
136+
# isn't using UTC
126137
- name: Set Timezone to Tokyo for datetime tests
127138
run: |
128139
sudo timedatectl set-timezone Asia/Tokyo
@@ -144,6 +155,9 @@ jobs:
144155
name: Build C# SDK
145156
runs-on: windows-2022
146157
needs: generate-sdk-sources
158+
permissions:
159+
contents: read
160+
147161
steps:
148162
- name: Strip 'v' prefix from xapi version
149163
shell: pwsh
@@ -158,7 +172,7 @@ jobs:
158172
# All tests builds and pipelines should
159173
# work on other timezones. This setting ensures that
160174
# SDK date time tests are run on a machine that
161-
# isn't using UTC
175+
# isn't using UTC
162176
- name: Set Timezone to Tokyo for datetime tests
163177
shell: pwsh
164178
run: Set-TimeZone -Id "Tokyo Standard Time"
@@ -192,6 +206,9 @@ jobs:
192206
# PowerShell SDK for PowerShell 5.x needs to run on windows-2019 because
193207
# windows-2022 doesn't contain .NET Framework 4.x dev tools
194208
runs-on: windows-2019
209+
permissions:
210+
contents: read
211+
195212
steps:
196213
- name: Strip 'v' prefix from xapi version
197214
shell: pwsh
@@ -265,6 +282,8 @@ jobs:
265282
dotnet: ["6", "8"]
266283
needs: build-csharp-sdk
267284
runs-on: windows-2022
285+
permissions:
286+
contents: read
268287

269288
steps:
270289
- name: Strip 'v' prefix from xapi version

.github/workflows/hugo.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Generate and upload Hugo docs
22

3+
permissions: {}
4+
35
on:
46
push:
57
branches: master
@@ -8,6 +10,9 @@ jobs:
810
ocaml:
911
name: Docs
1012
runs-on: ubuntu-22.04
13+
permissions:
14+
contents: read
15+
1116

1217
steps:
1318
- name: Checkout code

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Build and test
22

3+
permissions: {}
4+
35
on:
46
# When only Hugo docs change, this workflow is not required:
57
push:
@@ -20,6 +22,8 @@ jobs:
2022
ocaml-tests:
2123
name: Run OCaml tests
2224
runs-on: ubuntu-22.04
25+
permissions:
26+
contents: read
2327
env:
2428
# Ensure you also update test-sdk-builds
2529
# when changing this value, to keep builds

.github/workflows/other.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Build and test (other)
22

3+
permissions: {}
4+
35
on:
46
# When only Hugo docs change, this workflow is not required:
57
push:
@@ -20,6 +22,9 @@ jobs:
2022
python-test:
2123
name: Python tests
2224
runs-on: ubuntu-22.04
25+
permissions:
26+
contents: read
27+
2328
strategy:
2429
fail-fast: false
2530
matrix:
@@ -59,6 +64,8 @@ jobs:
5964
fail-on-error: false
6065

6166
- uses: dciborow/[email protected]
67+
permissions:
68+
pull-requests: write # allow commenting on the PR
6269
with:
6370
reporter: github-pr-review
6471
level: warning
@@ -68,13 +75,17 @@ jobs:
6875

6976
- name: Run pytype checks
7077
run: pip install pandas pytype toml && ./pytype_reporter.py
78+
permissions:
79+
pull-requests: write # allow commenting on the PR
7180
env:
7281
PR_NUMBER: ${{ github.event.number }}
7382
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7483
PYTYPE_REPORTER_DEBUG: True
7584

7685
- name: pyflakes
7786
uses: reviewdog/action-pyflakes@v1
87+
permissions:
88+
pull-requests: write # allow commenting on the PR
7889
with:
7990
github_token: ${{ secrets.github_token }}
8091
continue-on-error: true
@@ -96,6 +107,8 @@ jobs:
96107
deprecation-test:
97108
name: Deprecation tests
98109
runs-on: ubuntu-22.04
110+
permissions:
111+
contents: read
99112

100113
steps:
101114
- name: Checkout code
@@ -110,6 +123,8 @@ jobs:
110123
test-sdk-builds:
111124
name: Test SDK builds
112125
uses: ./.github/workflows/generate-and-build-sdks.yml
126+
permissions:
127+
contents: read
113128
with:
114129
# Ensure you also update ocaml-tests
115130
# when changing this value, to keep builds

.github/workflows/release.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Create release from tag
22

3+
permissions: {}
4+
35
on:
46
push:
57
tags:
@@ -9,6 +11,8 @@ jobs:
911
build-python:
1012
name: Build and upload Python artifacts
1113
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
1216

1317
steps:
1418
- name: Checkout code
@@ -36,10 +40,15 @@ jobs:
3640
build-sdks:
3741
name: Build and upload SDK artifacts
3842
uses: ./.github/workflows/generate-and-build-sdks.yml
43+
permissions:
44+
contents: read
3945
with:
4046
xapi_version: ${{ github.ref_name }}
4147

4248
release:
49+
permissions:
50+
contents: write # allow creating a release
51+
4352
name: "Create and package release"
4453
runs-on: ubuntu-latest
4554
needs: [build-python, build-sdks]
@@ -124,6 +133,7 @@ jobs:
124133
needs: release
125134
environment: pypi
126135
permissions:
136+
contents: read
127137
id-token: write
128138
steps:
129139
- name: Retrieve python distribution artifacts

.github/workflows/shellcheck.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: ShellCheck
22

3+
permissions: {}
4+
35
on:
46
pull_request:
57
merge_group:
@@ -16,8 +18,11 @@ jobs:
1618
runs-on: ubuntu-latest
1719

1820
permissions:
21+
actions: read
22+
contents: read
23+
pull-requests: write # allow commenting on the PR
1924
security-events: write
20-
25+
2126
steps:
2227
- name: Checkout code
2328
uses: actions/checkout@v4

0 commit comments

Comments
 (0)