Skip to content

Commit c07abd9

Browse files
chore: Set permissions for GitHub actions
Restrict the GitHub token permissions only to the required ones; this way, even if the attackers will succeed in compromising your workflow, they won’t be able to do much. - Included permissions for the action. https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs [Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) Signed-off-by: naveen <[email protected]>
1 parent 2922473 commit c07abd9

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Cancel duplicate workflows
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI", "CodeQL"]
6+
types:
7+
- requested
8+
9+
# Note: This has to be in workflow_run so it works for PRs from forks.
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
cancel:
15+
permissions:
16+
actions: write # for styfle/cancel-workflow-action to cancel/stop running workflows
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Cancel previous runs
20+
uses: styfle/cancel-workflow-action@3d86a7cc43670094ac248017207be0295edbc31d # 0.8.0
21+
with:
22+
workflow_id: ${{ github.event.workflow.id }}

.github/workflows/ci_crontests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
# run every Monday at 5am UTC
1010
- cron: '0 5 * * 1'
1111

12+
permissions:
13+
contents: read
14+
1215
jobs:
1316
tests:
1417
name: ${{ matrix.name }}

.github/workflows/ci_devtests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ concurrency:
1818
group: ${{ github.workflow }}-${{ github.ref }}
1919
cancel-in-progress: true
2020

21+
permissions:
22+
contents: read
23+
2124
jobs:
2225
tests:
2326
name: ${{ matrix.name }}

.github/workflows/ci_tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ concurrency:
1818
group: ${{ github.workflow }}-${{ github.ref }}
1919
cancel-in-progress: true
2020

21+
permissions:
22+
contents: read
2123

2224
jobs:
2325
tests:

.github/workflows/codeql-analysis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ concurrency:
1111
group: ${{ github.workflow }}-${{ github.ref }}
1212
cancel-in-progress: true
1313

14+
permissions:
15+
contents: read
16+
1417
jobs:
1518
analyze:
19+
permissions:
20+
actions: read # for github/codeql-action/init to get workflow details
21+
contents: read # for actions/checkout to fetch code
22+
security-events: write # for github/codeql-action/autobuild to send a status report
1623
name: Analyze
1724
runs-on: ubuntu-latest
1825

0 commit comments

Comments
 (0)