Merge pull request #10308 from malancas/attestation-verify-ref-commit-policy-opts
Add signer-digest, source-ref, and source-digest options for `gh attestation verify`
This commit is contained in:
commit
33d863f98d
6 changed files with 76 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
@ -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 != "" {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue