Skip to content

Commit 078325e

Browse files
authored
ci(security): harden CI/CD supply chain with SHA pinning and least-privilege permissions (#650)
- Pin all GitHub Actions to full SHA with version comments - Add top-level permissions: contents: read to test.yml - Add top-level permissions: contents: read to release.yml (write only at job level) - Upgrade pypa/gh-action-pypi-publish from release/v1 tag to v1.14.0 SHA - Add pip ecosystem tracking to dependabot - Add commit-message prefixes and labels to dependabot config
1 parent 3f0e3e0 commit 078325e

3 files changed

Lines changed: 36 additions & 10 deletions

File tree

.github/dependabot.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
1-
# Keep GitHub Actions up to date with GitHub's Dependabot...
21
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
3-
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#package-ecosystem
42
version: 2
53
updates:
4+
# Keep GitHub Actions pinned-by-SHA references up to date. Dependabot
5+
# rewrites the SHA and the trailing `# vX.Y.Z` version comment together.
66
- package-ecosystem: github-actions
77
directory: /
8+
schedule:
9+
interval: weekly
10+
open-pull-requests-limit: 5
11+
commit-message:
12+
prefix: ci
13+
include: scope
814
groups:
915
github-actions:
1016
patterns:
11-
- "*" # Group all Actions updates into a single larger pull request
17+
- "*"
18+
labels:
19+
- dependencies
20+
- github-actions
21+
22+
- package-ecosystem: pip
23+
directory: /
1224
schedule:
1325
interval: weekly
26+
open-pull-requests-limit: 5
27+
commit-message:
28+
prefix: chore
29+
include: scope
30+
labels:
31+
- dependencies
32+
- python

.github/workflows/release.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ on:
44
release:
55
types: [created]
66

7+
# Least-privilege default: jobs are read-only unless they opt into more below.
8+
permissions:
9+
contents: read
10+
711
jobs:
812
publish:
913
runs-on: ubuntu-latest
10-
# Specifying a GitHub environment is optional, but strongly encouraged
1114
environment: release
1215
permissions:
1316
# IMPORTANT: this permission is mandatory for trusted publishing
@@ -16,10 +19,10 @@ jobs:
1619
contents: write
1720

1821
steps:
19-
- uses: actions/checkout@v6
22+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
2023

2124
- name: Set up Python
22-
uses: actions/setup-python@v6
25+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
2326
with:
2427
python-version: "3.x"
2528

@@ -32,7 +35,7 @@ jobs:
3235
run: make sdist
3336

3437
- name: Publish package distributions to PyPI
35-
uses: pypa/gh-action-pypi-publish@release/v1
38+
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
3639

3740
- name: Build Documentation
3841
run: |
@@ -41,7 +44,7 @@ jobs:
4144
mkdocs build
4245
4346
- name: Deploy to GitHub Pages
44-
uses: peaceiris/actions-gh-pages@v4
47+
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4
4548
with:
4649
github_token: ${{ secrets.GITHUB_TOKEN }}
4750
publish_dir: ./site

.github/workflows/test.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
- main
77
pull_request:
88

9+
# Least-privilege default token for every job in this workflow.
10+
permissions:
11+
contents: read
12+
913
concurrency:
1014
group: ${{ github.workflow }}-${{ github.ref }}
1115
cancel-in-progress: true
@@ -31,10 +35,10 @@ jobs:
3135
python-version: "3.14"
3236

3337
steps:
34-
- uses: actions/checkout@v6
38+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
3539

3640
- name: Set up Python ${{ matrix.python-version }}
37-
uses: actions/setup-python@v6
41+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
3842
with:
3943
python-version: ${{ matrix.python-version }}
4044
allow-prereleases: true

0 commit comments

Comments
 (0)