-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add end-to-end tests for Builder/ClusterBuilder signing.
Add a new test suite to the end-to-end tests to verify that once a Builder or ClusterBuilder is created, if a cosign secret is present, then the image will be signed and the signature will be verifiable.
- Loading branch information
1 parent
4bcac5e
commit 10108d0
Showing
3 changed files
with
706 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package cosign | ||
|
||
import ( | ||
"context" | ||
"crypto" | ||
cosignVerify "github.com/sigstore/cosign/v2/cmd/cosign/cli/verify" | ||
"github.com/sigstore/cosign/v2/pkg/cosign" | ||
"github.com/sigstore/cosign/v2/pkg/signature" | ||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"testing" | ||
) | ||
|
||
func GenerateFakeKeyPair(t *testing.T, secretName string, secretNamespace string, password string, annotations map[string]string) corev1.Secret { | ||
t.Helper() | ||
|
||
passFunc := func(_ bool) ([]byte, error) { | ||
return []byte(password), nil | ||
} | ||
|
||
keys, err := cosign.GenerateKeyPair(passFunc) | ||
require.NoError(t, err) | ||
|
||
data := map[string][]byte{ | ||
SecretDataCosignPublicKey: keys.PublicBytes, | ||
SecretDataCosignKey: keys.PrivateBytes, | ||
SecretDataCosignPassword: []byte(password), | ||
} | ||
|
||
secret := corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: secretName, | ||
Namespace: secretNamespace, | ||
Annotations: annotations, | ||
}, | ||
Data: data, | ||
} | ||
|
||
return secret | ||
} | ||
|
||
func Verify(t *testing.T, keyRef, imageRef string, annotations map[string]interface{}) error { | ||
t.Helper() | ||
|
||
cmd := cosignVerify.VerifyCommand{ | ||
KeyRef: keyRef, | ||
Annotations: signature.AnnotationsMap{Annotations: annotations}, | ||
CheckClaims: true, | ||
HashAlgorithm: crypto.SHA256, | ||
IgnoreTlog: true, | ||
} | ||
|
||
args := []string{imageRef} | ||
|
||
return cmd.Exec(context.Background(), args) | ||
} |
Oops, something went wrong.