Skip to content

Publish from a job that runs no project code - #81

Closed
dblock wants to merge 1 commit into
masterfrom
dblock/isolated-release
Closed

dblock wants to merge 1 commit into
masterfrom
dblock/isolated-release

Conversation

@dblock

@dblock dblock commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Summary

Add an opt-in reusable workflow, .github/workflows/isolated-release.yml, so publication credentials never coexist with project code. This addresses the security review of ruby-grape/grape#3078: the standard workflow installs the project's dev/test bundle and runs its full suite in the same job that holds id-token: write and contents: write.

  • Build job (contents: read, no environment): installs the bundle and runs capture, validate, prepare, resolve, test, and checkpoint exactly as today, then a new release:workflow:seal task. Sealing prepares and commits the next development iteration locally (so hooks such as README updates still run), rewrites release.bundle with the tag and both commits, and writes a publication.json handoff. Everything is uploaded as the recovery artifact before publication.
  • Publish job (release environment, contents: write, id-token: write): checks out the caller at the dispatched commit and this library at job.workflow_sha, installs no bundle (bundler: none), and runs Workflow::IsolatedPublication with ruby --disable-gems -I ../library/lib. It never loads the project's Gemfile, Rakefile, gemspec, or commands.
  • Publication order: after verifying the handoff (default branch, release commit's only parent is the dispatched commit, lightweight tag at the release commit, development commit's only parent is the release commit, gem checksum and identity), it pushes the release commit before gem push, then the tag, the GitHub Release, and the development commit. A branch that rejects the Actions token now fails before anything is published (review item 1). Each step reconciles existing state, so "Re-run failed jobs" resumes.
  • Guards: sealing fails in the unprivileged job unless the default package, RubyGems destination, Git, and GitHub Release hosting (or hosting: nil) are used, and rejects publication-stage hooks and success:/failure: callbacks the publish job cannot run. Workflow::SemanticRubyGem is supported, including generated notes and bump: false.
  • Trusted Publishing: verified against rubygems.org's OIDC::TrustedPublisher::GitHubAction: the workflow filename is matched against the reusable workflow's path in job_workflow_ref, so callers configure isolated-release.yml, and that publisher cannot be used by the single-job workflow. RubyGems accepts any ref, so the docs recommend SHA pinning.
  • Testing API: RubyGemRelease::RSpec::Project#isolated_release! and #publish_isolated! run the build tasks and then publish from a fresh clone in a separate plain-Ruby process with the local adapters.
  • The single-job workflow and composite action are unchanged. The self-release pin updater also covers isolated-release.yml@vX references.
  • .github/actionlint.yaml narrowly ignores job.workflow_repository/job.workflow_sha for this file only: both are documented by GitHub but unknown to actionlint 1.7.12 (fix: add documented job workflow context properties rhysd/actionlint#707).

Validation

  • bundle exec rake: RuboCop (including spellcheck) and all unit and integration specs pass.
  • bundle exec rake build and actionlint for .github/workflows/*.yml and examples/.github/workflows/*.yml pass.
  • New integration specs use the lifecycle-hooks example: a complete isolated release with the expected commit chain and README content, repeat publication as a no-op, a protected branch (pre-receive hook) failing before registry or hosting publication and resuming once permitted, a branch that advanced after the build, a handoff from another commit, and a publication-stage hook rejected while sealing.
  • Verified Workflow::IsolatedPublication loads with ruby --disable-gems -I lib and no Rake, Bundler, or Commonmarker features.

Not validated: a real Actions run. The publish job's use of job.workflow_*, artifact handoff between jobs, and OIDC exchange need a first real dispatch. Consumer CI does not exercise Actions authentication.

This PR was written by an AI (Claude) acting on behalf of @dblock.

🤖 Generated with Claude Code

https://claude.ai/code/session_011Gr21j6KD4oksnhmZ5u3pr

Add an opt-in isolated reusable workflow. A read-only build job runs the
project's capture, validation, preparation, tests, and checkpoint, then
`release:workflow:seal` commits the next development iteration locally
and preserves a Git bundle and `publication.json` handoff with the gem.
An environment-gated publish job checks out the library at the reusable
workflow's own commit and publishes with plain Ruby, never loading the
project's bundle, Rakefile, or gemspec. It verifies the handoff against
the dispatched commit, then pushes the release commit before the gem, so
a branch that rejects the release token fails before publication.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Gr21j6KD4oksnhmZ5u3pr
@dblock
dblock force-pushed the dblock/isolated-release branch from 8e5d35d to 699f4d7 Compare November 20, 2026 21:39
@dblock

dblock commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

Closing this. The isolation it adds doesn't cover the outcome that matters most.

  • The standard workflow already provides the large improvement. Compared with releasing from a maintainer's machine (long-lived credentials for all gems and repos, and possible persistence), a malicious dependency in CI only reaches a short-lived key for one gem and a token for one repo, for minutes, on a throwaway runner, after environment approval.
  • A compromised dependency can still ship a malicious gem here. The unprivileged job still runs the project's bundle and produces the .gem, the release and development commits, and publication.json. The publish job checks that these are consistent with each other, but not against reviewed source, so it publishes and pushes whatever that job built.
  • What it does remove is narrow. It stops misuse of the job's credentials beyond this release, such as pushing other refs or keeping the short-lived key. Both credentials are already scoped to this gem and repository.
  • The cost is high. It adds a second workflow, a handoff step, a separate trusted publisher, limits on hooks and callbacks, and an OIDC exchange and artifact handoff that have not been validated in a real Actions run.

Meaningful isolation would require the privileged job to rebuild the gem from the tagged source without the development bundle, or to verify it against the Git tree, similar to the reviewed workflow's content audit. That would be a separate, larger design.

This comment was written by an AI (Claude) acting on behalf of @dblock.

@dblock dblock closed this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant