Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Load a TrustRoot reference when using the policy-tester #698

Merged
merged 1 commit into from
Apr 3, 2023
Merged
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
24 changes: 24 additions & 0 deletions cmd/tester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
"sigs.k8s.io/release-utils/version"
"sigs.k8s.io/yaml"

"github.com/sigstore/policy-controller/pkg/apis/config"
"github.com/sigstore/policy-controller/pkg/apis/policy/v1alpha1"
"github.com/sigstore/policy-controller/pkg/policy"
"github.com/sigstore/policy-controller/pkg/webhook"
)
Expand All @@ -54,6 +56,7 @@ func main() {
versionFlag := flag.Bool("version", false, "return the policy-controller tester version")
image := flag.String("image", "", "image to compare against policy")
resourceFilePath := flag.String("resource", "", "path to a kubernetes resource to use with includeSpec, includeObjectMeta")
trustRootFilePath := flag.String("trustroot", "", "path to a kubernetes TrustRoot resource to use with the ClusterImagePolicy")
flag.Parse()

if *versionFlag {
Expand Down Expand Up @@ -140,6 +143,27 @@ func main() {
ctx = webhook.IncludeTypeMeta(ctx, typeMeta)
}

if *trustRootFilePath != "" {
configCtx := config.FromContextOrDefaults(ctx)
raw, err := os.ReadFile(*trustRootFilePath)
if err != nil {
log.Fatal(err)
}
tr := &v1alpha1.TrustRoot{}
if err := yaml.Unmarshal(raw, tr); err != nil {
log.Fatal(err)
}

c := &config.SigstoreKeys{}
c.ConvertFrom(context.Background(), tr.Spec.SigstoreKeys)
maps := make(map[string]config.SigstoreKeys, 0)

maps[tr.Name] = *c
configCtx.SigstoreKeysConfig = &config.SigstoreKeysMap{SigstoreKeys: maps}

ctx = config.ToContext(ctx, configCtx)
}

errStrings := []string{}
if err := vfy.Verify(ctx, ref, authn.DefaultKeychain); err != nil {
errStrings = append(errStrings, strings.Trim(err.Error(), "\n"))
Expand Down