-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor insecure registry E2E tests (#3701)
* Fix e2e test copypaste error Signed-off-by: Colleen Murphy <colleenmurphy@google.com> * Clean up kind-e2e-insecure-registry workflow - These tests don't use KinD, don't set it up - Don't install yq, ko, or kustomize - The scripts build cosign, no need to build it in its own step - Don't use global environment variables when they're only needed for individual steps Signed-off-by: Colleen Murphy <colleenmurphy@google.com> * Move insecure OCI 1.0 registry tests to Go suite Signed-off-by: Colleen Murphy <colleenmurphy@google.com> * Move insecure OCI 1.1 registry tests to Go suite Signed-off-by: Colleen Murphy <colleenmurphy@google.com> * Make registry tests hermetic Signed-off-by: Colleen Murphy <colleenmurphy@google.com> * Move insecure registry workflow to e2e tests Condense the kind-e2e-insecure-registry workflow into the rest of the E2E tests workflow. The workflow name was misleading because these tests don't relate to KinD except as an implementation detail of the scaffolding action. Combining it makes it more discoverable and reduces clutter inthe GitHub Actions UI. Signed-off-by: Colleen Murphy <colleenmurphy@google.com> --------- Signed-off-by: Colleen Murphy <colleenmurphy@google.com>
- Loading branch information
Showing
7 changed files
with
233 additions
and
254 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 was deleted.
Oops, something went wrong.
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,125 @@ | ||
// Copyright 2024 The Sigstore Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//go:build e2e && registry | ||
|
||
package test | ||
|
||
import ( | ||
"context" | ||
"crypto/tls" | ||
"net/http" | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/google/go-containerregistry/pkg/name" | ||
"github.com/google/go-containerregistry/pkg/v1/random" | ||
"github.com/google/go-containerregistry/pkg/v1/remote" | ||
"github.com/sigstore/cosign/v2/cmd/cosign/cli/options" | ||
"github.com/sigstore/cosign/v2/cmd/cosign/cli/sign" | ||
cliverify "github.com/sigstore/cosign/v2/cmd/cosign/cli/verify" | ||
"github.com/sigstore/cosign/v2/pkg/cosign/env" | ||
ociremote "github.com/sigstore/cosign/v2/pkg/oci/remote" | ||
) | ||
|
||
const ( | ||
oci11Var = "OCI11" | ||
rekorURLVar = "REKOR_URL" | ||
) | ||
|
||
func TestInsecureRegistry(t *testing.T) { | ||
if os.Getenv("COSIGN_TEST_REPO") == "" { | ||
t.Fatal("COSIGN_TEST_REPO must be set to an insecure registry for this test") | ||
} | ||
repo, stop := reg(t) | ||
defer stop() | ||
td := t.TempDir() | ||
|
||
imgName := path.Join(repo, "cosign-registry-e2e") | ||
cleanup := makeImageIndexWithInsecureRegistry(t, imgName) | ||
defer cleanup() | ||
|
||
_, privKey, pubKey := keypair(t, td) | ||
|
||
useOCI11 := os.Getenv("oci11Var") != "" | ||
|
||
rekorURL := os.Getenv(rekorURLVar) | ||
must(downloadAndSetEnv(t, rekorURL+"/api/v1/log/publicKey", env.VariableSigstoreRekorPublicKey.String(), td), t) | ||
|
||
ko := options.KeyOpts{ | ||
KeyRef: privKey, | ||
PassFunc: passFunc, | ||
RekorURL: rekorURL, | ||
SkipConfirmation: true, | ||
} | ||
so := options.SignOptions{ | ||
Upload: true, | ||
TlogUpload: true, | ||
} | ||
mustErr(sign.SignCmd(ro, ko, so, []string{imgName}), t) | ||
so.Registry = options.RegistryOptions{ | ||
AllowInsecure: true, | ||
} | ||
if useOCI11 { | ||
so.RegistryExperimental = options.RegistryExperimentalOptions{ | ||
RegistryReferrersMode: options.RegistryReferrersModeOCI11, | ||
} | ||
} | ||
must(sign.SignCmd(ro, ko, so, []string{imgName}), t) | ||
mustErr(verify(pubKey, imgName, true, nil, "", false), t) | ||
cmd := cliverify.VerifyCommand{ | ||
KeyRef: pubKey, | ||
CheckClaims: true, | ||
RegistryOptions: options.RegistryOptions{ | ||
AllowInsecure: true, | ||
}, | ||
} | ||
if useOCI11 { | ||
cmd.ExperimentalOCI11 = true | ||
} | ||
must(cmd.Exec(context.Background(), []string{imgName}), t) | ||
} | ||
|
||
func makeImageIndexWithInsecureRegistry(t *testing.T, n string) func() { | ||
ref, err := name.ParseReference(n, name.WeakValidation) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
index, err := random.Index(512, 1, 0) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
regClientOpts := registryClientOpts(context.Background()) | ||
// Add TLS config to allow us to push the image to the insecure registry | ||
insecureTransport := &http.Transport{ | ||
TLSClientConfig: &tls.Config{ | ||
InsecureSkipVerify: true, | ||
}, | ||
} | ||
regClientOpts = append(regClientOpts, remote.WithTransport(insecureTransport)) | ||
if err := remote.WriteIndex(ref, index, regClientOpts...); err != nil { | ||
t.Fatal(err) | ||
} | ||
remoteImage, err := remote.Get(ref, regClientOpts...) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
cleanup := func() { | ||
_ = remote.Delete(ref, regClientOpts...) | ||
ref, _ := ociremote.SignatureTag(ref.Context().Digest(remoteImage.Descriptor.Digest.String()), ociremote.WithRemoteOptions(regClientOpts...)) | ||
_ = remote.Delete(ref, regClientOpts...) | ||
} | ||
return cleanup | ||
} |
Oops, something went wrong.