Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verify-signature: fixed (in)secure transport #17202

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/oc/admin/image/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"github.com/docker/distribution/digest"

"k8s.io/client-go/rest"

"github.com/openshift/origin/pkg/image/importer"
)

Expand All @@ -18,7 +20,12 @@ func getImageManifestByIDFromRegistry(registry *url.URL, repositoryName, imageID
credentials := importer.NewBasicCredentials()
credentials.Add(registry, username, password)

repo, err := importer.NewContext(http.DefaultTransport, http.DefaultTransport).
insecureRT, err := rest.TransportFor(&rest.Config{TLSClientConfig: rest.TLSClientConfig{Insecure: true}})
if err != nil {
return nil, err
}

repo, err := importer.NewContext(http.DefaultTransport, insecureRT).
WithCredentials(credentials).
Repository(ctx, registry, repositoryName, insecure)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/admin/image/verify-signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (o *VerifyImageSignatureOptions) getImageManifest(img *imageapi.Image) ([]b
if len(o.RegistryURL) > 0 {
registryURL = &url.URL{Host: o.RegistryURL, Scheme: "https"}
if o.Insecure {
registryURL.Scheme = "http"
registryURL.Scheme = ""
}
}
return getImageManifestByIDFromRegistry(registryURL, parsed.RepositoryName(), img.Name, o.CurrentUser, o.CurrentUserToken, o.Insecure)
Expand Down
29 changes: 23 additions & 6 deletions test/extended/registry/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package registry

import (
"fmt"
"strings"

g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
Expand All @@ -12,7 +13,7 @@ import (
e2e "k8s.io/kubernetes/test/e2e/framework"
)

var _ = g.Describe("[imageapis][registry][Skipped][Serial] image signature workflow", func() {
var _ = g.Describe("[imageapis][registry][Serial] image signature workflow", func() {

defer g.GinkgoRecover()

Expand All @@ -22,7 +23,6 @@ var _ = g.Describe("[imageapis][registry][Skipped][Serial] image signature workf
)

g.It("can push a signed image to openshift registry and verify it", func() {
g.Skip("FIXME: fix oadm verify-image-signature to work with secured registry")
g.By("building a signer image that knows how to sign images")
output, err := oc.Run("create").Args("-f", signerBuildFixture).Output()
if err != nil {
Expand Down Expand Up @@ -86,8 +86,17 @@ var _ = g.Describe("[imageapis][registry][Skipped][Serial] image signature workf
// Sign and copy the origin-pod image into target image stream tag
// TODO: Fix skopeo to pickup the Kubernetes environment variables (remove the $KUBERNETES_MASTER)
g.By("signing the origin-pod:latest image and pushing it into openshift registry")
_, err = pod.Exec("KUBERNETES_MASTER=https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT GNUPGHOME=/var/lib/origin/gnupg " +
"skopeo --debug --tls-verify=false copy --sign-by joe@foo.bar --dest-creds " + user + ":" + token + " --dest-tls-verify=false docker://docker.io/openshift/origin-pod:latest atomic:" + signedImage)
out, err = pod.Exec(strings.Join([]string{
"KUBERNETES_MASTER=https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT",
"GNUPGHOME=/var/lib/origin/gnupg",
"skopeo", "--debug", "copy", "--sign-by", "joe@foo.bar",
"--dest-creds=" + user + ":" + token,
// TODO: test with this turned to true as well
"--dest-tls-verify=false",
"docker://docker.io/openshift/origin-pod:latest",
"atomic:" + signedImage,
}, " "))
fmt.Fprintf(g.GinkgoWriter, "output: %s\n", out)
o.Expect(err).NotTo(o.HaveOccurred())

err = exutil.WaitForAnImageStreamTag(oc, oc.Namespace(), "signed", "latest")
Expand All @@ -102,8 +111,16 @@ var _ = g.Describe("[imageapis][registry][Skipped][Serial] image signature workf
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("Unverified"))

out, err = pod.Exec("GNUPGHOME=/var/lib/origin/gnupg " +
"oc adm verify-image-signature " + imageName + " --expected-identity=" + signedImage + " --save")
out, err = pod.Exec(strings.Join([]string{
"GNUPGHOME=/var/lib/origin/gnupg",
"oc", "adm", "verify-image-signature",
"--insecure=true", // TODO: import the ca certificate into the signing pod
"--loglevel=5",
imageName,
"--expected-identity=" + signedImage,
" --save",
}, " "))
fmt.Fprintf(g.GinkgoWriter, "output: %s\n", out)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("identity is now confirmed"))

Expand Down