Skip to content

Commit d1bf08b

Browse files
jfagoagasandoniaf
andauthored
feat(security): improve GHA security (#43)
Co-authored-by: Andoni A. <14891798+andoniaf@users.noreply.github.com>
1 parent 04ca76b commit d1bf08b

File tree

7 files changed

+93
-15
lines changed

7 files changed

+93
-15
lines changed

.github/workflows/conventional-commit.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ on:
99
- 'edited'
1010
- 'synchronize'
1111

12+
permissions: {}
13+
1214
concurrency:
1315
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
1416
cancel-in-progress: true
1517

1618
jobs:
1719
conventional-commit-check:
20+
name: Check conventional commit
1821
runs-on: ubuntu-latest
1922
timeout-minutes: 15
2023
permissions:
21-
contents: read
2224
pull-requests: read
2325

2426
steps:

.github/workflows/find-secrets.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ on:
88
branches:
99
- 'main'
1010

11+
permissions: {}
12+
1113
concurrency:
1214
group: ${{ github.workflow }}-${{ github.ref }}
1315
cancel-in-progress: true
1416

1517
jobs:
1618
scan-secrets:
19+
name: Scan for secrets
1720
runs-on: ubuntu-latest
1821
timeout-minutes: 15
1922
permissions:

.github/workflows/pr-conflict-checker.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ on:
1010
branches:
1111
- 'main'
1212

13+
permissions: {}
14+
1315
concurrency:
1416
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
1517
cancel-in-progress: true
1618

1719
jobs:
1820
check-conflicts:
21+
name: Check for conflict markers
1922
runs-on: ubuntu-latest
2023
timeout-minutes: 15
2124
permissions:
@@ -76,15 +79,16 @@ jobs:
7679
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7780
PR_NUMBER: ${{ github.event.pull_request.number }}
7881
HAS_CONFLICTS: ${{ steps.conflict-check.outputs.has_conflicts }}
82+
REPO: ${{ github.repository }}
7983
run: |
8084
LABEL_NAME="has-conflicts"
8185
8286
if [ "$HAS_CONFLICTS" = "true" ]; then
8387
echo "Adding conflict label to PR #${PR_NUMBER}..."
84-
gh pr edit "$PR_NUMBER" --add-label "$LABEL_NAME" --repo ${{ github.repository }} || true
88+
gh pr edit "$PR_NUMBER" --add-label "$LABEL_NAME" --repo "$REPO" || true
8589
else
8690
echo "Removing conflict label from PR #${PR_NUMBER}..."
87-
gh pr edit "$PR_NUMBER" --remove-label "$LABEL_NAME" --repo ${{ github.repository }} || true
91+
gh pr edit "$PR_NUMBER" --remove-label "$LABEL_NAME" --repo "$REPO" || true
8892
fi
8993
9094
- name: Find existing comment
@@ -95,7 +99,8 @@ jobs:
9599
comment-author: 'github-actions[bot]'
96100
body-includes: '<!-- conflict-checker-comment -->'
97101

98-
- name: Create or update comment
102+
103+
- name: Create or update comment # zizmor: ignore[superfluous-actions]
99104
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0
100105
with:
101106
comment-id: ${{ steps.find-comment.outputs.comment-id }}

.github/workflows/pull-request.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ on:
88
branches:
99
- "main"
1010

11+
permissions: {}
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
1117
jobs:
1218
build:
19+
name: Lint and test (Python ${{ matrix.python-version }})
1320
runs-on: ubuntu-latest
1421
strategy:
1522
matrix:
@@ -68,5 +75,5 @@ jobs:
6875
- name: Upload coverage reports to Codecov
6976
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
7077
with:
71-
token: ${{ secrets.CODECOV_TOKEN }}
78+
token: ${{ secrets.CODECOV_TOKEN }} # zizmor: ignore[secrets-outside-env]
7279
slug: prowler-cloud/py-pwsh-session

.github/workflows/pypi-release.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
name: PyPI release
2-
permissions:
3-
contents: read
4-
id-token: write
52

63
on:
74
release:
85
types: [published]
96

7+
permissions: {}
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: false
12+
1013
env:
11-
RELEASE_TAG: ${{ github.event.release.tag_name }}
1214
PYTHON_VERSION: 3.11
13-
# CACHE: "poetry"
1415

1516
jobs:
1617
release:
1718
runs-on: ubuntu-latest
19+
environment: release
20+
permissions:
21+
contents: read
22+
id-token: write
1823

1924
name: Release py-pwsh-session to PyPI
2025
steps:
21-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
26+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2227
with:
2328
persist-credentials: false
2429

@@ -27,15 +32,13 @@ jobs:
2732
pipx install poetry==2.1.1
2833
2934
- name: Setup Python
30-
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
35+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
3136
with:
3237
python-version: ${{ env.PYTHON_VERSION }}
33-
# cache: ${{ env.CACHE }}
3438

3539
- name: Build package
3640
run: |
3741
poetry build
3842
3943
- name: Publish package to PyPI
40-
run: |
41-
POETRY_PYPI_TOKEN_PYPI=${{ secrets.PYPI_API_TOKEN }} poetry publish
44+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0

.github/workflows/zizmor.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: "Tools: Zizmor"
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
paths:
8+
- ".github/workflows/**"
9+
pull_request:
10+
branches:
11+
- "main"
12+
paths:
13+
- ".github/workflows/**"
14+
15+
permissions: {}
16+
17+
jobs:
18+
zizmor-pr:
19+
name: Run zizmor (PR)
20+
if: github.event_name == 'pull_request'
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
actions: read
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
28+
with:
29+
persist-credentials: false
30+
31+
- name: Run zizmor
32+
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2
33+
with:
34+
advanced-security: "false"
35+
annotations: "true"
36+
37+
zizmor-push:
38+
name: Run zizmor (push)
39+
if: github.event_name == 'push'
40+
runs-on: ubuntu-latest
41+
permissions:
42+
security-events: write
43+
contents: read
44+
actions: read
45+
steps:
46+
- name: Checkout repository
47+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
48+
with:
49+
persist-credentials: false
50+
51+
- name: Run zizmor
52+
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ repos:
2121
args: ["--autofix"]
2222
files: pyproject.toml
2323

24+
## GITHUB ACTIONS
25+
- repo: https://github.com/zizmorcore/zizmor-pre-commit
26+
rev: v1.23.1
27+
hooks:
28+
- id: zizmor
29+
2430
## PYTHON
2531
- repo: https://github.com/myint/autoflake
2632
rev: v2.3.1

0 commit comments

Comments
 (0)