Skip to content

Conversation

@ianlewis
Copy link

This PR adds a new --provenance-bundle flag alongside the --provenance flag for npm publish. The flag takes a file path to a file in sigstore bundle format (JSON encoded).

This allows CI builders to generate signed provenance external to the npm CLI and upload it to the npm registry along with the created package.

ianlewis and others added 4 commits March 9, 2023 06:29
This updates the `--provenance` flag to also take a string path to a
sigstore bundle in JSON format that can be uploaded with a package by
`npm publish`.

Previous functionality of specifying `--provenance` as a boolean is
preserved.

Signed-off-by: Ian Lewis <ianlewis@google.com>
Signed-off-by: Ian Lewis <ianlewis@google.com>
Signed-off-by: Ian Lewis <ianlewis@google.com>
Signed-off-by: Ian Lewis <ianlewis@google.com>
@ianlewis ianlewis marked this pull request as ready for review March 29, 2023 03:17
@ianlewis ianlewis requested a review from a team as a code owner March 29, 2023 03:17
@ianlewis ianlewis requested review from lukekarrys and removed request for a team March 29, 2023 03:17
Comment on lines +142 to +147
if (provenance === true && provenanceBundle) {
throw Object.assign(
new Error('--provenance and --provenance-bundle cannot be specified at the same time.'),
{ code: 'EUSAGE' }
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems confusing - if they're mutually exclusive, why not --provenance=path/to/bundle?

Copy link
Author

@ianlewis ianlewis Mar 29, 2023

Choose a reason for hiding this comment

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

I did try this. However, I wanted to preserve the existing --provenance boolean, and npm seems finicky about its flags. If I create a flag that can be a boolean or string then npm publish --provenance package-name will no longer work and parse package-name as the argument to --provenance.

@wraithgar
Copy link
Member

This is not the direction we are going w/ this flag. We need to fix the bug where we can't configure a flag to be either a boolean or a string, and use that flag for this purpose. The fix is in #6020 (I think? Someone used copilot to "fix" the PR and now it's pretty unreadable).

@wraithgar
Copy link
Member

The original provenance PR did have this functionality and that is how we found the config bug, so it was paused till we can fix it.

@wraithgar wraithgar closed this Mar 29, 2023
@ianlewis
Copy link
Author

The original provenance PR did have this functionality and that is how we found the config bug, so it was paused till we can fix it.

Just to be clear, Is it fair to say we still want to add the functionality once the config bug is fixed and we just don't want it to be a separate flag?

@wraithgar
Copy link
Member

Just to be clear, Is it fair to say we still want to add the functionality once the config bug is fixed and we just don't want it to be a separate flag?

Yes the end goal is for you to be able to go --provenance or --provenance=/tmp/build/foo-1.2.0.output

@ianlewis
Copy link
Author

Just to be clear, Is it fair to say we still want to add the functionality once the config bug is fixed and we just don't want it to be a separate flag?

Yes the end goal is for you to be able to go --provenance or --provenance=/tmp/build/foo-1.2.0.output

I created #6313 to explain the flag parsing issue. This is unfortunately blocking me from adding publishing support to https://github.com/slsa-framework/slsa-github-generator.

I think this will also require changes to nopt since flags are not parsed correctly if they could be a boolean or something else like a string. i.e. npm publish --provenance --help would not work as --help would get parsed an argument to --provenance rather than handled as a flag itself`. I think most flag parsing libraries don't allow this so they don't have to handle cases like this.

@bdehamer
Copy link
Contributor

@ianlewis just an FYI that this work is continuing here.

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.

4 participants