Skip to content

Commit 88cd40e

Browse files
author
Ian Lewis
authored
feat: Use low-perms delegator for Node.js builder (#577)
Signed-off-by: Ian Lewis <[email protected]>
1 parent 5c0baa4 commit 88cd40e

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

verifiers/internal/gha/builder.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ var defaultContainerTrustedReusableWorkflows = map[string]bool{
3535
}
3636

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

3940
var defaultBYOBReusableWorkflows = map[string]bool{
40-
delegatorGenericReusableWorkflow: true,
41+
delegatorGenericReusableWorkflow: true,
42+
delegatorLowPermsGenericReusableWorkflow: true,
4143
}
4244

4345
// VerifyCertficateSourceRepository verifies the source repository.

verifiers/internal/gha/verifier.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func verifyNpmEnvAndCert(env *dsse.Envelope,
101101
// We verify against the delegator re-usable workflow, not the user-provided
102102
// builder. This is because the signing identity for delegator-based builders
103103
// is *always* the delegator workflow.
104-
expectedDelegatorWorkflow := httpsGithubCom + delegatorGenericReusableWorkflow
104+
expectedDelegatorWorkflow := httpsGithubCom + delegatorLowPermsGenericReusableWorkflow
105105
delegatorBuilderOpts := options.BuilderOpts{
106106
ExpectedID: &expectedDelegatorWorkflow,
107107
}

verifiers/utils/builder.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
serrors "github.com/slsa-framework/slsa-verifier/v2/errors"
88
)
99

10+
// TrustedBuilderID represents a builder ID that has been explicitly trusted.
1011
type TrustedBuilderID struct {
1112
name, version string
1213
}
@@ -24,7 +25,7 @@ func TrustedBuilderIDNew(builderID string, needVersion bool) (*TrustedBuilderID,
2425
}, nil
2526
}
2627

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

4041
if name != b.name {
4142
return fmt.Errorf("%w: expected name '%s', got '%s'", serrors.ErrorMismatchBuilderID,
42-
name, b.name)
43+
b.name, name)
4344
}
4445

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

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

6667
if name != b.name {
6768
return fmt.Errorf("%w: expected name '%s', got '%s'", serrors.ErrorMismatchBuilderID,
68-
name, b.name)
69+
b.name, name)
6970
}
7071

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

85+
// Name returns the trusted builder's name.
8486
func (b *TrustedBuilderID) Name() string {
8587
return b.name
8688
}
8789

90+
// Version returns the trusted builder's version reference if any.
8891
func (b *TrustedBuilderID) Version() string {
8992
return b.version
9093
}
9194

95+
// String returns the full trusted builder ID as a string.
9296
func (b *TrustedBuilderID) String() string {
9397
if b.version == "" {
9498
return b.name

0 commit comments

Comments
 (0)