Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions pkg/cmd/attestation/verification/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package verification
import (
"encoding/hex"
"fmt"
"strings"

"github.com/cli/cli/v2/pkg/cmd/attestation/artifact"

Expand Down Expand Up @@ -49,3 +50,45 @@ func (c EnforcementCriteria) Valid() error {
}
return nil
}

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

policyAttr = appendStr(policyAttr, "- OIDC Issuer must match", c.Certificate.Issuer)
if c.Certificate.RunnerEnvironment == GitHubRunner {
policyAttr = appendStr(policyAttr, "- Action workflow Runner Environment must match ", GitHubRunner)
}

policyAttr = appendStr(policyAttr, "- Source Repository Owner URI must match", c.Certificate.SourceRepositoryOwnerURI)

if c.Certificate.SourceRepositoryURI != "" {
policyAttr = appendStr(policyAttr, "- Source Repository URI must match", c.Certificate.SourceRepositoryURI)
}

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

if c.SAN != "" {
policyAttr = appendStr(policyAttr, "- Subject Alternative Name must match", c.SAN)
} else if c.SANRegex != "" {
policyAttr = appendStr(policyAttr, "- Subject Alternative Name must match regex", c.SANRegex)
}

maxColLen := 0
for _, attr := range policyAttr {
if len(attr[0]) > maxColLen {
maxColLen = len(attr[0])
}
}

policyInfo := ""
for _, attr := range policyAttr {
dots := strings.Repeat(".", maxColLen-len(attr[0]))
policyInfo += fmt.Sprintf("%s:%s %s\n", attr[0], dots, attr[1])
}

return policyInfo
}

func appendStr(arr [][]string, a, b string) [][]string {
return append(arr, []string{a, b})
}
6 changes: 3 additions & 3 deletions pkg/cmd/attestation/verify/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func expandToGitHubURL(tenant, ownerOrRepo string) string {
}

func newEnforcementCriteria(opts *Options) (verification.EnforcementCriteria, error) {
var c verification.EnforcementCriteria
c := verification.EnforcementCriteria{
PredicateType: opts.PredicateType,
}

// Set SANRegex using either the opts.SignerRepo or opts.SignerWorkflow values
if opts.SignerRepo != "" {
Expand Down Expand Up @@ -80,8 +82,6 @@ func newEnforcementCriteria(opts *Options) (verification.EnforcementCriteria, er
c.Certificate.Issuer = opts.OIDCIssuer
}

c.PredicateType = opts.PredicateType

return c, nil
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/attestation/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ func runVerify(opts *Options) error {
}
attestations = filteredAttestations

opts.Logger.VerbosePrintf("Verifying attestations with predicate type: %s\n", ec.PredicateType)
// print information about the policy that will be enforced against attestations
opts.Logger.Println("\nThe following policy criteria will be enforced:")
opts.Logger.Println(ec.BuildPolicyInformation())

verified, errMsg, err := verifyAttestations(*artifact, attestations, opts.SigstoreVerifier, ec)
if err != nil {
Expand Down