Automated PyPI & Docker Releases with OIDC Trusted Publishing¶
Note
Published: November 30, 2026
Authors: Written by Gemini 3.8 Flash, Co-Authored & Reviewed by Carlos Santos (@carlkidcrypto)
Estimated Reading Time: 7 minutes
Tags: GitHub Actions • OIDC • PyPI • Docker • Shared Workflows • CI/CD • Security
Publishing Python wheels to PyPI and multi-architecture container images to GitHub Container Registry (GHCR) traditionally relied on long-lived static API tokens stored in repository secrets. If a token leaked or expired, maintainers faced broken release pipelines or urgent credential rotation across every project in their portfolio.
OpenID Connect (OIDC) Trusted Publishing eliminates static secrets
altogether. Instead of storing passwords or PYPI_API_TOKEN values, a
GitHub Actions workflow requests a short-lived, cryptographically signed OIDC
JWT token scoped strictly to that repository, tag, and environment.
By centralizing these release jobs inside shared-workflows, every Python package (ezsnmp, purpleair_api) and containerized service (purpleair_data_logger, purpleair-matterbridge) inherits uniform, zero-secret release automation.
In this tutorial, we will design a reusable OIDC PyPI release workflow, build a multi-architecture Docker Buildx publisher for GHCR, and configure environment protection rules for safe automated deployments.
How GitHub OIDC Trusted Publishing Works¶
When a workflow declares permissions: id-token: write, GitHub’s OIDC
provider issues a short-lived JSON Web Token (JWT) containing verified claims
about the workflow run:
repositoryandrepository_owner(e.g.carlkidcrypto/ezsnmp)ref(the exact git tag, such asrefs/tags/v2026.11.9b0)environment(for example,pypiortestpypi)job_workflow_ref(pointing to the reusable workflow inshared-workflows)
PyPI validates those OIDC claims against your pre-configured Trusted
Publisher policy and issues an ephemeral upload token valid only for that
single job. For container images, GHCR authenticates directly via the ephemeral
job-scoped GITHUB_TOKEN (with packages: write), while id-token: write
and attestations: write enable cryptographic SLSA build provenance
attestations.
Reusable PyPI OIDC Release Workflow¶
Store the shared PyPI publisher in
.github/workflows/pypi-oidc.yml inside shared-workflows.
Notice that permissions are scoped cleanly: id-token: write for OIDC
exchange and contents: read for checking out artifacts:
name: Reusable PyPI OIDC Publish
on:
workflow_call:
inputs:
environment-name:
description: "GitHub deployment environment (pypi or testpypi)"
required: false
type: string
default: "pypi"
artifact-name:
description: "Name of the uploaded dist artifact"
required: false
type: string
default: "python-dist"
skip-existing:
description: "Skip files already published on PyPI"
required: false
type: boolean
default: false
jobs:
publish-pypi:
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment-name }}
permissions:
id-token: write
contents: read
steps:
- name: Download built wheels and sdist
uses: actions/download-artifact@v4
with:
name: ${{ inputs.artifact-name }}
path: dist/
- name: Publish distributions via OIDC Trusted Publishing
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: ${{ inputs.skip-existing }}
repository-url: >-
${{ inputs.environment-name == 'testpypi' &&
'https://test.pypi.org/legacy/' ||
'https://upload.pypi.org/legacy/' }}
Multi-Arch Docker Buildx & GHCR OIDC Publishing¶
For containerized tools like purpleair_data_logger and
purpleair-matterbridge, a reusable Docker workflow builds linux/amd64
and linux/arm64 manifests and pushes directly to GHCR using the ephemeral
GITHUB_TOKEN (no personal access token required):
name: Reusable Multi-Arch Docker Publish
on:
workflow_call:
inputs:
image-name:
description: "GHCR image name (e.g. ghcr.io/org/app)"
required: true
type: string
platforms:
description: "Target platforms for Buildx"
required: false
type: string
default: "linux/amd64,linux/arm64"
jobs:
docker-release:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout caller repository
uses: actions/checkout@v4
- name: Set up QEMU for ARM64 emulation
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata and semver tags
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.image-name }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push multi-arch image
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ inputs.platforms }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
Security Hardening Checklist¶
Bind Trusted Publishers to GitHub Environments:
Configure PyPI’s Trusted Publisher settings to require the
pypiGitHub Environment. Enable manual reviewer approvals or tag-branch restrictions on that environment so pull requests from forks can never mint production PyPI tokens.
Avoid ``workflow_call`` Secret Inheritance for Release Jobs:
Because OIDC relies on
id-token: writerather than stored secrets, you can omitsecrets: inheritcompletely on release jobs.
Generate Build Provenance Attestations:
Include
attestations: writeon Docker and wheel release jobs to attach cryptographic SLSA provenance directly to your GitHub Releases.
Summary & What’s Next¶
Centralizing OIDC Trusted Publishing inside shared-workflows removes static API secrets across every repository while standardizing wheel and multi-arch container releases.
In our next blog post, we will rotate back to purpleair_api, exploring how to export normalized PurpleAir telemetry into GeoJSON FeatureCollections and Pandas DataFrames for spatial mapping and smoke plume analysis.
Warning
AI-generated content may contain misinformation or mistakes. A human does review this, but we are only human.