Skip to content

Commit 6f1d460

Browse files
authored
Use trusted publishing (#62)
* update to use OIDC trusted publishing to npm Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> * chore: commit Cargo.lock files for reproducible builds Remove Cargo.lock from .gitignore and track lock files for both Rust workspaces (code-validator/guest and sandbox/runtime). Prevents transitive dependency MSRV breakage (e.g. constant_time_eq 0.4.3 requiring rustc 1.95.0) when building on CI with pinned toolchain versions. * review fixes Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> --------- Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent 0368c07 commit 6f1d460

6 files changed

Lines changed: 3285 additions & 6 deletions

File tree

.github/workflows/publish.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ on:
1212
required: true
1313
type: string
1414

15+
# Workflow-level permissions use least privilege (read-only).
16+
# Jobs that need elevated permissions (npm OIDC, GHCR push) declare them
17+
# individually on the job — see publish-npm and publish-docker.
1518
permissions:
1619
contents: read
17-
packages: write
1820

1921
env:
2022
REGISTRY: ghcr.io
@@ -114,6 +116,11 @@ jobs:
114116
publish-npm:
115117
name: Publish to npmjs.org
116118
needs: [build-native]
119+
# id-token: write is required for npm OIDC trusted publishing;
120+
# contents: read for checkout. Scoped to this job only (least privilege).
121+
permissions:
122+
contents: read
123+
id-token: write
117124
runs-on: [self-hosted, Linux, X64, "1ES.Pool=hld-kvm-amd","JobId=hyperagent-publish-npm-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}"]
118125
steps:
119126
- uses: actions/checkout@v6
@@ -123,6 +130,11 @@ jobs:
123130
node-version: "22"
124131
registry-url: "https://registry.npmjs.org"
125132

133+
# Trusted publishing requires npm >=11.5.1 for OIDC token exchange.
134+
# Pin to ^11.5.1 so we don't silently get an older 11.x that lacks OIDC.
135+
- name: Upgrade npm for trusted publishing
136+
run: npm install -g npm@^11.5.1 && npm --version
137+
126138
- uses: hyperlight-dev/ci-setup-workflow@v1.9.0
127139
with:
128140
rust-toolchain: "1.89"
@@ -152,15 +164,30 @@ jobs:
152164
if: github.event_name == 'workflow_dispatch'
153165
run: npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version
154166

167+
# OIDC trusted publishing for release events; NPM_TOKEN fallback for workflow_dispatch
168+
- name: Set publish flags
169+
id: publish-flags
170+
run: |
171+
if [ "${{ github.event_name }}" != "workflow_dispatch" ]; then
172+
echo "provenance=--provenance" >> "$GITHUB_OUTPUT"
173+
else
174+
echo "provenance=" >> "$GITHUB_OUTPUT"
175+
fi
176+
155177
- name: Publish to npmjs.org
156-
run: npm publish --access public
178+
run: npm publish --access public ${{ steps.publish-flags.outputs.provenance }}
157179
env:
158-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
180+
NODE_AUTH_TOKEN: ${{ github.event_name == 'workflow_dispatch' && secrets.NPM_TOKEN || '' }}
159181

160182
# Build and publish Docker image (after tests pass)
161183
publish-docker:
162184
name: Publish to GitHub Container Registry
163185
needs: [build-native]
186+
# packages: write for pushing the image to GHCR.
187+
# Scoped to this job only (least privilege).
188+
permissions:
189+
contents: read
190+
packages: write
164191
runs-on: ubuntu-latest
165192
steps:
166193
- uses: actions/checkout@v6

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ builtin-modules/*.d.ts.map
1919

2020
# Rust build artifacts
2121
target/
22-
Cargo.lock
2322
*.node
2423

2524
# Log files are written to ~/.hyperagent/logs/ (not in the repo)
@@ -43,7 +42,6 @@ iteration-logs/
4342

4443
# Hyperagent runtime build artifacts
4544
src/sandbox/runtime/target/
46-
src/sandbox/runtime/Cargo.lock
4745

4846
# Generated plugin files (compiled from *.ts)
4947
# These are regenerated via `npm run build:modules`

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
9+
### Changed
10+
11+
- **Trusted npm publishing** — Publish workflow now uses OIDC trusted publishing with `--provenance` for release-triggered publishes, eliminating the need for a long-lived `NPM_TOKEN` secret. Manual `workflow_dispatch` publishes fall back to `NPM_TOKEN`.
12+
713
## [v0.1.6] - 2026-03-27
814

915
### Added

docs/RELEASING.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,25 @@ git push origin v0.1.1
5050
The [publish workflow](../.github/workflows/publish.yml) automatically:
5151

5252
1. Runs tests on all hypervisors (KVM, MSHV, WHP)
53-
2. Publishes npm package to [npmjs.org](https://www.npmjs.com/package/@hyperlight-dev/hyperagent)
53+
2. Publishes npm package to [npmjs.org](https://www.npmjs.com/package/@hyperlight-dev/hyperagent) with [npm provenance](https://docs.npmjs.com/generating-provenance-statements) via OIDC trusted publishing
5454
3. Publishes Docker image to GitHub Container Registry (`ghcr.io/hyperlight-dev/hyperagent`)
5555

56+
#### npm Trusted Publishing
57+
58+
Release-triggered publishes use **OIDC trusted publishing** instead of an `NPM_TOKEN` secret:
59+
60+
- The workflow requests an OIDC `id-token` from GitHub Actions and exchanges it with npmjs.org
61+
- npm attaches a **provenance attestation** (`--provenance`) linking the published package to its source commit and build
62+
- No long-lived npm API key is required for release publishes
63+
64+
**Prerequisites** (one-time setup on npmjs.com):
65+
66+
1. Go to the [@hyperlight-dev/hyperagent](https://www.npmjs.com/package/@hyperlight-dev/hyperagent) package settings
67+
2. Under "Publishing access", add a GitHub Actions trusted publisher:
68+
- **Organization**: `hyperlight-dev`
69+
- **Repository**: `hyperagent`
70+
- **Workflow**: `publish.yml`
71+
5672
## Manual Release (workflow_dispatch)
5773

5874
For testing or hotfixes without creating a git tag:
@@ -61,6 +77,8 @@ For testing or hotfixes without creating a git tag:
6177
2. Enter version (e.g., `0.1.1-beta.1`)
6278
3. Click "Run workflow"
6379

80+
> **Note**: Manual dispatches fall back to the `NPM_TOKEN` repository secret (no provenance attestation). This is the emergency path only — prefer tagged releases for production.
81+
6482
## Verifying a Release
6583

6684
### npm package

0 commit comments

Comments
 (0)