Skip to content

Commit 85bf2b6

Browse files
committed
Add Zizmor Github actions security policy
1 parent d0c10b9 commit 85bf2b6

13 files changed

Lines changed: 198 additions & 41 deletions

File tree

‎.devcontainer/Dockerfile‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
# See here for image contents: https://github.com/devcontainers/images/tree/main/src
22

3-
ARG VARIANT="3.14-bookworm"
4-
FROM mcr.microsoft.com/vscode/devcontainers/python:${VARIANT}
3+
# Image version 3.3.2, Python 3.14, Debian bookworm. Tag and digest are updated by Dependabot.
4+
FROM mcr.microsoft.com/vscode/devcontainers/python:3.3.2-3.14-bookworm@sha256:94053b777943a4eda40e83d5386f7c5befb72f5bb778878ac527bb9491adcd42
55

66
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
77
ARG NODE_VERSION="none"
88
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
99

1010
# Just Installation
11-
COPY --from=ghcr.io/casey/just:latest /just /usr/local/bin/
11+
COPY --from=ghcr.io/casey/just:1.59.0@sha256:014cbe6e6de678864004e2fd8b0405f77ce43b20b225e816feb330f2fb575c01 /just /usr/local/bin/
1212

1313
# uv Installation
14-
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/
14+
COPY --from=ghcr.io/astral-sh/uv:0.13.7@sha256:96f40d3904aad8d0bd010539001d36c8e2188b981e1334471a90c4a1d93bb490 /uv /uvx /usr/local/bin/
1515

1616
# [Optional] Uncomment this section to install additional OS packages.
1717
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
1818
# && apt-get -y install --no-install-recommends <your-package-list-here>
1919

2020
# [Optional] Uncomment this line to install global node packages.
2121
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
22-

‎.devcontainer/devcontainer.json‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
"dockerfile": "Dockerfile",
77
"context": "..",
88
"args": {
9-
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
10-
// Append -bullseye or -buster to pin to an OS version.
11-
// Use -bullseye variants on local on arm64/Apple Silicon.
12-
"VARIANT": "3.14-bookworm",
9+
// The Python version is pinned in the Dockerfile's FROM line (tag + digest).
1310
// Options
1411
"NODE_VERSION": "none"
1512
}

‎.github/dependabot.yml‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Dependabot configuration.
2+
# See https://docs.github.com/en/code-security/dependabot/working-with-dependabot/dependabot-options-reference
3+
version: 2
4+
5+
updates:
6+
# GitHub Actions used in .github/workflows (updates SHA pins and their version comments)
7+
- package-ecosystem: "github-actions"
8+
directory: "/"
9+
schedule:
10+
interval: "weekly"
11+
cooldown:
12+
default-days: 7
13+
labels: ["dependencies"]
14+
groups:
15+
github-actions:
16+
patterns: ["*"]
17+
18+
# Python dependencies in pyproject.toml / uv.lock
19+
- package-ecosystem: "uv"
20+
directory: "/"
21+
schedule:
22+
interval: "weekly"
23+
cooldown:
24+
default-days: 7
25+
labels: ["dependencies"]
26+
groups:
27+
python-minor-and-patch:
28+
update-types: ["minor", "patch"]
29+
30+
# Base image in .devcontainer/Dockerfile
31+
- package-ecosystem: "docker"
32+
directory: "/.devcontainer"
33+
schedule:
34+
interval: "weekly"
35+
cooldown:
36+
default-days: 7
37+
labels: ["dependencies"]
38+
39+
# Features in .devcontainer/devcontainer.json
40+
- package-ecosystem: "devcontainers"
41+
directory: "/"
42+
schedule:
43+
interval: "weekly"
44+
cooldown:
45+
default-days: 7
46+
labels: ["dependencies"]

‎.github/workflows/python.yml‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
1-
name: CI Checks
1+
name: Python CI Checks
22

33
on:
44
push:
55
branches: [ main ]
66
pull_request:
77
branches: [ main ]
88

9-
permissions:
10-
contents: read
11-
pull-requests: read
9+
permissions: {}
1210

1311
jobs:
1412
code-check-and-unit-test:
15-
runs-on: ubuntu-latest
13+
runs-on: ubuntu-slim
1614
steps:
17-
- uses: actions/checkout@v7
15+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1816
with:
19-
fetch-depth: 0
20-
- name: Setup just
21-
uses: extractions/setup-just@v3
17+
persist-credentials: false
2218
- name: Install uv
23-
uses: astral-sh/setup-uv@v7
19+
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
2420
with:
25-
enable-cache: true
26-
version: ">=0.11,<0.12"
27-
- name: Check gitleaks
28-
uses: gitleaks/gitleaks-action@v3
29-
env:
30-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31-
GITLEAKS_ENABLE_COMMENTS: false
21+
enable-cache: false
22+
version: ">=0.13,<0.14"
3223
- name: Setup environment
3324
run: |
25+
uv tool install rust-just
3426
just sync
3527
- name: Lint
3628
run: |

‎.github/workflows/release-drafter.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ permissions:
1212
jobs:
1313
update-draft:
1414
if: github.event_name == 'push'
15-
runs-on: ubuntu-latest
15+
runs-on: ubuntu-slim
1616
permissions:
1717
contents: write
1818
steps:
19-
- uses: release-drafter/release-drafter@v6
19+
- uses: release-drafter/release-drafter@978bb0b30c5ee8cdd332ced253758157150d43f0 # v7.10.0
2020
env:
2121
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2222

2323
autolabel:
2424
if: github.event_name == 'pull_request' && github.event.action != 'labeled' && github.event.action != 'unlabeled'
25-
runs-on: ubuntu-latest
25+
runs-on: ubuntu-slim
2626
permissions:
2727
pull-requests: write
2828
steps:
29-
- uses: release-drafter/release-drafter@v6
29+
- uses: release-drafter/release-drafter@978bb0b30c5ee8cdd332ced253758157150d43f0 # v7.10.0
3030
with:
3131
disable-releaser: true
3232
env:
@@ -40,7 +40,7 @@ jobs:
4040
permissions:
4141
pull-requests: read
4242
steps:
43-
- uses: mheap/github-action-required-labels@v5
43+
- uses: mheap/github-action-required-labels@23e10fde7e062233401931a0eece796cd9bf3177 # v5.6.0
4444
with:
4545
mode: minimum
4646
count: 1

‎.github/workflows/release.yml‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ jobs:
1616
permissions:
1717
contents: write
1818
steps:
19-
- uses: actions/checkout@v7
19+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2020
with:
2121
ref: main
22+
persist-credentials: false
2223
- name: Install uv
23-
uses: astral-sh/setup-uv@v7
24+
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
2425
with:
25-
version: ">=0.11,<0.12"
26+
enable-cache: false
27+
version: ">=0.13,<0.14"
2628

2729
- name: Refresh draft release
2830
id: drafter
29-
uses: release-drafter/release-drafter@v6
31+
uses: release-drafter/release-drafter@978bb0b30c5ee8cdd332ced253758157150d43f0 # v7.10.0
3032
env:
3133
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3234

@@ -36,7 +38,7 @@ jobs:
3638
run: uv version "$VERSION"
3739

3840
- name: Update CHANGELOG.md
39-
uses: stefanzweifel/changelog-updater-action@v1
41+
uses: stefanzweifel/changelog-updater-action@a938690fad7edf25368f37e43a1ed1b34303eb36 # v1.12.0
4042
with:
4143
latest-version: ${{ steps.drafter.outputs.tag_name }}
4244
release-notes: ${{ steps.drafter.outputs.body }}

‎.github/workflows/security.yml‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: GitHub Actions Security Analysis with zizmor
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["**"]
8+
9+
permissions: {}
10+
11+
jobs:
12+
zizmor:
13+
runs-on: ubuntu-slim
14+
permissions:
15+
contents: read # only needed for private or internal repos
16+
actions: read # only needed for private or internal repos
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
20+
with:
21+
persist-credentials: false
22+
23+
- name: Run zizmor
24+
uses: zizmorcore/zizmor-action@45d7276c9ca790aabd705e31ca99c6185c3e76dd # v0.8.1
25+
with:
26+
advanced-security: false
27+
gitleaks:
28+
runs-on: ubuntu-slim
29+
steps:
30+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
31+
with:
32+
persist-credentials: false
33+
fetch-depth: 0
34+
- name: Check gitleaks
35+
uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
GITLEAKS_ENABLE_COMMENTS: false

‎Brewfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
brew "gitleaks"
22
brew "just"
33
brew "uv"
4+
brew "zizmor"

‎CLAUDE.md.example‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ Python project template using `uv` for environment/dependency management and `ju
44

55
## Commands
66

7+
- `just setup` - install Homebrew tools (`Brewfile`) and sync the project
78
- `just sync` - install all dependency groups into `.venv`
89
- `just lint` - type check (ty), lint + autofix (ruff), format (ruff), spell check (codespell)
910
- `just ci-lint` - same checks without modifying files (used to verify, not fix)
1011
- `just test` - run pytest with coverage (fails under 98%)
12+
- `just zizmor` - audit GitHub Actions workflows for security issues
13+
- `just git-leaks` - scan staged changes for secrets
14+
- `just set-github-labels` - create/update the release labels on GitHub (`scripts/sync-labels.sh`, needs `gh`)
1115
- `uv add <pkg>` / `uv add --dev <pkg>` - add a runtime / dev dependency (never edit `uv.lock` by hand)
1216
- `uv run example` - run the app entry point
1317

@@ -19,10 +23,30 @@ Run `just lint` and `just test` before considering a change done.
1923
- `src/example/__init__.py` - `main()` entry point, exposed as the `example` script
2024
- `tests/` - pytest tests; import the package as `from example.<module> import ...`
2125
- `prek.toml` - git hook config (`prek install` to enable)
26+
- `.github/workflows/` - `python.yml` (lint + tests), `security.yml` (zizmor, gitleaks),
27+
`release-drafter.yml` (draft release, PR labels), `release.yml` (manual release)
28+
- `.github/release-drafter.yml` - release label → version bump / release notes section mapping
29+
- `.github/dependabot.yml` - weekly updates for actions, uv, dev container image and features
30+
- `.devcontainer/` - dev container; base image, `just`, and `uv` pinned by tag + digest
31+
- `scripts/` - repo maintenance scripts
2232

2333
## Conventions
2434

2535
- Python >= 3.14; ruff line length 100, double quotes
2636
- Docstrings required in `src/` (ruff `D` rules), not in `tests/`
2737
- Type hints on public functions; code must pass `ty check`
2838
- Renaming the project means updating `[project] name`, the `src/<name>/` folder, and `[project.scripts]` together
39+
40+
## CI, security, and releases
41+
42+
- Pin GitHub Actions to a full commit SHA with a version comment (`uses: owner/action@<sha> # vX.Y.Z`);
43+
run `just zizmor` after editing workflows
44+
- Give each workflow/job least-privilege `permissions`; set `persist-credentials: false` on checkout
45+
unless the job pushes
46+
- Pin Docker images as `image:tag@sha256:<digest>`
47+
- uv is pinned to 0.13.x in four places that must stay in sync: `[tool.uv] required-version` and the
48+
`uv_build` requirement in `pyproject.toml`, `setup-uv` `version` in the workflows, and the uv image in
49+
`.devcontainer/Dockerfile`
50+
- Do not edit `CHANGELOG.md` or bump `[project] version` by hand; the Release workflow does both
51+
- Every PR needs a release label (GitHub PR label, not a title/commit prefix): `breaking`, `feature`,
52+
`enhancement`, `bug`, `fix`, `chore`, `ci`, `dependencies`, `documentation`, `refactor`, or `skip-changelog`

‎README.md‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Python Project Template
22

33
[![CI](https://github.com/ahcode0919/python-project-template/actions/workflows/python.yml/badge.svg?branch=main)](https://github.com/ahcode0919/python-project-template/actions/workflows/python.yml)
4+
[![Security](https://github.com/ahcode0919/python-project-template/actions/workflows/security.yml/badge.svg?branch=main)](https://github.com/ahcode0919/python-project-template/actions/workflows/security.yml)
45
[![gitleaks](https://img.shields.io/badge/protected%20by-gitleaks-blue)](https://github.com/gitleaks/gitleaks)
56

67
Baseline Python project template
@@ -11,10 +12,10 @@ Project supports local development and VSCode Dev container development
1112

1213
### Local Development Installation
1314

14-
Note: Project uses `uv` and `just` to manage project configuration and commands
15+
Note: Project uses `uv` (0.13.x, enforced by `required-version` in `pyproject.toml`) and `just` to
16+
manage project configuration and commands
1517

16-
* Install dependencies via Homebrew - `brew bundle install`
17-
* Sync project - `just sync`
18+
* Install tools and sync the project - `just setup` (runs `brew bundle install`, then `just sync`)
1819

1920
### VS Code Dev Container
2021

@@ -24,16 +25,36 @@ Note: Project uses `uv` and `just` to manage project configuration and commands
2425
* Install recommended extensions
2526
* Reopen in container using Remote Development Container menu
2627

28+
The base image, `just`, and `uv` are pinned by version and digest in `.devcontainer/Dockerfile`
29+
and updated by Dependabot. To change the Python version, edit the `FROM` line.
30+
2731
## Project Commands
2832

33+
* `just setup` - install Homebrew tools from the `Brewfile` and sync the project
2934
* `just sync` - sync project dependencies (all groups)
3035
* `just lint` - type check, lint, format, and spellcheck project files (applies fixes)
3136
* `just ci-lint` - run the same checks without modifying files (used in CI)
3237
* `just test` - run unit tests
3338
* `just prek` - run pre-commit hooks via prek
3439
* `just git-leaks` - scan staged changes for secrets with gitleaks
40+
* `just zizmor` - audit GitHub Actions workflows for security issues
41+
* `just set-github-labels` - create or update the release labels on GitHub (requires `gh auth login`)
3542
* `uv add {package}` - install a dependency
3643

44+
## CI and Security
45+
46+
| Workflow | Runs on | Purpose |
47+
| ------------------------------------------------- | ---------------------------- | ---------------------------------------------- |
48+
| `python.yml` | push / PR to `main` | lint and unit tests |
49+
| `security.yml` | push to `main`, all PRs | zizmor workflow audit, gitleaks secret scan |
50+
| `release-drafter.yml` | push to `main`, PRs | update the draft release, label PRs |
51+
| `release.yml` | manual | publish a release |
52+
53+
* GitHub Actions are pinned to full commit SHAs, with the version in a trailing comment
54+
* Dependabot (`.github/dependabot.yml`) checks weekly for updates to GitHub Actions, Python
55+
dependencies, the dev container image, and dev container features. New releases wait 7 days
56+
before an update is proposed. Dependabot PRs get the `dependencies` label
57+
3758
## Releases
3859

3960
Releases are managed with [Release Drafter](https://github.com/release-drafter/release-drafter),
@@ -56,6 +77,7 @@ labels; other repository labels (e.g. `good first issue`, `question`) are ignore
5677
has PRs with different labels, the largest bump wins
5778
* Release labels are added automatically from the PR's branch name prefix (`feat/`, `fix/`, `chore/`,
5879
`ci/`, `docs/`, `refactor/`) and from the files it changes. You can add or change them by hand
80+
* Run `just set-github-labels` once to create the release labels in the GitHub repository
5981
* Merging to `main` updates a draft GitHub Release with the next version and notes
6082
* To release, run the **Release** workflow from the Actions tab. It bumps the version in
6183
`pyproject.toml`/`uv.lock`, updates `CHANGELOG.md`, tags the release, and uploads build artifacts

0 commit comments

Comments
 (0)