From 35bf61a2c328fdf49b259251bbe1cfcc25a9d7e8 Mon Sep 17 00:00:00 2001 From: Riyad Khan <65298773+rr3khan@users.noreply.github.com> Date: Thu, 3 Dec 2026 16:48:45 -0500 Subject: [PATCH 1/3] Publish to PyPI with trusted publishing instead of an API token The release workflow uploaded to PyPI with a long-lived PYPI_API_TOKEN secret. Switch it to PyPI trusted publishing (OIDC), so the workflow gets a short-lived token for each release and no secret is stored. The single release job is split into build, publish and GitHub release jobs. Only the publish job gets an OIDC token, and it runs in the `pypi` environment so each publish needs a reviewer's approval. Also replace the deprecated `::set-output` command with $GITHUB_OUTPUT. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 67 ++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3fbf0f2..9b08620 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,17 +1,27 @@ name: Release SDK if needed +# Publishes onepasswordconnectsdk to PyPI with PyPI trusted publishing (OIDC), so no PyPI +# token is involved. The trusted publisher on pypi.org is bound to this file (release.yml) +# and the `pypi` environment; renaming either breaks publishing. +# +# Runs when a release/* PR is merged into main. The publish job waits for approval on the +# `pypi` environment before anything is uploaded. + on: pull_request: branches: main types: closed permissions: - contents: write + contents: read jobs: - release: + build: + name: Build runs-on: ubuntu-latest if: github.event.pull_request.merged == true && contains(github.event.pull_request.head.ref, 'release/') + permissions: + contents: read steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 @@ -22,6 +32,7 @@ jobs: uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1 with: fetch-depth: 0 + persist-credentials: false - name: Setup Python uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0 with: @@ -33,17 +44,63 @@ jobs: poetry install - name: Build the package run: poetry build - - name: Publish to PyPi + - name: Upload distributions + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: dist + path: dist/ + if-no-files-found: error + + # Only this job gets an OIDC token, and it runs nothing from the repo: it uploads the + # files the build job made. + publish: + name: Publish to PyPI + needs: build + runs-on: ubuntu-latest + # Must match the environment on the PyPI trusted publisher config. + environment: + name: pypi + url: https://pypi.org/project/onepasswordconnectsdk/ + permissions: + id-token: write # PyPI trusted publishing (OIDC) + steps: + - name: Harden the runner (Audit all outbound calls) + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: audit + + - name: Download distributions + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: dist + path: dist/ + + # No password: the action exchanges the job's OIDC token for a short-lived PyPI + # token, and attaches PEP 740 attestations to the uploaded files. + - name: Publish to PyPI uses: step-security/gh-action-pypi-publish@eccc9148d1fa355476d98c01819ec34b75a86f24 # v1.14.2 + + # Kept in its own job so only this job can write to the repo, and the publish job + # (which holds the PyPI OIDC token) stays read-only. + release: + name: GitHub release + needs: publish + runs-on: ubuntu-latest + permissions: + contents: write # create the tag and GitHub release + steps: + - name: Harden the runner (Audit all outbound calls) + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: - password: ${{ secrets.PYPI_API_TOKEN }} + egress-policy: audit + - name: Create Release tag id: create-tag env: PR_REF: ${{ github.event.pull_request.head.ref }} run: | release_tag=$(echo "$PR_REF" | cut -d "/" -f2) - echo "::set-output name=release-tag::$release_tag" + echo "release-tag=$release_tag" >> "$GITHUB_OUTPUT" - name: Make new release uses: step-security/release-action@a0d8e0f90f554c15366ca2c9046bf4090d24adbe # v1.21.0 with: From bb7fdf03266eb6e775ee376ab831d74aad745cc1 Mon Sep 17 00:00:00 2001 From: Riyad Khan <65298773+rr3khan@users.noreply.github.com> Date: Thu, 3 Dec 2026 16:59:39 -0500 Subject: [PATCH 2/3] Keep the PyPI token as a fallback until trusted publishing is set up Publish with the PYPI_API_TOKEN secret unless the PYPI_TRUSTED_PUBLISHING repository variable is `true`. Releases keep working if this merges before the trusted publisher exists on PyPI, and switching over is a settings change rather than another PR. The token path will be removed once a release has gone through with trusted publishing. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9b08620..beb28be 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,10 @@ name: Release SDK if needed -# Publishes onepasswordconnectsdk to PyPI with PyPI trusted publishing (OIDC), so no PyPI -# token is involved. The trusted publisher on pypi.org is bound to this file (release.yml) -# and the `pypi` environment; renaming either breaks publishing. +# Publishes onepasswordconnectsdk to PyPI with PyPI trusted publishing (OIDC) when the +# `PYPI_TRUSTED_PUBLISHING` repository variable is set to `true`. Otherwise it falls back to +# the PYPI_API_TOKEN secret, until the trusted publisher on pypi.org is set up and the token +# is removed. The trusted publisher is bound to this file (release.yml) and the `pypi` +# environment; renaming either breaks publishing. # # Runs when a release/* PR is merged into main. The publish job waits for approval on the # `pypi` environment before anything is uploaded. @@ -75,10 +77,13 @@ jobs: name: dist path: dist/ - # No password: the action exchanges the job's OIDC token for a short-lived PyPI - # token, and attaches PEP 740 attestations to the uploaded files. + # With no password, the action exchanges the job's OIDC token for a short-lived PyPI + # token and attaches PEP 740 attestations to the uploaded files. Until the + # PYPI_TRUSTED_PUBLISHING variable is `true`, it uploads with the API token instead. - name: Publish to PyPI uses: step-security/gh-action-pypi-publish@eccc9148d1fa355476d98c01819ec34b75a86f24 # v1.14.2 + with: + password: ${{ vars.PYPI_TRUSTED_PUBLISHING != 'true' && secrets.PYPI_API_TOKEN || '' }} # Kept in its own job so only this job can write to the repo, and the publish job # (which holds the PyPI OIDC token) stays read-only. From 510ec49a69f86342a2da42a81f193e0ff2800203 Mon Sep 17 00:00:00 2001 From: Riyad Khan <65298773+rr3khan@users.noreply.github.com> Date: Fri, 4 Dec 2026 10:29:05 -0500 Subject: [PATCH 3/3] Use the PyPI token only while it is set Drop the PYPI_TRUSTED_PUBLISHING variable. The publish step now passes the PYPI_API_TOKEN secret directly, so releases use the token while the secret exists and trusted publishing once it is deleted. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index beb28be..9a1a51b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,10 +1,8 @@ name: Release SDK if needed -# Publishes onepasswordconnectsdk to PyPI with PyPI trusted publishing (OIDC) when the -# `PYPI_TRUSTED_PUBLISHING` repository variable is set to `true`. Otherwise it falls back to -# the PYPI_API_TOKEN secret, until the trusted publisher on pypi.org is set up and the token -# is removed. The trusted publisher is bound to this file (release.yml) and the `pypi` -# environment; renaming either breaks publishing. +# Publishes onepasswordconnectsdk to PyPI with the PYPI_API_TOKEN secret while it is set, and +# with PyPI trusted publishing (OIDC) once it is deleted. The trusted publisher is bound to +# this file (release.yml) and the `pypi` environment; renaming either breaks publishing. # # Runs when a release/* PR is merged into main. The publish job waits for approval on the # `pypi` environment before anything is uploaded. @@ -77,13 +75,13 @@ jobs: name: dist path: dist/ - # With no password, the action exchanges the job's OIDC token for a short-lived PyPI - # token and attaches PEP 740 attestations to the uploaded files. Until the - # PYPI_TRUSTED_PUBLISHING variable is `true`, it uploads with the API token instead. + # While the PYPI_API_TOKEN secret is set, the action uploads with it. Once the secret is + # deleted, the password is empty, so the action exchanges the job's OIDC token for a + # short-lived PyPI token and attaches PEP 740 attestations to the uploaded files. - name: Publish to PyPI uses: step-security/gh-action-pypi-publish@eccc9148d1fa355476d98c01819ec34b75a86f24 # v1.14.2 with: - password: ${{ vars.PYPI_TRUSTED_PUBLISHING != 'true' && secrets.PYPI_API_TOKEN || '' }} + password: ${{ secrets.PYPI_API_TOKEN }} # Kept in its own job so only this job can write to the repo, and the publish job # (which holds the PyPI OIDC token) stays read-only.