diff options
author | Miloslav Trmač <mitr@redhat.com> | 2022-08-24 19:39:11 +0200 |
---|---|---|
committer | Miloslav Trmač <mitr@redhat.com> | 2022-08-25 01:50:43 +0200 |
commit | e2d1bdd1d8c10617818e5805330c54523580b647 (patch) | |
tree | 65911731b1d3ea8074fd2f32940fb10bbd40766b /pkg/trust/policy.go | |
parent | cbdbb025a3f6e6e5417cdade032075d679842056 (diff) | |
download | podman-e2d1bdd1d8c10617818e5805330c54523580b647.tar.gz podman-e2d1bdd1d8c10617818e5805330c54523580b647.tar.bz2 podman-e2d1bdd1d8c10617818e5805330c54523580b647.zip |
Improve validation of data in ImageEngine.SetTrust
- Also reject public keys with types that don't use them
- Reject unknown trust types
- And add unit tests
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'pkg/trust/policy.go')
-rw-r--r-- | pkg/trust/policy.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/pkg/trust/policy.go b/pkg/trust/policy.go index 352be781c..df4f49ff1 100644 --- a/pkg/trust/policy.go +++ b/pkg/trust/policy.go @@ -143,10 +143,22 @@ func AddPolicyEntries(policyPath string, input AddPolicyEntriesInput) error { if trustType == "accept" { trustType = "insecureAcceptAnything" } - pubkeysfile := input.PubKeyFiles - if len(pubkeysfile) == 0 && trustType == "signedBy" { - return errors.New("at least one public key must be defined for type 'signedBy'") + + // The error messages in validation failures use input.Type instead of trustType to match the user’s input. + switch trustType { + case "insecureAcceptAnything", "reject": + if len(pubkeysfile) != 0 { + return fmt.Errorf("%d public keys unexpectedly provided for trust type %v", len(pubkeysfile), input.Type) + } + + case "signedBy": + if len(pubkeysfile) == 0 { + return errors.New("at least one public key must be defined for type 'signedBy'") + } + + default: + return fmt.Errorf("unknown trust type %q", input.Type) } _, err := os.Stat(policyPath) |