Skip to content
Merged
10 changes: 10 additions & 0 deletions pkg/cmd/attestation/verification/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,15 @@ func verifyCertExtensions(given, expected certificate.Summary) error {
return fmt.Errorf("expected Issuer to be %s, got %s", expected.Issuer, given.Issuer)
}

if expected.BuildSignerDigest != "" && !strings.EqualFold(expected.BuildSignerDigest, given.BuildSignerDigest) {
return fmt.Errorf("expected BuildSignerDigest to be %s, got %s", expected.BuildSignerDigest, given.BuildSignerDigest)
}
if expected.SourceRepositoryDigest != "" && !strings.EqualFold(expected.SourceRepositoryDigest, given.SourceRepositoryDigest) {
return fmt.Errorf("expected SourceRepositoryDigest to be %s, got %s", expected.SourceRepositoryDigest, given.SourceRepositoryDigest)
}
if expected.SourceRepositoryRef != "" && !strings.EqualFold(expected.SourceRepositoryRef, given.SourceRepositoryRef) {
return fmt.Errorf("expected SourceRepositoryRef to be %s, got %s", expected.SourceRepositoryRef, given.SourceRepositoryRef)
}

return nil
}
12 changes: 11 additions & 1 deletion pkg/cmd/attestation/verification/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c EnforcementCriteria) Valid() error {
}

func (c EnforcementCriteria) BuildPolicyInformation() string {
policyAttr := make([][]string, 0, 6)
policyAttr := [][]string{}

policyAttr = appendStr(policyAttr, "- Predicate type must match", c.PredicateType)

Expand All @@ -62,6 +62,16 @@ func (c EnforcementCriteria) BuildPolicyInformation() string {
policyAttr = appendStr(policyAttr, "- Source Repository URI must match", c.Certificate.SourceRepositoryURI)
}

if c.Certificate.BuildSignerDigest != "" {
policyAttr = appendStr(policyAttr, "- Build signer digest must match", c.Certificate.BuildSignerDigest)
}
if c.Certificate.SourceRepositoryDigest != "" {
policyAttr = appendStr(policyAttr, "- Source repo digest digest must match", c.Certificate.SourceRepositoryDigest)
}
if c.Certificate.SourceRepositoryRef != "" {
policyAttr = appendStr(policyAttr, "- Source repo ref must match", c.Certificate.SourceRepositoryRef)
}

if c.SAN != "" {
policyAttr = appendStr(policyAttr, "- Subject Alternative Name must match", c.SAN)
} else if c.SANRegex != "" {
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/attestation/verify/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ type Options struct {
Repo string
SAN string
SANRegex string
SignerDigest string
SignerRepo string
SignerWorkflow string
SourceDigest string
SourceRef string
APIClient api.Client
Logger *io.Handler
OCIClient oci.Client
Expand Down
8 changes: 7 additions & 1 deletion pkg/cmd/attestation/verify/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func newEnforcementCriteria(opts *Options) (verification.EnforcementCriteria, er
// then we default to the repo option
c.SANRegex = expandToGitHubURLRegex(opts.Tenant, opts.Repo)
} else {
// if opts.Repo was not provided, we fallback to the opts.Owner value
// if opts.Repo was not provided, we fall back to the opts.Owner value
c.SANRegex = expandToGitHubURLRegex(opts.Tenant, owner)
}

Expand Down Expand Up @@ -98,6 +98,12 @@ func newEnforcementCriteria(opts *Options) (verification.EnforcementCriteria, er
c.Certificate.Issuer = opts.OIDCIssuer
}

// set the SourceRepositoryDigest, SourceRepositoryRef, and BuildSignerDigest
// extensions if the options are provided
c.Certificate.BuildSignerDigest = opts.SignerDigest
c.Certificate.SourceRepositoryDigest = opts.SourceDigest
c.Certificate.SourceRepositoryRef = opts.SourceRef

return c, nil
}

Expand Down
42 changes: 42 additions & 0 deletions pkg/cmd/attestation/verify/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,48 @@ func TestNewEnforcementCriteria(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "https://foo.com", c.Certificate.Issuer)
})

t.Run("sets Certificate.BuildSignerDigest using opts.SignerDigest", func(t *testing.T) {
opts := &Options{
ArtifactPath: artifactPath,
Owner: "wrong",
Repo: "wrong/value",
SignerDigest: "foo",
Hostname: "github.com",
}

c, err := newEnforcementCriteria(opts)
require.NoError(t, err)
require.Equal(t, "foo", c.Certificate.BuildSignerDigest)
})

t.Run("sets Certificate.SourceRepositoryDigest using opts.SourceDigest", func(t *testing.T) {
opts := &Options{
ArtifactPath: artifactPath,
Owner: "wrong",
Repo: "wrong/value",
SourceDigest: "foo",
Hostname: "github.com",
}

c, err := newEnforcementCriteria(opts)
require.NoError(t, err)
require.Equal(t, "foo", c.Certificate.SourceRepositoryDigest)
})

t.Run("sets Certificate.SourceRepositoryRef using opts.SourceRef", func(t *testing.T) {
opts := &Options{
ArtifactPath: artifactPath,
Owner: "wrong",
Repo: "wrong/value",
SourceRef: "refs/heads/main",
Hostname: "github.com",
}

c, err := newEnforcementCriteria(opts)
require.NoError(t, err)
require.Equal(t, "refs/heads/main", c.Certificate.SourceRepositoryRef)
})
}

func TestValidateSignerWorkflow(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/attestation/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ func NewVerifyCmd(f *cmdutil.Factory, runF func(*Options) error) *cobra.Command
verifyCmd.MarkFlagsMutuallyExclusive("cert-identity", "cert-identity-regex", "signer-repo", "signer-workflow")
verifyCmd.Flags().StringVarP(&opts.OIDCIssuer, "cert-oidc-issuer", "", verification.GitHubOIDCIssuer, "Issuer of the OIDC token")
verifyCmd.Flags().StringVarP(&opts.Hostname, "hostname", "", "", "Configure host to use")
verifyCmd.Flags().StringVarP(&opts.SignerDigest, "signer-digest", "", "", "Digest associated with the signer workflow")
verifyCmd.Flags().StringVarP(&opts.SourceRef, "source-ref", "", "", "Ref associated with the source workflow")
verifyCmd.Flags().StringVarP(&opts.SourceDigest, "source-digest", "", "", "Digest associated with the source workflow")

return verifyCmd
}
Expand Down