Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: npm default runner support #495

Merged
merged 23 commits into from
Mar 2, 2023

Conversation

laurentsimon
Copy link
Contributor

@laurentsimon laurentsimon commented Feb 18, 2023

This PR adds support for the npm provenance verification. It requires some end-to-end tests in a follow-up PR.

The implementation verifies:

  1. The publish attestation
  2. The provenance attestation.

NOTE:

verifiers/internal/gha/builder.go Outdated Show resolved Hide resolved
verifiers/internal/gha/builder.go Outdated Show resolved Hide resolved
verifiers/internal/gha/npm.go Outdated Show resolved Hide resolved
Comment on lines 76 to 113
// Provenance type verification.
if !strings.HasPrefix(attestations[1].PredicateType, publishAttestationV01) {
return nil, fmt.Errorf("%w: invalid predicate type: %v. Expected %v", errrorInvalidAttestations,
attestations[1].PredicateType, publishAttestationV01)
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: If we care that the publish attestation is there, shoudn't we do anything to actually verify it? maybe provide options for it, like --publish-user or something?

Copy link
Contributor Author

@laurentsimon laurentsimon Feb 27, 2023

Choose a reason for hiding this comment

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

we verify its signature in verifyPublishAttesttationSignature(), its headers in verifyIntotoHeaders() and its content in verifyPackageName(). The --attestations-path verifies both attestations, but we may have dedicated --publish-attestation-path and --provenance-path to separate verification for each in the future.

Wdut?

Copy link
Member

@ianlewis ianlewis Feb 28, 2023

Choose a reason for hiding this comment

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

I think it's ok for now, as long as npm package verification is an experimental feature.

Though I wonder if we should require it. I'm not sure what the private npm repository experience would be like. Will we get publish attestations for all registries that support SLSA attestations? or could npm repositories support SLSA provenance attestations without necessarily creating publish attestations?

https://github.com/gh-community/npm-provenance-private-beta-community/issues/13#issuecomment-1447569734

verifiers/internal/gha/npm.go Outdated Show resolved Hide resolved
verifiers/internal/gha/npm.go Outdated Show resolved Hide resolved
verifiers/internal/gha/npm.go Show resolved Hide resolved
verifiers/internal/gha/npm.go Outdated Show resolved Hide resolved
verifiers/internal/gha/npm.go Outdated Show resolved Hide resolved
verifiers/internal/gha/npm.go Outdated Show resolved Hide resolved
cli/slsa-verifier/verify/options.go Outdated Show resolved Hide resolved
)

type VerifyNpmPackageCommand struct {
AttestationsPath string
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a real difference between this and provenance-path? The only thing is that this is supposed to be supporting JSONL (multiple provenance concat). Maybe better to just allow provenance-path to support that and converge these?

Copy link
Contributor Author

@laurentsimon laurentsimon Feb 27, 2023

Choose a reason for hiding this comment

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

I think the publish attestation is not a SLSA provenance: predicateType: https://github.com/npm/attestation/tree/main/specs/publish/v0.1 which is why I'm hesitant to hide them both under the provenance-path. There may be some uses cases where users only have a provenance file and want to verify it anyway, in which case we would support a --provenance-path, e.g. when they store provenance in a differnent registry that does not support the publish attestation.

The term "attestation" is consistent with what npm developers would be used to, as the attestations are fetched thru the npm view | jq .dist.attestations.url

I think the namespacing of verification options (verify-artifact, verify-image, verify-npm-package) lets us adjust to each ecosystem more freely.

That's the motivation, at least. Let's discuss it more.

Wdut?

Copy link
Contributor Author

@laurentsimon laurentsimon Feb 28, 2023

Choose a reason for hiding this comment

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

@ianlewis @mihaimaruseac let us know if you have thoughts on this

Copy link
Contributor

Choose a reason for hiding this comment

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

On the other hand though, a cosign attestation file alongside the artifact contains many other predicate types, not just the SLSA ones, just like this case.

I agree that the naming of attestation is actually better than provenance...

There may be some uses cases where users only have a provenance file and want to verify it anyway, in which case we would support a --provenance-path, e.g. when they store provenance in a differnent registry that does not support the publish attestation.

Ah, this is a little confusing to me then - provenance allows the SLSA provenance, and --attestation-path may be both, but at least including publish attestation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@asraa asraa Mar 1, 2023

Choose a reason for hiding this comment

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

Resolving this: let's keep this attestation-name, when we major version bump let's file an issue changing other builders to attestation-name as well?

edit: plus also allowing JSONL in all the verification commands is better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #512 for tracking.

cli/slsa-verifier/verify/verify_npm_package.go Outdated Show resolved Hide resolved
// WARNING: the default npm builder is *not* one of our trusted builders.
// We return success but no trusted builder.
return nil, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

does the issuer check need to be added like it is above?

maybe you can consolidate these codes by using a special error case when it's not a known trusted builder in the VerifyWorkflowIdentity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: consolidate. I separated VerifyBuilderIdentity() and VerifyCertficateSourceRepository().
re: issuer check was done at the start of the function

if !strings.EqualFold(id.Issuer, certOidcIssuer) {
, but I've updated the code with separate VerifyBuilderIdentity() and VerifyCertficateSourceRepository(). Let me know what you think

@asraa
Copy link
Contributor

asraa commented Feb 27, 2023

I'm a little bit concerned there is going to be three dupes of this code, our old code, and the delegator code, but we they are all different cases and it may need to be that implementing general delegator builds may need to refactor some of this later - in my view the npm builder is a special case of the delegator builds with additional verifications and check for the L2 builders.

@laurentsimon
Copy link
Contributor Author

laurentsimon commented Feb 27, 2023

I'm a little bit concerned there is going to be three dupes of this code, our old code, and the delegator code, but we they are all different cases and it may need to be that implementing general delegator builds may need to refactor some of this later - in my view the npm builder is a special case of the delegator builds with additional verifications and check for the L2 builders.

I agree I'd like to remove the duplication and re-factor the code too. I may have missed: do we already have some BYOB verification?

@asraa
Copy link
Contributor

asraa commented Feb 28, 2023

I may have missed: do we already have some BYOB verification?

Not yet: I had implemented it in the PR I staged here, but was left at generating testcases with test repositories and tagged builders.

@laurentsimon
Copy link
Contributor Author

Merging this as discussed offline. I have created issues to track some of the remaining questions. I will cut an -rc release

Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
@laurentsimon laurentsimon merged commit 82a1259 into slsa-framework:main Mar 2, 2023
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.

3 participants