diff --git a/pkg/skaffold/schema/validation/validation.go b/pkg/skaffold/schema/validation/validation.go index 172af5b0ca8..b8c67aea4e9 100644 --- a/pkg/skaffold/schema/validation/validation.go +++ b/pkg/skaffold/schema/validation/validation.go @@ -189,7 +189,7 @@ func validateDockerNetworkMode(artifacts []*latest.Artifact) (errs []error) { if mode == "none" || mode == "bridge" || mode == "host" { continue } - containerRegExp := regexp.MustCompile("container:.+") + containerRegExp := regexp.MustCompile("^container:[a-zA-Z0-9][a-zA-Z0-9_.-]*$") if containerRegExp.MatchString(mode) { continue } diff --git a/pkg/skaffold/schema/validation/validation_test.go b/pkg/skaffold/schema/validation/validation_test.go index 086796e07d6..4462958e590 100644 --- a/pkg/skaffold/schema/validation/validation_test.go +++ b/pkg/skaffold/schema/validation/validation_test.go @@ -309,13 +309,54 @@ func TestValidateNetworkMode(t *testing.T) { shouldErr: true, }, { - description: "container's network stack", + description: "wrong container's network stack '-not-valid'", artifacts: []*latest.Artifact{ { ImageName: "image/container", ArtifactType: latest.ArtifactType{ DockerArtifact: &latest.DockerArtifact{ - NetworkMode: "Container:unique-identifier", + NetworkMode: "Container:-not-valid", + }, + }, + }, + }, + shouldErr: true, + }, + { + description: "wrong container's network stack 'fussball'", + artifacts: []*latest.Artifact{ + { + ImageName: "image/container", + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ + NetworkMode: "Container:fußball", + }, + }, + }, + }, + shouldErr: true, + }, + { + description: "container's network stack 'unique'", + artifacts: []*latest.Artifact{ + { + ImageName: "image/container", + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ + NetworkMode: "Container:unique", + }, + }, + }, + }, + }, + { + description: "container's network stack 'unique-id.123'", + artifacts: []*latest.Artifact{ + { + ImageName: "image/container", + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ + NetworkMode: "Container:unique-id.123", }, }, },