Skip to content

Commit 99b8cb5

Browse files
move cleanUpTrustpolicy call
Signed-off-by: Jagpreet Singh Tamber <jagpreetstamber@gmail.com>
1 parent f396630 commit 99b8cb5

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

internal/controller/helmchart_controller.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1401,8 +1401,9 @@ func (r *HelmChartReconciler) makeVerifiers(ctx context.Context, obj *helmv1.Hel
14011401
return nil, err
14021402
}
14031403

1404+
trustPolicy := notation.CleanTrustPolicy(&doc, ctrl.LoggerFrom(ctx))
14041405
defaultNotaryOciOpts := []notation.Options{
1405-
notation.WithTrustStore(&doc),
1406+
notation.WithTrustStore(trustPolicy),
14061407
notation.WithRemoteOptions(verifyOpts...),
14071408
notation.WithAuth(clientOpts.Authenticator),
14081409
notation.WithKeychain(clientOpts.Keychain),

internal/controller/ocirepository_controller.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,9 @@ func (r *OCIRepositoryReconciler) verifySignature(ctx context.Context, obj *ociv
729729

730730
verifiedResult := soci.VerificationResultFailed
731731

732+
trustPolicy := notation.CleanTrustPolicy(&doc, ctrl.LoggerFrom(ctx))
732733
defaultNotationOciOpts := []notation.Options{
733-
notation.WithTrustStore(&doc),
734+
notation.WithTrustStore(trustPolicy),
734735
notation.WithRemoteOptions(opt...),
735736
notation.WithAuth(auth),
736737
notation.WithKeychain(keychain),

internal/oci/notation/notation.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func WithInsecureRegistry(insecure bool) Options {
7171
// WithTrustStore sets the trust store configuration.
7272
func WithTrustStore(trustStore *trustpolicy.Document) Options {
7373
return func(opts *options) {
74-
opts.trustPolicy = trustStore
74+
opts.trustPolicy = cleanTrustPolicy(trustStore, opts.logger)
7575
}
7676
}
7777

@@ -165,7 +165,7 @@ func NewNotationVerifier(opts ...Options) (*NotationVerifier, error) {
165165
cert: o.rootCertificate,
166166
}
167167

168-
trustpolicy := cleanTrustPolicy(o.trustPolicy, o.logger)
168+
trustpolicy := o.trustPolicy
169169
if trustpolicy == nil {
170170
return nil, fmt.Errorf("trust policy cannot be empty")
171171
}
@@ -185,15 +185,15 @@ func NewNotationVerifier(opts ...Options) (*NotationVerifier, error) {
185185
}, nil
186186
}
187187

188-
// cleanTrustPolicy cleans the given trust policy by removing trust stores and trusted identities
188+
// CleanTrustPolicy cleans the given trust policy by removing trust stores and trusted identities
189189
// for trust policy statements that are set to skip signature verification but still have configured trust stores and/or trusted identities.
190190
// It takes a pointer to a trustpolicy.Document and a logger from the logr package as input parameters.
191191
// If the trustPolicy is nil, it returns nil.
192192
// Otherwise, it iterates over the trustPolicy.TrustPolicies and checks if each trust policy statement's
193193
// SignatureVerification.VerificationLevel is set to trustpolicy.LevelSkip.Name.
194194
// If it is, it logs a warning message and removes the trust stores and trusted identities for that trust policy statement.
195195
// Finally, it returns the modified trustPolicy.
196-
func cleanTrustPolicy(trustPolicy *trustpolicy.Document, logger logr.Logger) *trustpolicy.Document {
196+
func CleanTrustPolicy(trustPolicy *trustpolicy.Document, logger logr.Logger) *trustpolicy.Document {
197197
if trustPolicy == nil {
198198
return nil
199199
}

internal/oci/notation/notation_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func TestCleanTrustPolicy(t *testing.T) {
330330
logger := logr.New(l)
331331

332332
if tc.want == nil {
333-
cleanedPolicy := cleanTrustPolicy(nil, logger)
333+
cleanedPolicy := CleanTrustPolicy(nil, logger)
334334
if !reflect.DeepEqual(cleanedPolicy, tc.want) {
335335
t.Errorf("got %#v, want %#v", cleanedPolicy, tc.want)
336336
}
@@ -342,7 +342,7 @@ func TestCleanTrustPolicy(t *testing.T) {
342342
TrustPolicies: tc.policy,
343343
}
344344

345-
cleanedPolicy := cleanTrustPolicy(&policy, logger)
345+
cleanedPolicy := CleanTrustPolicy(&policy, logger)
346346

347347
if !reflect.DeepEqual(cleanedPolicy, tc.want) {
348348
t.Errorf("got %#v, want %#v", cleanedPolicy, tc.want)

0 commit comments

Comments
 (0)