Skip to content

Commit 32baefd

Browse files
puercoWojciechMazur
authored andcommitted
Least privilege permissions (#26700)
This commit updates all the repository workflows to drop all privileges (or to a bare minimum) and only enables additional capabilities for the token when required, following the least privilege principle. Fixes #26686 No - [x] Covered by existing tests (this is a refactoring) I've run a test release run (the testable parts at least) here, https://github.com/puerco/scala3/actions/runs/30780742171 Signed-off-by: Adolfo García Veytia (Puerco) <puerco@carabiner.dev>
1 parent a1b0e9c commit 32baefd

16 files changed

Lines changed: 65 additions & 4 deletions

.github/workflows/build-chocolatey.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ on:
2323
required: true
2424
type : string
2525

26+
permissions:
27+
contents: read
28+
2629
jobs:
2730
build:
2831
runs-on: windows-latest

.github/workflows/build-msi.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ on:
1717
description: 'The developed Scala version (major.minor.patch) extracted from project/Build.scala'
1818
value: ${{ jobs.build.outputs.version }}
1919

20+
permissions:
21+
contents: read
22+
2023
env:
2124
# Release only happends when triggering CI by pushing tag
2225
RELEASEBUILD: ${{ startsWith(github.event.ref, 'refs/tags/') && 'yes' || 'no' }}

.github/workflows/build-sdk.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ on:
4040
description: The SHA256 of the uploaded artifact (`win x86-64`)
4141
value : ${{ jobs.build.outputs.win-x86_64-digest }}
4242

43+
permissions:
44+
contents: read
45+
actions: read # To read back the win-x86_64 artifact through the Actions API
4346

4447
jobs:
4548
build:

.github/workflows/ci.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ on:
2424
merge_group:
2525
workflow_dispatch:
2626

27+
# Default token permissions for all jobs: read-only. Jobs that need more must
28+
# declare their own permissions block.
29+
permissions:
30+
contents: read
31+
2732
# Cancels any in-progress runs within the same group identified by workflow name and GH reference (branch or tag)
2833
# For example it would:
2934
# - terminate previous PR CI execution after pushing more changes to the same PR branch
@@ -245,6 +250,9 @@ jobs:
245250

246251
build-sdk-package:
247252
uses: ./.github/workflows/build-sdk.yml
253+
permissions:
254+
contents: read
255+
actions: read # to read back the win-x86_64 artifact through the Actions API
248256
if:
249257
(github.event_name == 'pull_request' && !contains(github.event.pull_request.body, '[skip ci]')) ||
250258
(github.event_name == 'workflow_dispatch' && github.repository == 'scala/scala3') ||
@@ -264,6 +272,8 @@ jobs:
264272

265273
test-chocolatey-package:
266274
uses: ./.github/workflows/test-chocolatey.yml
275+
permissions:
276+
actions: read # downloads the launcher artifact through the Actions API
267277
with:
268278
version : 3.6.0-SNAPSHOT # Fake version, used only for choco tests
269279
java-version: 17

.github/workflows/dependency-graph.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ on:
33
push:
44
branches:
55
- main # default branch of the project
6+
7+
permissions:
8+
contents: write # To submit the dependency graph (in sbt-dependency-submission)
9+
610
jobs:
711
dependency-graph:
812
name: Update Dependency Graph

.github/workflows/language-reference.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ permissions:
1515
jobs:
1616
build-and-push:
1717
name: Build reference documentation and push it
18-
permissions:
19-
contents: write # for Git to git push
2018
runs-on: ubuntu-latest
2119
steps:
2220
- name: Get current date

.github/workflows/lts-backport.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ on:
55
branches:
66
- main
77

8+
# The backporting project is updated via the API with a GitHub App token, the
9+
# workflow GITHUB_TOKEN is only used to check out the repository.
10+
permissions:
11+
contents: read
12+
813
jobs:
914
add-to-backporting-project:
1015
if: "!contains(github.event.push.head_commit.message, '[Next only]') &&

.github/workflows/publish-chocolatey.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ on:
2626
API-KEY:
2727
required: true
2828

29+
# Pushes to Chocolatey with an API key, no GITHUB_TOKEN use
30+
permissions: {}
31+
2932
jobs:
3033
publish:
3134
runs-on: windows-latest

.github/workflows/publish-sdkman.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ on:
2626
CONSUMER-TOKEN:
2727
required: true
2828

29+
# Publishes to SDKMAN! with vendor credentials no GITHUB_TOKEN use
30+
permissions: {}
31+
2932
env:
3033
RELEASE-URL: 'https://github.com/scala/scala3/releases/download/${{ inputs.version }}'
3134

.github/workflows/release-maven-artifacts.yml

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

10+
permissions:
11+
contents: read
12+
1013
jobs:
1114
release-maven-artifacts:
1215
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)