Skip to content

ci: gate the pnpr release publish and docker jobs behind the release environment - #12640

Merged
zkochan merged 1 commit into
pnpm:mainfrom
YESHYUNGSEOK:ci/pnpr-release-env-gate
Jun 25, 2026
Merged

zkochan merged 1 commit into
pnpm:mainfrom
YESHYUNGSEOK:ci/pnpr-release-env-gate

Conversation

@YESHYUNGSEOK

@YESHYUNGSEOK YESHYUNGSEOK commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

pnpr-release-to-npm.yml can be triggered via workflow_dispatch. Its publish job uses npm
OIDC trusted publishing to publish the @pnpm/pnpr package, and its docker job pushes the
mutable ghcr.io/pnpm/pnpr:latest tag. Neither job had an environment: release gate, so any
collaborator with write access could publish to npm and overwrite the mutable Docker tag via a
manual dispatch without reviewer approval — unlike release.yml, which gates its publishing job.

This adds environment: release to the publish and docker jobs. The build job produces no
externally visible artifacts and is intentionally left ungated so the matrix legs are not blocked
on approval.

Squash Commit Body

pnpr-release-to-npm.yml can be triggered via workflow_dispatch. Its publish job uses npm OIDC
trusted publishing to publish the `@pnpm/pnpr` package, and its docker job pushes the mutable
ghcr.io/pnpm/pnpr:latest tag. Neither had an environment gate, so any collaborator with write
access could publish to npm and overwrite the mutable Docker tag without reviewer approval.

Add an environment: release gate to the publish and docker jobs (the build job produces no
externally visible artifacts and is intentionally left ungated), matching the protection used
by release.yml.

Checklist

  • Added or updated tests — n/a; CI workflow permission gate with no unit-testable surface.
  • Updated the documentation if needed — n/a.

(No changeset: no published package changes. CI-only change.)


Written by an agent (Claude Code, claude-opus-4-8).

Summary by CodeRabbit

  • Chores
    • Improved the release workflow’s environment handling for publishing and Docker-related release steps.

…environment

pnpr-release-to-npm.yml can be triggered via workflow_dispatch. Its publish job uses npm OIDC
trusted publishing to publish the `@pnpm/pnpr` package, and its docker job pushes the mutable
ghcr.io/pnpm/pnpr:latest tag. Neither had an environment gate, so any collaborator with write
access could publish to npm and overwrite the mutable Docker tag without reviewer approval.

Add an environment: release gate to the publish and docker jobs (the build job produces no
externally visible artifacts and is intentionally left ungated), matching the protection used
by release.yml.

Co-authored-by: Claude <[email protected]>
@YESHYUNGSEOK
YESHYUNGSEOK requested a review from zkochan as a code owner June 25, 2026 02:12
@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 85f42378-55a0-4817-8718-d57c8aa49ab7

📥 Commits

Reviewing files that changed from the base of the PR and between 54c5c0e and 08f60fd.

📒 Files selected for processing (1)
  • .github/workflows/pnpr-release-to-npm.yml

📝 Walkthrough

Walkthrough

The release-to-npm workflow now assigns the release environment to both the publish and docker jobs. No triggers, steps, or artifact handling changed.

Changes

Release workflow environment declarations

Layer / File(s) Summary
Job environment declarations
.github/workflows/pnpr-release-to-npm.yml
The publish and docker jobs both declare the release environment.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

  • pnpm/pnpm#11496: Also changes npm release workflow behavior in GitHub Actions, with closely related publish-job configuration.
  • pnpm/pnpm#11963: Modifies the same release workflow file, so it is directly adjacent to these job-level changes.
  • pnpm/pnpm#12619: Touches the same release workflow and the publish/docker flow that this PR updates.

Suggested labels

product: pnpr

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Gate pnpr npm publish and Docker push behind GitHub Actions release environment
⚙️ Configuration changes 🐞 Bug fix 🕐 Less than 10 minutes

Grey Divider

Description

• Require environment: release approval before pnpr npm publishing runs
• Require environment: release approval before pushing the mutable pnpr:latest image tag
• Keep build matrix ungated since it produces no externally visible artifacts
Diagram

graph TD
  A(("workflow_dispatch")) --> B["Build (ungated)"] --> C["Publish (env: release)"] --> D["Docker (env: release)"] --> F["GHCR image (latest)ատ"]
  C --> E["npm registry (@pnpm/pnpr)"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Remove `workflow_dispatch` for pnpr publish workflow
  • ➕ Eliminates manual-trigger attack surface entirely
  • ➕ Forces publishing to happen only via tag-driven/release automation
  • ➖ Reduces operational flexibility (can’t manually republish/retry without tags)
  • ➖ May require additional release automation changes
2. Split into a gated reusable workflow (`workflow_call`) invoked only from a protected release workflow
  • ➕ Centralizes all publishing behind one protected entrypoint
  • ➕ Makes approval/policy enforcement harder to bypass
  • ➖ More refactor than necessary for the current risk
  • ➖ Adds indirection and coordination across workflows

Recommendation: Adding environment: release on the two externally-impactful jobs (npm publish and GHCR push) is the simplest effective control and matches the existing protection used by release.yml. Alternatives were considered, but they add operational cost/complexity without materially improving security for this specific gap.

Files changed (1) +2 / -0

Other (1) +2 / -0
pnpr-release-to-npm.ymlGate publish and docker jobs behind 'environment: release' +2/-0

Gate publish and docker jobs behind 'environment: release'

• Adds 'environment: release' to the 'publish' and 'docker' jobs in the manually-triggered pnpr release workflow. This enforces required reviewer approval before publishing to npm or updating the mutable GHCR 'latest' tag, while keeping the 'build' job ungated.

.github/workflows/pnpr-release-to-npm.yml

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jun 25, 2026
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Untrusted ref release risk 🐞 Bug ⛨ Security
Description
pnpr-release-to-npm.yml has no ref validation, so it can be manually dispatched on a non-protected
ref where the ungated build job (with id-token: write) produces release artifacts before the
environment: release approval happens. If an approver approves the environment-gated
publish/docker jobs for that run, the workflow can publish artifacts built from that untrusted
ref to npm and/or push them to GHCR.
Code

.github/workflows/pnpr-release-to-npm.yml[R150-156]

 publish:
   name: Publish
   runs-on: ubuntu-latest
+    environment: release
   permissions:
     # Required for npm provenance attestations via OIDC.
     id-token: write
Evidence
The workflow is manually dispatchable and does not validate github.ref/GITHUB_REF before running
the ungated build job; the build job runs with id-token: write and uploads artifacts that
publish/docker later consume. By contrast, release.yml demonstrates the pattern of validating
the ref before entering an environment: release gated job.

.github/workflows/pnpr-release-to-npm.yml[9-30]
.github/workflows/pnpr-release-to-npm.yml[140-158]
.github/workflows/pnpr-release-to-npm.yml[223-233]
.github/workflows/release.yml[12-26]
.github/workflows/release.yml[27-41]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
This workflow can be dispatched without constraining the git ref it runs on. Because `build` runs before the `environment: release` approval gate and produces the artifacts that `publish`/`docker` consume, approving the gated jobs can result in publishing artifacts built from an unintended (potentially attacker-controlled) ref.
### Issue Context
`release.yml` already includes a dedicated ref-validation job to ensure the release workflow only runs from an expected ref pattern before entering the environment-gated job.
### Fix Focus Areas
- .github/workflows/pnpr-release-to-npm.yml[9-30]
- .github/workflows/pnpr-release-to-npm.yml[150-158]
- .github/workflows/pnpr-release-to-npm.yml[223-233]
### Proposed fix
1. Add a lightweight `validate-release-ref` job (with `permissions: {}`) that fails unless `GITHUB_REF` matches the intended release ref(s) (e.g. `refs/heads/main`, or a tag pattern if that’s the intended model).
2. Make `build`, `publish`, and `docker` depend on it (e.g. `needs: validate-release-ref`), so no artifacts are built (and no OIDC tokens are issued) for unexpected refs.
3. Keep `environment: release` on the publishing jobs as in this PR.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Previous review results

Review updated until commit 08f60fd

Results up to commit 08f60fd


🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)


Remediation recommended
1. Untrusted ref release risk 🐞 Bug ⛨ Security
Description
pnpr-release-to-npm.yml has no ref validation, so it can be manually dispatched on a non-protected
ref where the ungated build job (with id-token: write) produces release artifacts before the
environment: release approval happens. If an approver approves the environment-gated
publish/docker jobs for that run, the workflow can publish artifacts built from that untrusted
ref to npm and/or push them to GHCR.
Code

.github/workflows/pnpr-release-to-npm.yml[R150-156]

  publish:
    name: Publish
    runs-on: ubuntu-latest
+    environment: release
    permissions:
      # Required for npm provenance attestations via OIDC.
      id-token: write
Evidence
The workflow is manually dispatchable and does not validate github.ref/GITHUB_REF before running
the ungated build job; the build job runs with id-token: write and uploads artifacts that
publish/docker later consume. By contrast, release.yml demonstrates the pattern of validating
the ref before entering an environment: release gated job.

.github/workflows/pnpr-release-to-npm.yml[9-30]
.github/workflows/pnpr-release-to-npm.yml[140-158]
.github/workflows/pnpr-release-to-npm.yml[223-233]
.github/workflows/release.yml[12-26]
.github/workflows/release.yml[27-41]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
This workflow can be dispatched without constraining the git ref it runs on. Because `build` runs before the `environment: release` approval gate and produces the artifacts that `publish`/`docker` consume, approving the gated jobs can result in publishing artifacts built from an unintended (potentially attacker-controlled) ref.

### Issue Context
`release.yml` already includes a dedicated ref-validation job to ensure the release workflow only runs from an expected ref pattern before entering the environment-gated job.

### Fix Focus Areas
- .github/workflows/pnpr-release-to-npm.yml[9-30]
- .github/workflows/pnpr-release-to-npm.yml[150-158]
- .github/workflows/pnpr-release-to-npm.yml[223-233]

### Proposed fix
1. Add a lightweight `validate-release-ref` job (with `permissions: {}`) that fails unless `GITHUB_REF` matches the intended release ref(s) (e.g. `refs/heads/main`, or a tag pattern if that’s the intended model).
2. Make `build`, `publish`, and `docker` depend on it (e.g. `needs: validate-release-ref`), so no artifacts are built (and no OIDC tokens are issued) for unexpected refs.
3. Keep `environment: release` on the publishing jobs as in this PR.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 08f60fd

@YESHYUNGSEOK

Copy link
Copy Markdown
Contributor Author

Thanks @qodo — re: Untrusted ref release risk (no ref validation on workflow_dispatch): valid as defense-in-depth, but note the environment: release gate this PR adds already forces a human approval before any npm (OIDC) publish or GHCR push, so a dispatch from an attacker-controlled ref is visible to — and can be declined by — the approver. The canonical mitigation is the release environment's deployment branches rule (repo settings) and/or an explicit ref allowlist step; both are follow-ups beyond this PR's scope, which is specifically adding the approval gate. I deliberately did not add a ref check here because the intended dispatch ref isn't certain and a wrong allowlist would break legitimate releases.


Written by an agent (Claude Code, claude-opus-4-8).

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Thanks @qodo — re: Untrusted ref release risk (no ref validation on workflow_dispatch): valid as defense-in-depth, but note the environment: release gate this PR adds already forces a human approval before any npm (OIDC) publish or GHCR push, so a dispatch from an attacker-controlled ref is visible to — and can be declined by — the approver. The canonical mitigation is the release environment's deployment branches rule (repo settings) and/or an explicit ref allowlist step; both are follow-ups beyond this PR's scope, which is specifically adding the approval gate. I deliberately did not add a ref check here because the intended dispatch ref isn't certain and a wrong allowlist would break legitimate releases.


Written by an agent (Claude Code, claude-opus-4-8).

Yes — I agree with that framing.

  • environment: release meaningfully reduces risk by requiring human approval before the sensitive publish/push steps run.
  • It does not by itself validate the dispatch ref, so an attacker-controlled ref can still reach the approval gate.
  • The stronger long-term controls are exactly what you called out: the environment’s deployment-branches rule and/or an explicit ref allowlist.

So I’m comfortable treating ref validation as a follow-up and keeping this PR scoped to adding the approval gate. If you want, I can also help draft a short comment in the workflow or PR description to make that scope explicit.

@zkochan

zkochan commented Jun 25, 2026

Copy link
Copy Markdown
Member

You could have combined this with the previous pr.

@zkochan
zkochan merged commit 0c44bb9 into pnpm:main Jun 25, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pnpr reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants