Skip to content

Commit 716b4ea

Browse files
myasnikovdaniillexfrei
authored andcommitted
ci: harden workflow token permissions and pin actions by SHA
Raise the OpenSSF Scorecard Token-Permissions and Pinned-Dependencies checks (both currently 0/10) ahead of CNCF Incubation due diligence: - Declare a top-level read-only default (permissions: contents: read) in every workflow, plus an explicit per-job permissions: block that grants only the writes that job actually needs. Workflows that previously held write scopes at the workflow level (backport, pr-labeler, pr-size, stale) now hold them at job level instead. - Pin every GitHub-owned and third-party action to a full commit SHA with a version comment. scorecard.yml was already pinned in #2721. No triggers, job graph, or step logic change; only token scopes and action refs. Self-hosted release jobs keep the exact write scopes they already declared. Signed-off-by: Myasnikov Daniil <[email protected]> Assisted-By: Claude <[email protected]>
1 parent 8348f96 commit 716b4ea

13 files changed

Lines changed: 119 additions & 64 deletions

‎.github/workflows/auto-release.yaml‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ concurrency:
1111
group: auto-release-${{ github.workflow }}
1212
cancel-in-progress: false
1313

14+
# Top-level token defaults to read-only; jobs request the minimum extra scopes.
15+
permissions:
16+
contents: read
17+
1418
jobs:
1519
auto-release:
1620
name: Auto Patch Release
@@ -22,14 +26,14 @@ jobs:
2226
steps:
2327
- name: Generate GitHub App token
2428
id: app-token
25-
uses: actions/create-github-app-token@v1
29+
uses: actions/create-github-app-token@d72941d797fd3113feb6b93fd0dec494b13a2547 # v1
2630
with:
2731
app-id: ${{ secrets.COZYSTACK_CI_APP_ID }}
2832
private-key: ${{ secrets.COZYSTACK_CI_PRIVATE_KEY }}
2933
owner: cozystack
3034

3135
- name: Checkout code
32-
uses: actions/checkout@v4
36+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
3337
with:
3438
fetch-depth: 0
3539
fetch-tags: true
@@ -44,7 +48,7 @@ jobs:
4448
git config --unset-all http.https://github.com/.extraheader || true
4549
4650
- name: Process release branches
47-
uses: actions/github-script@v7
51+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
4852
env:
4953
APP_TOKEN: ${{ steps.app-token.outputs.token }}
5054
with:

‎.github/workflows/backport.yaml‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ concurrency:
88
group: backport-${{ github.workflow }}-${{ github.event.pull_request.number }}
99
cancel-in-progress: true
1010

11+
# Top-level token defaults to read-only; jobs request the minimum extra scopes.
1112
permissions:
12-
contents: write
13-
pull-requests: write
13+
contents: read
1414

1515
jobs:
1616
# Determine which backports are needed
@@ -24,6 +24,8 @@ jobs:
2424
(github.event.action == 'labeled' && (github.event.label.name == 'backport' || github.event.label.name == 'backport-previous'))
2525
)
2626
runs-on: [self-hosted]
27+
permissions:
28+
contents: read
2729
outputs:
2830
backport_current: ${{ steps.labels.outputs.backport }}
2931
backport_previous: ${{ steps.labels.outputs.backport_previous }}
@@ -32,7 +34,7 @@ jobs:
3234
steps:
3335
- name: Check which labels are present
3436
id: labels
35-
uses: actions/github-script@v7
37+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
3638
with:
3739
script: |
3840
const pr = context.payload.pull_request;
@@ -47,7 +49,7 @@ jobs:
4749
4850
- name: Determine target branches
4951
id: branches
50-
uses: actions/github-script@v7
52+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
5153
with:
5254
script: |
5355
// Get latest release
@@ -94,6 +96,9 @@ jobs:
9496
github.event.pull_request.base.ref == 'main' &&
9597
(needs.prepare.outputs.backport_current == 'true' || needs.prepare.outputs.backport_previous == 'true')
9698
runs-on: [self-hosted]
99+
permissions:
100+
contents: write
101+
pull-requests: write
97102
strategy:
98103
matrix:
99104
backport_type: [current, previous]
@@ -116,13 +121,13 @@ jobs:
116121
# 2. Checkout (required by backport‑action)
117122
- name: Checkout repository
118123
if: steps.target.outcome == 'success'
119-
uses: actions/checkout@v4
124+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
120125

121126
# 3. Create the back‑port pull request
122127
- name: Create back‑port PR
123128
id: backport
124129
if: steps.target.outcome == 'success'
125-
uses: korthout/[email protected]
130+
uses: korthout/backport-action@0193454f0c5947491d348f33a275c119f30eb736 # v3.2.1
126131
with:
127132
github_token: ${{ secrets.GITHUB_TOKEN }}
128133
label_pattern: '' # don't read labels for targets

‎.github/workflows/codegen-drift.yml‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,22 @@ concurrency:
2323
group: codegen-drift-${{ github.workflow }}-${{ github.event.pull_request.number }}
2424
cancel-in-progress: true
2525

26+
# Top-level token defaults to read-only; jobs request the minimum extra scopes.
27+
permissions:
28+
contents: read
29+
2630
jobs:
2731
codegen-drift:
2832
name: Verify generated code is up to date
2933
runs-on: ubuntu-22.04
34+
permissions:
35+
contents: read
3036
steps:
3137
- name: Checkout code
32-
uses: actions/checkout@v4
38+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
3339

3440
- name: Set up Go
35-
uses: actions/setup-go@v5
41+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
3642
with:
3743
go-version-file: go.mod
3844
cache: true

‎.github/workflows/labels.yaml‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ concurrency:
2424
jobs:
2525
validate:
2626
runs-on: ubuntu-latest
27+
permissions:
28+
contents: read
2729
steps:
28-
- uses: actions/checkout@v4
30+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
2931

3032
- name: Validate labels.yml schema
3133
run: |
@@ -74,11 +76,12 @@ jobs:
7476
if: github.event_name != 'pull_request'
7577
runs-on: ubuntu-latest
7678
permissions:
79+
contents: read
7780
issues: write
7881
pull-requests: write
7982
steps:
80-
- uses: actions/checkout@v4
81-
- uses: EndBug/label-sync@v2
83+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
84+
- uses: EndBug/label-sync@52074158190acb45f3077f9099fea818aa43f97a # v2
8285
with:
8386
config-file: .github/labels.yml
8487
delete-other-labels: false

‎.github/workflows/pr-labeler.yaml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ on:
44
pull_request_target:
55
types: [opened, edited, reopened, synchronize]
66

7+
# Top-level token defaults to read-only; jobs request the minimum extra scopes.
78
permissions:
89
contents: read
9-
pull-requests: write
1010

1111
jobs:
1212
label:
1313
runs-on: ubuntu-latest
14+
permissions:
15+
pull-requests: write
1416
steps:
1517
- name: Apply labels from PR title
16-
uses: actions/github-script@v7
18+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
1719
with:
1820
script: |
1921
// Conventional Commits types accepted by Cozystack (per docs/agents/contributing.md):

‎.github/workflows/pr-size.yaml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ on:
44
pull_request_target:
55
types: [opened, synchronize, reopened]
66

7+
# Top-level token defaults to read-only; jobs request the minimum extra scopes.
78
permissions:
89
contents: read
9-
pull-requests: write
1010

1111
concurrency:
1212
group: pr-size-${{ github.event.pull_request.number }}
@@ -15,8 +15,10 @@ concurrency:
1515
jobs:
1616
size:
1717
runs-on: ubuntu-latest
18+
permissions:
19+
pull-requests: write
1820
steps:
19-
- uses: actions/github-script@v7
21+
- uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
2022
with:
2123
script: |
2224
const pr = context.payload.pull_request;

‎.github/workflows/pre-commit.yml‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,32 @@ concurrency:
88
group: pre-commit-${{ github.workflow }}-${{ github.event.pull_request.number }}
99
cancel-in-progress: true
1010

11+
# Top-level token defaults to read-only; jobs request the minimum extra scopes.
12+
permissions:
13+
contents: read
14+
1115
jobs:
1216
pre-commit:
1317
runs-on: ubuntu-22.04
18+
permissions:
19+
contents: read
1420
steps:
1521
- name: Checkout code
16-
uses: actions/checkout@v3
22+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
1723
with:
1824
fetch-depth: 0
1925
fetch-tags: true
2026

2127
- name: Set up Python
22-
uses: actions/setup-python@v4
28+
uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4
2329
with:
2430
python-version: '3.11'
2531

2632
- name: Install pre-commit
2733
run: pip install pre-commit
2834

2935
- name: Set up Go
30-
uses: actions/setup-go@v5
36+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
3137
with:
3238
go-version-file: go.mod
3339
cache: true

‎.github/workflows/pull-requests-release.yaml‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ concurrency:
1111
group: pr-${{ github.workflow }}-${{ github.event.pull_request.number }}
1212
cancel-in-progress: true
1313

14+
# Top-level token defaults to read-only; jobs request the minimum extra scopes.
15+
permissions:
16+
contents: read
17+
1418
jobs:
1519
finalize:
1620
name: Finalize Release
@@ -25,7 +29,7 @@ jobs:
2529
steps:
2630
- name: Generate GitHub App token
2731
id: app-token
28-
uses: actions/create-github-app-token@v1
32+
uses: actions/create-github-app-token@d72941d797fd3113feb6b93fd0dec494b13a2547 # v1
2933
with:
3034
app-id: ${{ secrets.COZYSTACK_CI_APP_ID }}
3135
private-key: ${{ secrets.COZYSTACK_CI_PRIVATE_KEY }}
@@ -34,7 +38,7 @@ jobs:
3438
# Extract tag from branch name (branch = release-X.Y.Z*)
3539
- name: Extract tag from branch name
3640
id: get_tag
37-
uses: actions/github-script@v7
41+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
3842
with:
3943
script: |
4044
const branch = context.payload.pull_request.head.ref;
@@ -49,7 +53,7 @@ jobs:
4953
5054
# Checkout repo & create / push annotated tag
5155
- name: Checkout repo
52-
uses: actions/checkout@v4
56+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
5357
with:
5458
fetch-depth: 0
5559

@@ -65,7 +69,7 @@ jobs:
6569
6670
# Ensure maintenance branch release-X.Y
6771
- name: Ensure maintenance branch release-X.Y
68-
uses: actions/github-script@v7
72+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
6973
with:
7074
github-token: ${{ steps.app-token.outputs.token }}
7175
script: |
@@ -120,7 +124,7 @@ jobs:
120124
121125
# Publish draft release and ensure correct latest flag
122126
- name: Publish draft release
123-
uses: actions/github-script@v7
127+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
124128
with:
125129
github-token: ${{ steps.app-token.outputs.token }}
126130
script: |

0 commit comments

Comments
 (0)