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

Add skip tls verify option to kaniko builder #2976

Merged
merged 3 commits into from
Oct 3, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/content/en/schemas/v1beta16.json
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,12 @@
"x-intellij-html-description": "used to strip timestamps out of the built image.",
"default": "false"
},
"skipTLS": {
"type": "boolean",
"description": "skips TLS verification when pulling and pushing the image.",
"x-intellij-html-description": "skips TLS verification when pulling and pushing the image.",
"default": "false"
},
"target": {
"type": "string",
"description": "Dockerfile target name to build.",
Expand All @@ -1303,7 +1309,8 @@
"buildContext",
"image",
"cache",
"reproducible"
"reproducible",
"skipTLS"
],
"additionalProperties": false,
"description": "*alpha* describes an artifact built from a Dockerfile, with kaniko.",
Expand Down
17 changes: 17 additions & 0 deletions pkg/skaffold/build/cluster/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/google/go-containerregistry/pkg/name"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -139,5 +140,21 @@ func args(artifact *latest.KanikoArtifact, context, tag string) ([]string, error
args = append(args, "--reproducible")
}

if artifact.SkipTLS {
reg, err := artifactRegistry(tag)
if err != nil {
return nil, err
}
args = append(args, "--skip-tls-verify-registry", reg)
}

return args, nil
}

func artifactRegistry(i string) (string, error) {
ref, err := name.ParseReference(i)
if err != nil {
return "", err
}
return ref.Context().RegistryStr(), nil
}
26 changes: 24 additions & 2 deletions pkg/skaffold/build/cluster/kaniko_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestArgs(t *testing.T) {
tests := []struct {
description string
artifact *latest.KanikoArtifact
tag string
shouldErr bool
expectedArgs []string
}{
Expand Down Expand Up @@ -104,12 +105,33 @@ func TestArgs(t *testing.T) {
},
shouldErr: true,
},
{
priyawadhwa marked this conversation as resolved.
Show resolved Hide resolved
description: "skip tls",
artifact: &latest.KanikoArtifact{
DockerfilePath: "Dockerfile",
SkipTLS: true,
},
expectedArgs: []string{"--skip-tls-verify-registry", "gcr.io"},
},
{
description: "invalid registry",
artifact: &latest.KanikoArtifact{
DockerfilePath: "Dockerfile",
SkipTLS: true,
},
tag: "!!!!",
shouldErr: true,
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
commonArgs := []string{"--dockerfile", "Dockerfile", "--context", "context", "--destination", "tag", "-v", "info"}
commonArgs := []string{"--dockerfile", "Dockerfile", "--context", "context", "--destination", "gcr.io/tag", "-v", "info"}

args, err := args(test.artifact, "context", "tag")
tag := "gcr.io/tag"
if test.tag != "" {
tag = test.tag
}
args, err := args(test.artifact, "context", tag)

t.CheckError(test.shouldErr, err)
if !test.shouldErr {
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,9 @@ type KanikoArtifact struct {

// Reproducible is used to strip timestamps out of the built image.
Reproducible bool `yaml:"reproducible,omitempty"`

// SkipTLS skips TLS verification when pulling and pushing the image.
SkipTLS bool `yaml:"skipTLS,omitempty"`
}

// DockerArtifact *beta* describes an artifact built from a Dockerfile,
Expand Down