Skip to content

Commit a45dae8

Browse files
committed
CI: be explicit about the permissions required for each workflow / job
1 parent dbe9bbb commit a45dae8

8 files changed

Lines changed: 40 additions & 4 deletions

File tree

.github/workflows/actions-linting.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ on:
1111
- main
1212
workflow_dispatch:
1313

14+
permissions:
15+
contents: read
16+
1417
jobs:
1518
action-validator:
1619
runs-on: ubuntu-latest
@@ -60,3 +63,21 @@ jobs:
6063
echo "$unpinned_actions"
6164
exit 1
6265
fi
66+
67+
explicit-permissions:
68+
runs-on: ubuntu-latest
69+
steps:
70+
- name: Checkout
71+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
72+
73+
- name: Find workflows that have jobs that rely on the default permissions
74+
run: |
75+
workflows_with_implicit_permissions=$(
76+
find .github/workflows -type f \( -iname \*.yaml -o -iname \*.yml \) -print0 \
77+
| xargs -0 -I {} yq '{filename: ([.jobs.* | has("permissions")] | all) or (. | has("permissions"))}' {} \
78+
| grep -E 'false$' || true)
79+
if [ "$workflows_with_implicit_permissions" != "" ]; then
80+
echo "There are workflows that have not set permissions either globally or for all jobs:"
81+
echo "$workflows_with_implicit_permissions"
82+
exit 1
83+
fi

.github/workflows/build-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
- main
1111
workflow_dispatch:
1212

13+
permissions:
14+
contents: read
15+
1316
jobs:
1417
# We build from source and commit all generated file changes so that we can see the impact in PRs
1518
# We want to ensure that the commit of built changes does happen, so fail if building creates changes

.github/workflows/changelog_check.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ name: Changelog
66
on:
77
pull_request:
88

9+
permissions:
10+
contents: read
11+
912
jobs:
1013
check-newsfile:
1114
if: ${{ (github.base_ref == 'main' || contains(github.base_ref, 'release-')) && github.actor != 'dependabot[bot]' && github.actor != 'github-actions[bot]' }}

.github/workflows/licensing.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ on:
1111
- main
1212
workflow_dispatch:
1313

14+
permissions:
15+
contents: read
16+
1417
jobs:
1518
reuse-compliance-check:
1619
runs-on: ubuntu-latest

.github/workflows/matrix-tools.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ env:
1717
REGISTRY_IMAGE: ghcr.io/${{ github.repository }}/matrix-tools
1818
GO_VERSION: "1.24"
1919

20-
permissions:
21-
contents: read
22-
packages: read
23-
2420
jobs:
2521
tests:
22+
permissions:
23+
contents: read
24+
packages: read
2625
runs-on: ubuntu-latest
2726
steps:
2827
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

.github/workflows/scripts-linting.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ on:
1111
- main
1212
workflow_dispatch:
1313

14+
permissions:
15+
contents: read
16+
1417
jobs:
1518
shellcheck:
1619
runs-on: ubuntu-latest

.github/workflows/templates-dyff.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ name: dyff of rendered templates
66
on:
77
pull_request:
88

9+
permissions:
10+
contents: read
11+
912
jobs:
1013
generate-dyff:
1114
runs-on: ubuntu-latest

newsfragments/589.internal.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CI: be explicit about what permissions are workflow/job requires

0 commit comments

Comments
 (0)