Skip to content

Commit

Permalink
cosigned: Test unsupported KMS providers
Browse files Browse the repository at this point in the history
This adds a test case to cover the case where a specified KMS provider
isn't supported; in this case, we fire an event describing the error.

Signed-off-by: Jason Hall <jason@chainguard.dev>
  • Loading branch information
imjasonh committed Apr 30, 2022
1 parent d2d7464 commit 04aa0b0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
2 changes: 0 additions & 2 deletions go.sum
Expand Up @@ -235,8 +235,6 @@ github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdII
github.com/OpenPeeDeeP/depguard v1.0.1/go.mod h1:xsIw86fROiiwelg+jB2uM9PiKihMMmUx/1V+TNhjQvM=
github.com/PaesslerAG/gval v1.0.0 h1:GEKnRwkWDdf9dOmKcNrar9EA1bz1z9DqPIO1+iLzhd8=
github.com/PaesslerAG/gval v1.0.0/go.mod h1:y/nm5yEyTeX6av0OfKJNp9rBNj2XrGhAf5+v24IBN1I=
github.com/PaesslerAG/gval v1.0.0/go.mod h1:y/nm5yEyTeX6av0OfKJNp9rBNj2XrGhAf5+v24IBN1I=
github.com/PaesslerAG/jsonpath v0.1.0/go.mod h1:4BzmtoM/PI8fPO4aQGIusjGxGir2BzcV0grWtFzq1Y8=
github.com/PaesslerAG/jsonpath v0.1.0/go.mod h1:4BzmtoM/PI8fPO4aQGIusjGxGir2BzcV0grWtFzq1Y8=
github.com/PaesslerAG/jsonpath v0.1.1 h1:c1/AToHQMVsduPAa4Vh6xp2U0evy4t8SWp8imEsylIk=
github.com/PaesslerAG/jsonpath v0.1.1/go.mod h1:lVboNxFGal/VwW6d9JzIy56bUsYAP6tH/x80vjnCseY=
Expand Down
16 changes: 7 additions & 9 deletions pkg/reconciler/clusterimagepolicy/clusterimagepolicy.go
Expand Up @@ -155,16 +155,14 @@ func (r *Reconciler) inlinePublicKeys(ctx context.Context, cip *v1alpha1.Cluster
return nil, err
}
}
if authority.Key != nil && authority.Key.KMS != "" {
if strings.Contains(authority.Key.KMS, "://") {
pubKeyString, err := getKMSPublicKey(ctx, authority.Key.KMS)
if err != nil {
return nil, err
}

authority.Key.Data = pubKeyString
authority.Key.KMS = ""
if authority.Key != nil && strings.Contains(authority.Key.KMS, "://") {
pubKeyString, err := getKMSPublicKey(ctx, authority.Key.KMS)
if err != nil {
return nil, err
}

authority.Key.Data = pubKeyString
authority.Key.KMS = ""
}
}
return ret, nil
Expand Down
32 changes: 29 additions & 3 deletions pkg/reconciler/clusterimagepolicy/clusterimagepolicy_test.go
Expand Up @@ -511,8 +511,9 @@ func TestReconcile(t *testing.T) {
AssertTrackingSecret(system.Namespace(), keylessSecretName),
},
}, {
Name: "ClusterImagePolicy with glob and KMS key, added the data after querying the fake signer",
Key: cipKMSName,
Name: "ClusterImagePolicy with glob and KMS key, added the data after querying the fake signer",
Key: cipKMSName,

SkipNamespaceValidation: true, // Cluster scoped
Objects: []runtime.Object{
NewClusterImagePolicy(cipKMSName,
Expand Down Expand Up @@ -557,7 +558,32 @@ func TestReconcile(t *testing.T) {
WantPatches: []clientgotesting.PatchActionImpl{
makePatch(replaceCIPKeySourcePatch),
},
}, {}}
}, {
Name: "ClusterImagePolicy with glob and KMS key, for unsupported KMS provider",
Key: cipKMSName,

SkipNamespaceValidation: true, // Cluster scoped
Objects: []runtime.Object{
NewClusterImagePolicy(cipKMSName,
WithImagePattern(v1alpha1.ImagePattern{
Glob: glob,
}),
WithAuthority(v1alpha1.Authority{
Key: &v1alpha1.KeyRef{
KMS: "unsupported://blah",
}},
)),
makeEmptyConfigMap(), // Make the existing configmap
},
WantErr: true,
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(system.Namespace(), cipKMSName),
},
WantEvents: []string{
Eventf(corev1.EventTypeNormal, "FinalizerUpdate", `Updated "test-kms-cip" finalizers`),
Eventf(corev1.EventTypeWarning, "InternalError", `no kms provider found for key reference: unsupported://blah`),
},
}}

logger := logtesting.TestLogger(t)
table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler {
Expand Down

0 comments on commit 04aa0b0

Please sign in to comment.