@@ -36,100 +36,54 @@ var defaultBYOBReusableWorkflows = map[string]bool{
36
36
trustedBuilderRepository + "/.github/workflows/delegator_generic_slsa3.yml" : true ,
37
37
}
38
38
39
- // VerifyWorkflowIdentity verifies the signing certificate information
40
- // Builder IDs are verified against an expected builder ID provided in the
41
- // builerOpts, or against the set of defaultBuilders provided.
42
- func VerifyWorkflowIdentity (id * WorkflowIdentity ,
43
- builderOpts * options.BuilderOpts , source string ,
44
- defaultBuilders map [string ]bool ,
45
- ) (* utils.TrustedBuilderID , error ) {
46
- // cert URI path is /org/repo/path/to/workflow@ref
47
- workflowPath := strings .SplitN (id .JobWobWorkflowRef , "@" , 2 )
48
- if len (workflowPath ) < 2 {
49
- return nil , fmt .Errorf ("%w: workflow uri: %s" , serrors .ErrorMalformedURI , id .JobWobWorkflowRef )
50
- }
51
-
52
- // Verify trusted workflow.
53
- reusableWorkflowPath := strings .Trim (workflowPath [0 ], "/" )
54
- reusableWorkflowTag := strings .Trim (workflowPath [1 ], "/" )
55
- builderID , err := verifyTrustedBuilderID (reusableWorkflowPath , reusableWorkflowTag ,
56
- builderOpts .ExpectedID , defaultBuilders )
57
- if err != nil {
58
- return nil , err
59
- }
60
-
61
- // Verify the ref is a full semantic version tag.
62
- if err := verifyTrustedBuilderRef (id , reusableWorkflowTag ); err != nil {
63
- return nil , err
64
- }
65
-
66
- // Issuer verification.
67
- if id .Issuer != certOidcIssuer {
68
- return nil , fmt .Errorf ("%w: %s" , serrors .ErrorInvalidOIDCIssuer , id .Issuer )
69
- }
70
-
39
+ // VerifyCertficateSourceRepository verifies the source repository.
40
+ func VerifyCertficateSourceRepository (id * WorkflowIdentity ,
41
+ sourceRepo string ,
42
+ ) error {
71
43
// The caller repository in the x509 extension is not fully qualified. It only contains
72
44
// {org}/{repository}.
73
- expectedSource := strings .TrimPrefix (source , "git+https://" )
45
+ expectedSource := strings .TrimPrefix (sourceRepo , "git+https://" )
74
46
expectedSource = strings .TrimPrefix (expectedSource , "github.com/" )
75
47
if id .CallerRepository != expectedSource {
76
- return nil , fmt .Errorf ("%w: expected source '%s', got '%s'" , serrors .ErrorMismatchSource ,
48
+ return fmt .Errorf ("%w: expected source '%s', got '%s'" , serrors .ErrorMismatchSource ,
77
49
expectedSource , id .CallerRepository )
78
50
}
79
-
80
- // Return the builder and its tag.
81
- // Note: the tag has the format `refs/tags/v1.2.3`.
82
- return builderID , nil
51
+ return nil
83
52
}
84
53
85
- // VerifyNpmWorkflowIdentity verifies the signing certificate information
86
- // Any builder ID is allowed, but it must match the source repo as well
87
- // in the provenance.
88
- func VerifyNpmWorkflowIdentity (id * WorkflowIdentity , source string ,
54
+ // VerifyBuilderIdentity verifies the signing certificate information
55
+ // Builder IDs are verified against an expected builder ID provided in the
56
+ // builerOpts, or against the set of defaultBuilders provided.
57
+ func VerifyBuilderIdentity (id * WorkflowIdentity ,
58
+ builderOpts * options.BuilderOpts ,
89
59
defaultBuilders map [string ]bool ,
90
60
) (* utils.TrustedBuilderID , error ) {
91
- // cert URI path is /org/repo/path/to/workflow@ref
92
- workflowPath := strings .SplitN (id .JobWobWorkflowRef , "@" , 2 )
93
- if len (workflowPath ) < 2 {
94
- return nil , fmt .Errorf ("%w: workflow uri: %s" , serrors .ErrorMalformedURI , id .JobWobWorkflowRef )
95
- }
96
-
97
61
// Issuer verification.
98
- if ! strings .EqualFold (id .Issuer , certOidcIssuer ) {
62
+ // NOTE: this is necessary before we do any further verification.
63
+ if id .Issuer != certOidcIssuer {
99
64
return nil , fmt .Errorf ("%w: %s" , serrors .ErrorInvalidOIDCIssuer , id .Issuer )
100
65
}
101
66
102
- // The caller repository in the x509 extension is not fully qualified. It only contains
103
- // {org}/{repository}.
104
- expectedSource := strings .TrimPrefix (source , "git+https://" )
105
- expectedSource = strings .TrimPrefix (expectedSource , "github.com/" )
106
- if ! strings .EqualFold (id .CallerRepository , expectedSource ) {
107
- return nil , fmt .Errorf ("%w: expected source '%s', got '%s'" , serrors .ErrorMismatchSource ,
108
- expectedSource , id .CallerRepository )
67
+ // cert URI path is /org/repo/path/to/workflow@ref
68
+ workflowPath := strings .SplitN (id .JobWobWorkflowRef , "@" , 2 )
69
+ if len (workflowPath ) < 2 {
70
+ return nil , fmt .Errorf ("%w: workflow uri: %s" , serrors .ErrorMalformedURI , id .JobWobWorkflowRef )
109
71
}
110
72
111
73
// Verify trusted workflow.
112
74
reusableWorkflowPath := strings .Trim (workflowPath [0 ], "/" )
113
75
reusableWorkflowTag := strings .Trim (workflowPath [1 ], "/" )
114
- // No expected builder ID verification in the certificate:
115
- // 1. It's either one of our trusted builders.
116
- // 2. Or it's any workflow in a repo.
117
76
builderID , err := verifyTrustedBuilderID (reusableWorkflowPath , reusableWorkflowTag ,
118
- nil , defaultBuilders )
77
+ builderOpts . ExpectedID , defaultBuilders )
119
78
if err != nil {
120
- // WARNING: the default npm builder is *not* one of our trusted builders.
121
- // We return success but no trusted builder.
122
- return nil , nil
79
+ return nil , err
123
80
}
124
81
125
- // This is one of our trusted reusable workflows.
126
82
// Verify the ref is a full semantic version tag.
127
83
if err := verifyTrustedBuilderRef (id , reusableWorkflowTag ); err != nil {
128
84
return nil , err
129
85
}
130
86
131
- // Return the builder and its tag.
132
- // Note: the tag has the format `refs/tags/v1.2.3`.
133
87
return builderID , nil
134
88
}
135
89
0 commit comments