/tiran-skills:secure-python-release-pipelinefrom tiran-skills
Sets up a hardened GitHub Actions pipeline for building, verifying, and publishing Python packages to PyPI via Trusted Publisher (OIDC). Splits sdist and wheel builds, uses cibuildwheel for compiled extensions, and applies security hardening (SHA-pinned actions, Dependabot, zizmor audit, attestations).
Ships in tiran-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Status: Experimental — assembled from two real shipping projects (see
reference/templates.md: pycxxfilt for compiled/cibuildwheel, zipwire for
pure-Python) plus the upstream PyPI/zizmor/cibuildwheel docs. Follow it, adapt to
your project, and have a human review permissions and the PyPI publisher config.
A good pipeline proves the release is buildable, reproducible, and untampered:
build the sdist, build wheels from that sdist, verify, then publish with
short-lived OIDC credentials from a locked-down job. Work in the order below;
copy-paste-ready workflows are in reference/templates.md, the rationale for
each hardening rule in reference/hardening.md.
pypa/gh-action-pypi-publish — https://github.com/pypa/gh-action-pypi-publishGuardrails. Read
../GUARDRAILS.mdand follow it unless the user says otherwise: work in a project-local.venvwith uv (never global/user site-packages); don't delete content or commit/push without approval (never straight tomain); ask before installing heavy packages or starting a heavy compile (torch/CUDA are multi-GB); match the project's existing style and keep comments/docstrings terse.
grep -nE 'ext_modules|extension_module|cffi|setuptools-rust|maturin' pyproject.toml setup.py meson.build 2>/dev/null
bdist_wheel; a single noarch
wheel. Build with uv build (or python -m build) — zipwire template.manylinux/musllinux containers, and repair (auditwheel/delocate).
Don't hand-roll a per-platform matrix (pycxxfilt template).This is the core correctness check. A wheel built straight from your checkout can
succeed while the sdist silently omits a needed file (a header, a
meson.build, a generated source) — PEP 517 builds run isolated, so anything not
packaged is simply absent. Catch it by making the wheel job consume the sdist:
uv build --sdist (or python -m build --sdist); upload
dist/*.tar.gz as an artifact.pypa/cibuildwheel with package-dir: <path-to-sdist.tar.gz>;uv build --wheel <sdist.tar.gz> (or python -m build --wheel / pip wheel).If the sdist is missing a file, the wheel build fails here instead of shipping a
broken sdist. (Shortcut for simple projects:
hynek/build-and-inspect-python-package does sdist → wheel-from-sdist → inspect
in one step — pycxxfilt uses it in CI.)
Add a gate job that depends on all wheel jobs and downloads every artifact:
twine check dist/*, and for compiled wheels assert the ABI/platform tags
(abi3audit for abi3, and confirm manylinux/macos/win tags). Only a green
verify job feeds the publish job.
Configure the publisher on PyPI first (project → Publishing): GitHub owner,
repository, the workflow filename (e.g. release.yml), and the environment
name (e.g. pypi). Then a minimal publish job:
publish:
needs: [sdist, wheels, verify] # everything must be green first
runs-on: ubuntu-latest
environment: pypi # matches the PyPI publisher config
permissions:
id-token: write # MANDATORY for OIDC trusted publishing (and signs attestations)
contents: read
steps:
- uses: actions/download-artifact@<sha> # collect sdist + all wheels
with: { path: dist, merge-multiple: true }
- uses: pypa/gh-action-pypi-publish@<sha> # pin >=v1.11.0; no username/password/token
Keep this in a separate job so nothing that touches source or runs your build
code holds id-token: write. This job runs no checkout and no build — only
download-artifact then pypi-publish — so the one credentialed job executes the
least code and consumes no untrusted source. Pass the sdist/wheels between jobs as
artifacts (upload/download-artifact), not via the build cache, which is
best-effort and poisonable (see §6). No API tokens anywhere — there is no persistent
credential to steal or abuse; OIDC mints a short-lived, workflow-scoped token at
publish time. PEP 740 provenance is generated by default for
Trusted-Publisher uploads (since gh-action-pypi-publish v1.11.0 — so pin that or
newer; attestations: false opts out): a Sigstore-signed record of the org, repo,
commit SHA, ref, and workflow that built each artifact, logged in Sigstore's
append-only Rekor transparency log so consumers can verify origin. The same
id-token: write covers both publishing and signing — no attestations: write
permission is needed (that scope belongs to GitHub's separate native-attestation
API, not this flow). For staging, add with: repository-url: https://test.pypi.org/legacy/.
Optional — also attach artifacts to a GitHub Release with native provenance. If you publish the sdist + wheels as a GitHub Release (not just to PyPI), give those GitHub-hosted files verifiable provenance too. Do it in a separate job so the extra scopes never land on the PyPI publish job:
github-release:
needs: [verify] # same green gate as publish
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write # create the Release + upload assets
id-token: write # Sigstore signing for the attestation
attestations: write # write GitHub-native SLSA provenance
steps:
- uses: actions/download-artifact@<sha> # no checkout — artifacts only
with: { path: dist, merge-multiple: true }
- uses: actions/attest-build-provenance@<sha> # GitHub-side provenance
with: { subject-path: "dist/*" }
- uses: softprops/action-gh-release@<sha> # or `gh release create`
with: { files: dist/* }
This is the only place attestations: write is warranted — it feeds GitHub's
native-attestation API (actions/attest-*), verifiable with gh attestation verify, and is entirely separate from the PyPI PEP 740 flow above. Keeping it in
its own job preserves the privilege gradient: the PyPI publish job stays
id-token: write-only. Skip this job if you publish to PyPI alone.
permissions: {} at the workflow top level (deny-all default), then
grant the minimum per job — most jobs need only contents: read.id-token: write lives only in the publish job — and it's the only write
scope that job needs (it also covers attestation signing). The one exception is
the optional GitHub-Release job (§4), which adds contents: write +
attestations: write for native provenance; keep it separate so those scopes
never touch the PyPI publish job.needs:).
Each downstream job does less: the sdist job clones and builds; the wheel jobs
consume the sdist (no clone needed); the publish job only fetches artifacts and
uploads. Privilege is inverted — the most-privileged job (id-token: write,
PyPI upload) runs the fewest and least-sensitive steps and touches no source,
minimizing its attack surface.actions/checkout with persist-credentials: false (don't leave the token in
.git/config).concurrency group to cancel superseded runs.Rationale and the full permission map: reference/hardening.md.
uses: owner/action@<40-char-sha> # vX.Y.Z), not a
moving tag — a tag can be repointed at malicious code..github/dependabot.yml for the github-actions (and pip) ecosystems, and
set cooldown: { default-days: 7 } so an update PR waits a week after a release
— long enough for a compromised or broken version to be caught/yanked before
you adopt it. Group the multi-action CodeQL bundle so its sub-actions bump
together in one PR: groups: { codeql: { patterns: ["github/codeql-action/*"] } }.
Full config in reference/templates.md (§E).astral-sh/setup-uv with enable-cache: false; skip actions/cache on tags
(if: ${{ !startsWith(github.ref, 'refs/tags/v') }}). Cache freely in PR/CI
where the output isn't published. Use per-run cache keys
(key: …-${{ github.run_id }}) so runs can't poison each other.uv.lock or a
pip-tools/pylock.toml equivalent) so CI, dev, and build deps resolve to fixed
hashes, and set a ≥3-day resolution cooldown so a freshly published version
can't be pulled in before the community vets it — uv's exclude-newer (e.g.
[tool.uv] exclude-newer = "3 days"). This is the resolver-side twin of the
Dependabot cooldown above. Detail in reference/hardening.md.zizmor is a static analyzer for GitHub Actions (finds injection sinks, excessive permissions, unpinned actions, credential persistence). Run it two ways:
zizmorcore/zizmor-action@<sha>; uploads SARIF to code scanning
(needs security-events: write, contents: read, actions: read). SARIF mode
exits 0 even with findings, so gate merges with a ruleset, not the checkmark.uvx zizmor . (or the
github.com/zizmorcore/zizmor-pre-commit hook, id zizmor). --persona=pedantic
adds code smells; --offline for no-network audits.Optionally add actionlint for the correctness class zizmor doesn't cover —
shellcheck on run: scripts, invalid needs/matrix/runs-on references, and
malformed ${{ }} expressions. It's complementary (security vs syntax), but a Go
tool with no uvx install. Prefer a prebuilt binary in a CI job (rhysd ships
release binaries and a download-actionlint.bash script) over the
rhysd/actionlint pre-commit hook, which compiles from source (language: golang) and needs a Go toolchain locally.
Fix what they flag before shipping. Templates in reference/templates.md.
If the version comes from VCS/git tags (see port-to-scikit-build-core /
port-to-meson-python), VCS versioning and tag-triggered releases work
together:
on: push: tags: ["v*"]); the tag is
the version source.fetch-depth: 0 so the version tool can see tags (shallow
clones hide them).PKG-INFO. Because step 2
builds every wheel from that one sdist, the sdist and all wheels carry the
identical version with no per-wheel git access needed — one source of
truth, consistent across the whole release.Tag-triggered workflow builds an sdist, builds all wheels from that sdist,
verifies them, and publishes via a Trusted Publisher from a dedicated
id-token: write job; permissions: {} at top level with minimal per-job
grants; all actions SHA-pinned; no cache on release builds; zizmor runs clean (or
findings triaged); sdist + wheels share one VCS-derived version.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
npx claudepluginhub tiran/agent-skills --plugin tiran-skills12 skills in this plugin
/bootstrap-python-projectScaffold a new Python project from zero: src/ layout, PEP 621 metadata, a chosen build backend (hatchling for pure Python; meson-python / scikit-build-core / maturin for compiled) with dynamic VCS versioning, py.typed, ruff, a type checker, pytest + coverage, tox or nox via uv, and hardened GitHub Actions CI (SHA-pinned, Trusted Publisher, CodeQL/Scorecard/Dependabot). Always writes a README, LICENSE, and .gitignore. Orchestrates the choose-python-build-backend, modernize-python-metadata, ship-type-information, and secure-python-release-pipeline skills. Use when asked to start a new package, scaffold/bootstrap a Python project, set up a repo from zero, turn a loose script into a proper package, or bring an existing project up to this standard (adopt the layout, metadata, tooling, or CI it lacks)./choose-python-build-backendRecommend the right PEP 517 build backend for a new or existing Python package, and give enough context to migrate. Chooses by three axes: purelib (pure Python) vs platlib (compiled C/C++/Rust/Torch), static vs dynamic/VCS metadata, and native language/build system. Covers uv-build, flit-core, hatchling (incl. compiled via scikit-build-core[hatchling] / a custom build hook), meson-python, scikit-build-core, maturin, and setuptools (legacy). Weighs compiled-project concerns: Cython, PyTorch extensions, pybind11/nanobind bindings, the stable Python ABI (abi3 / limited API), and fast parallel builds (CMake+Ninja, Meson). Use when asked "which build backend should I use", to pick a backend for a new project, or to decide whether to move an existing project off setuptools./crypto-fips-auditAudit a Python package — and any C/C++/Go/Rust code it ships — for its use of cryptography, across three use cases: inventory what crypto a package uses at all (algorithms, providers, linkage, RNG, CA stores), find insecure or weak cryptography, and assess FIPS 140-3 / NIST compliance. Flags insecure use of approved primitives (AES-ECB, RSA PKCS#1 v1.5, static IV/nonce, `random` for secrets, timing-unsafe compares, disabled TLS verification), weak RSA/EC key sizes, and — for FIPS — refused hashes (MD5, MD4, RIPEMD-160), restricted ones (SHA-1), non-approved primitives (BLAKE2/3, ChaCha20-Poly1305, 3DES, scrypt/Argon2/bcrypt, X25519/X448 key agreement, secp256k1), vendored or statically linked crypto (bundled OpenSSL/BoringSSL/AWS-LC/NSS/GnuTLS/libgcrypt/ nettle/libsodium) that escapes the system validated module, hardcoded TLS versions/ciphers that bypass crypto-policies, bundled CA trust stores, and problematic PyPI deps (bcrypt, pycryptodome, pynacl, ecdsa, rsa, m2crypto, …). Source-first, then confirmed against the built wheel/binaries. Gathers evidence; does not certify compliance./modernize-python-metadataImprove a Python package's metadata and move it into a PEP 621 [project] table in pyproject.toml — filling in what's missing along the way. Covers the readme field (dropping the open().read() hack), SPDX license expressions, trove classifiers, well-known project URLs, authors/keywords/requires-python, dependency version constraints (avoid upper caps), PEP 735 dependency groups vs extras, and the build-system table. Keeps the existing build backend (setuptools is fine). Includes a Poetry → PEP 621 migration lens (the [tool.poetry] field map and caret/tilde → floor translation; PDM too). Use when asked to clean up packaging metadata, move metadata out of setup.py/setup.cfg, migrate a Poetry (or PDM) project to [project]/PEP 621, or improve a project's PyPI page./port-to-free-threaded-pythonMake a Python package work correctly on the free-threaded (no-GIL) CPython build (PEP 703; the cp313t/cp314t "t" ABI) and declare that it does, so importing it does not silently re-enable the GIL. Covers the pure-Python thread-safety pass (mutable global/class state, caches, contextvars vs threading.local) and, for C/C++/Cython/pybind11/nanobind/Rust-PyO3 extensions, declaring support (Py_mod_gil / PyUnstable_Module_SetGIL / the per-binding flag), fixing data races with critical sections (Py_BEGIN_CRITICAL_SECTION), PyMutex, atomics and thread-local state, the borrowed-reference hazards and their strong-reference replacements (PyList_GetItemRef, PyDict_GetItemRef), building cp3Xt wheels (meson-python, scikit-build-core, maturin, setuptools, cibuildwheel), and testing under load with ThreadSanitizer and pytest-run-parallel. Use to add free-threading / no-GIL / nogil / free-threaded / PEP 703 support, ship a cp313t/cp314t wheel, or stop the GIL being re-enabled. For a single stable-ABI abi3t wheel (3.15+) pair it with port-to-python-limited-api./port-to-meson-pythonBuild a Python package (usually with a compiled C/C++/Cython/Fortran/Rust extension) with the meson-python PEP 517 backend, or port one off a bespoke setuptools setup.py. Covers the pyproject.toml backend, the meson.build (project / extension_module / install_sources), VCS/dynamic versioning computed in meson.build, editable installs, config-settings, and abi3 / limited-API wheels. Use when asked to adopt meson-python or Meson, scaffold a new meson-python project, drop setup.py, or produce standards-based wheels.