Skip to content

Commit d8e3946

Browse files
committed
template: Tighten permissions
Request only for the permissions we need to use. In particular, explicitly request no permissions when none are needed, as the default gives at least contents write permission. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent 35753b0 commit d8e3946

30 files changed

Lines changed: 174 additions & 0 deletions

File tree

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/auto-dependabot.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ jobs:
3232
with:
3333
app-id: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_ID }}
3434
private-key: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_PRIVATE_KEY }}
35+
# Merge Dependabot PRs.
36+
permission-contents: write
37+
# Create the auto-merged label if it does not exist.
38+
permission-issues: write
39+
# Approve PRs, add labels, and enable auto-merge.
40+
permission-pull-requests: write
3541

3642
- name: Auto-merge Dependabot PR
3743
uses: frequenz-floss/dependabot-auto-approve@e943399cc9d76fbb6d7faae446cd57301d110165 # v1.5.0

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/ci-pr.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ name: Test PR
44
on:
55
pull_request:
66

7+
permissions:
8+
# Read repository contents for checkout and dependency resolution only.
9+
contents: read
10+
711
env:
812
# Please make sure this version is included in the `matrix`, as the
913
# `matrix` section can't use `env`, so it must be entered manually

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/ci.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ on:
1616
- 'dependabot/**'
1717
workflow_dispatch:
1818

19+
permissions:
20+
# Read repository contents for checkout and dependency resolution only.
21+
contents: read
22+
1923
env:
2024
# Please make sure this version is included in the `matrix`, as the
2125
# `matrix` section can't use `env`, so it must be entered manually
@@ -95,6 +99,8 @@ jobs:
9599
# We skip this job only if nox was also skipped
96100
if: always() && needs.nox.result != 'skipped'
97101
runs-on: ubuntu-slim
102+
# Drop token permissions: this job only checks matrix status from `needs`.
103+
permissions: {}
98104
env:
99105
DEPS_RESULT: ${{ needs.nox.result }}
100106
steps:
@@ -202,6 +208,8 @@ jobs:
202208
# We skip this job only if test-installation was also skipped
203209
if: always() && needs.test-installation.result != 'skipped'
204210
runs-on: ubuntu-slim
211+
# Drop token permissions: this job only checks matrix status from `needs`.
212+
permissions: {}
205213
env:
206214
DEPS_RESULT: ${{ needs.test-installation.result }}
207215
steps:

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/dco-merge-queue.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ name: DCO
44
on:
55
merge_group:
66

7+
# Drop all token permissions: this workflow only runs a local echo command.
8+
permissions: {}
9+
710
jobs:
811
DCO:
912
runs-on: ubuntu-slim

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/repo-config-migration.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ jobs:
5050
with:
5151
app-id: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_ID }}
5252
private-key: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_PRIVATE_KEY }}
53+
# Push migration commits to the PR branch.
54+
permission-contents: write
55+
# Manage labels when auto-merging patch-only updates.
56+
permission-issues: write
57+
# Approve pull requests and enable auto-merge.
58+
permission-pull-requests: write
59+
# Allow pushes when migration changes workflow files.
60+
permission-workflows: write
5361
- name: Migrate
5462
uses: frequenz-floss/gh-action-dependabot-migrate@07dc7e74726498c50726a80cc2167a04d896508f # v1.0.0
5563
with:

tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/.github/workflows/auto-dependabot.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ jobs:
3131
with:
3232
app-id: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_ID }}
3333
private-key: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_PRIVATE_KEY }}
34+
# Merge Dependabot PRs.
35+
permission-contents: write
36+
# Create the auto-merged label if it does not exist.
37+
permission-issues: write
38+
# Approve PRs, add labels, and enable auto-merge.
39+
permission-pull-requests: write
3440

3541
- name: Auto-merge Dependabot PR
3642
uses: frequenz-floss/dependabot-auto-approve@e943399cc9d76fbb6d7faae446cd57301d110165 # v1.5.0

tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/.github/workflows/ci-pr.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Test PR
33
on:
44
pull_request:
55

6+
permissions:
7+
# Read repository contents for checkout and dependency resolution only.
8+
contents: read
9+
610
env:
711
# Please make sure this version is included in the `matrix`, as the
812
# `matrix` section can't use `env`, so it must be entered manually

tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/.github/workflows/ci.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ on:
1515
- 'dependabot/**'
1616
workflow_dispatch:
1717

18+
permissions:
19+
# Read repository contents for checkout and dependency resolution only.
20+
contents: read
21+
1822
env:
1923
# Please make sure this version is included in the `matrix`, as the
2024
# `matrix` section can't use `env`, so it must be entered manually
@@ -62,6 +66,8 @@ jobs:
6266
# We skip this job only if nox was also skipped
6367
if: always() && needs.nox.result != 'skipped'
6468
runs-on: ubuntu-slim
69+
# Drop token permissions: this job only checks matrix status from `needs`.
70+
permissions: {}
6571
env:
6672
DEPS_RESULT: ${{ needs.nox.result }}
6773
steps:
@@ -169,6 +175,8 @@ jobs:
169175
# We skip this job only if test-installation was also skipped
170176
if: always() && needs.test-installation.result != 'skipped'
171177
runs-on: ubuntu-slim
178+
# Drop token permissions: this job only checks matrix status from `needs`.
179+
permissions: {}
172180
env:
173181
DEPS_RESULT: ${{ needs.test-installation.result }}
174182
steps:

tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/.github/workflows/dco-merge-queue.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: DCO
33
on:
44
merge_group:
55

6+
# Drop all token permissions: this workflow only runs a local echo command.
7+
permissions: {}
8+
69
jobs:
710
DCO:
811
runs-on: ubuntu-slim

tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/.github/workflows/repo-config-migration.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ jobs:
4949
with:
5050
app-id: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_ID }}
5151
private-key: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_PRIVATE_KEY }}
52+
# Push migration commits to the PR branch.
53+
permission-contents: write
54+
# Manage labels when auto-merging patch-only updates.
55+
permission-issues: write
56+
# Approve pull requests and enable auto-merge.
57+
permission-pull-requests: write
58+
# Allow pushes when migration changes workflow files.
59+
permission-workflows: write
5260
- name: Migrate
5361
uses: frequenz-floss/gh-action-dependabot-migrate@07dc7e74726498c50726a80cc2167a04d896508f # v1.0.0
5462
with:

0 commit comments

Comments
 (0)