Skip to content

Commit

Permalink
feat: Use low-perms delegator for Node.js builder (#577)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Lewis <ianlewis@google.com>
  • Loading branch information
ianlewis committed May 1, 2023
1 parent 5c0baa4 commit 88cd40e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion verifiers/internal/gha/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ var defaultContainerTrustedReusableWorkflows = map[string]bool{
}

var delegatorGenericReusableWorkflow = trustedBuilderRepository + "/.github/workflows/delegator_generic_slsa3.yml"
var delegatorLowPermsGenericReusableWorkflow = trustedBuilderRepository + "/.github/workflows/delegator_lowperms-generic_slsa3.yml"

var defaultBYOBReusableWorkflows = map[string]bool{
delegatorGenericReusableWorkflow: true,
delegatorGenericReusableWorkflow: true,
delegatorLowPermsGenericReusableWorkflow: true,
}

// VerifyCertficateSourceRepository verifies the source repository.
Expand Down
2 changes: 1 addition & 1 deletion verifiers/internal/gha/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func verifyNpmEnvAndCert(env *dsse.Envelope,
// We verify against the delegator re-usable workflow, not the user-provided
// builder. This is because the signing identity for delegator-based builders
// is *always* the delegator workflow.
expectedDelegatorWorkflow := httpsGithubCom + delegatorGenericReusableWorkflow
expectedDelegatorWorkflow := httpsGithubCom + delegatorLowPermsGenericReusableWorkflow
delegatorBuilderOpts := options.BuilderOpts{
ExpectedID: &expectedDelegatorWorkflow,
}
Expand Down
12 changes: 8 additions & 4 deletions verifiers/utils/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
serrors "github.com/slsa-framework/slsa-verifier/v2/errors"
)

// TrustedBuilderID represents a builder ID that has been explicitly trusted.
type TrustedBuilderID struct {
name, version string
}
Expand All @@ -24,7 +25,7 @@ func TrustedBuilderIDNew(builderID string, needVersion bool) (*TrustedBuilderID,
}, nil
}

// Matches matches the builderID string against the reference builderID.
// MatchesLoose matches the builderID string against the reference builderID.
// If the builderID contains a semver, the full builderID must match.
// Otherwise, only the name needs to match.
// `allowRef: true` indicates that the matching need not be an eaxct
Expand All @@ -39,7 +40,7 @@ func (b *TrustedBuilderID) MatchesLoose(builderID string, allowRef bool) error {

if name != b.name {
return fmt.Errorf("%w: expected name '%s', got '%s'", serrors.ErrorMismatchBuilderID,
name, b.name)
b.name, name)
}

if version != "" && version != b.version {
Expand All @@ -55,7 +56,7 @@ func (b *TrustedBuilderID) MatchesLoose(builderID string, allowRef bool) error {
return nil
}

// Matches matches the builderID string against the reference builderID.
// MatchesFull matches the builderID string against the reference builderID.
// Both the name and versions are always verified.
func (b *TrustedBuilderID) MatchesFull(builderID string, allowRef bool) error {
name, version, err := ParseBuilderID(builderID, false)
Expand All @@ -65,7 +66,7 @@ func (b *TrustedBuilderID) MatchesFull(builderID string, allowRef bool) error {

if name != b.name {
return fmt.Errorf("%w: expected name '%s', got '%s'", serrors.ErrorMismatchBuilderID,
name, b.name)
b.name, name)
}

if version != b.version {
Expand All @@ -81,14 +82,17 @@ func (b *TrustedBuilderID) MatchesFull(builderID string, allowRef bool) error {
return nil
}

// Name returns the trusted builder's name.
func (b *TrustedBuilderID) Name() string {
return b.name
}

// Version returns the trusted builder's version reference if any.
func (b *TrustedBuilderID) Version() string {
return b.version
}

// String returns the full trusted builder ID as a string.
func (b *TrustedBuilderID) String() string {
if b.version == "" {
return b.name
Expand Down

0 comments on commit 88cd40e

Please sign in to comment.