Skip to content

Conversation

cometkim
Copy link
Contributor

@cometkim cometkim commented Sep 13, 2025

What's the problem this PR addresses?

Resolves #6831

How did you fix it?

Implementation adapted from https://github.com/npm/cli/blob/7d900c4656cfffc8cca93240c6cda4b441fbbfaa/lib/utils/oidc.js

You can check the published package and the provenance here: https://www.npmjs.com/package/npgi

Note: it doesn't work with the Yarn registry proxy, so it requires setting publishConfig.registry to "https://registry.npmjs.org" Fixed.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@cometkim cometkim force-pushed the npm-trusted-publish branch 2 times, most recently from c8563c6 to 8d89c74 Compare September 13, 2025 22:52
@cometkim cometkim marked this pull request as ready for review September 13, 2025 23:01
Copy link
Member

@arcanis arcanis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Left a couple of comments


declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/cli"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cli also needs to be a minor

ident,
otp: this.otp,
jsonResponse: true,
allowOidc: Boolean(env.CI && (env.GITHUB_ACTIONS || env.GITLAB)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we gain something to exposing that as an option? Shouldn't it be an implementation detail of npmHttpUtils, since only put needs it and it always wants to set it if possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically, it could be supported anywhere related to the registry if the registry provider wanted it. It's not necessarily coupled with publish or put actions.

Since this essentially involves more than two provider details (registry and runner environment), I didn't think plugin-npm was the ideal place to do it, but I wanted to avoid too many changes here.

Another approach would be to use the getNpmAuthenticationHeader hook; perhaps a plugin for each CI provider would be ideal.

import {packUtils} from '@yarnpkg/plugin-pack';
import {Command, Option, Usage, UsageError} from 'clipanion';

const {env} = process;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid making an indirection for process.env, it makes it a little more difficult to understand where a value comes from at a glance.

@cometkim
Copy link
Contributor Author

@arcanis, btw, do you have any idea why it's not working with https://registry.yarnpkg.com? I thought it was a simple HTTP proxy.

@arcanis
Copy link
Member

arcanis commented Sep 17, 2025

It's a CNAME, yes. I'm not familiar with the oidc protocol but I imagine some certificates may be attached to the hostnames and they didn't bother to do it for the Yarn hostname? Not sure.

Unfortunately these days I think GitHub tickets are the only way to get support from the folks handling the npm server 🫤

return null;

const url = new URL(process.env.ACTIONS_ID_TOKEN_REQUEST_URL);
url.searchParams.append(`audience`, `npm:${new URL(registry).host}`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. When using registry.yarnpkg.com, audience should be replaced with the original (registry.npmjs.com)

@cometkim
Copy link
Contributor Author

Ok, now it works without changing the registry URL.

https://github.com/cometkim/npgi/actions/runs/17808768531/job/50627038427

@arcanis arcanis merged commit 0964654 into yarnpkg:master Sep 18, 2025
25 of 26 checks passed
@arcanis
Copy link
Member

arcanis commented Sep 18, 2025

Released in 4.10 - thanks a lot !

@cometkim cometkim deleted the npm-trusted-publish branch September 18, 2025 11:38
arcanis pushed a commit that referenced this pull request Sep 22, 2025
## What's the problem this PR addresses?

At #6898, I made a mistake, making it not work for scoped packages.
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.

[Feature] Support for OIDC auth for npm publish

2 participants