diff --git a/images/image-user/Dockerfile b/images/image-user/Dockerfile new file mode 100644 index 0000000000..406344881a --- /dev/null +++ b/images/image-user/Dockerfile @@ -0,0 +1,17 @@ +# Copyright 2018 The Kubernetes 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. + +FROM busybox +ARG USER +USER ${USER} diff --git a/images/image-user/Makefile b/images/image-user/Makefile new file mode 100644 index 0000000000..7b53f59164 --- /dev/null +++ b/images/image-user/Makefile @@ -0,0 +1,33 @@ +# Copyright 2018 The Kubernetes 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. + +.PHONY: all test-image-user-uid test-image-user-username test-image-user-uid-group test-image-user-username-group + +all: test-image-user-uid test-image-user-username test-image-user-uid-group test-image-user-username-group + +test-image-user-uid: + docker build . -t gcr.io/cri-tools/$@ --build-arg USER=1002 + gcloud docker -- push gcr.io/cri-tools/$@ + +test-image-user-username: + docker build . -t gcr.io/cri-tools/$@ --build-arg USER=www-data + gcloud docker -- push gcr.io/cri-tools/$@ + +test-image-user-uid-group: + docker build . -t gcr.io/cri-tools/$@ --build-arg USER=1003:users + gcloud docker -- push gcr.io/cri-tools/$@ + +test-image-user-username-group: + docker build . -t gcr.io/cri-tools/$@ --build-arg USER=www-data:100 + gcloud docker -- push gcr.io/cri-tools/$@ diff --git a/pkg/validate/image.go b/pkg/validate/image.go index 8afe254735..0aa203f46a 100644 --- a/pkg/validate/image.go +++ b/pkg/validate/image.go @@ -17,6 +17,7 @@ limitations under the License. package validate import ( + "fmt" "sort" "github.com/kubernetes-incubator/cri-tools/pkg/framework" @@ -36,6 +37,15 @@ const ( // digested reference for test image testImageWithDigest = "gcr.io/cri-tools/test-image-digest@sha256:9179135b4b4cc5a8721e09379244807553c318d92fa3111a65133241551ca343" + + testImageUserUID = "gcr.io/cri-tools/test-image-user-uid" + imageUserUID = int64(1002) + testImageUserUsername = "gcr.io/cri-tools/test-image-user-username" + imageUserUsername = "www-data" + testImageUserUIDGroup = "gcr.io/cri-tools/test-image-user-uid-group" + imageUserUIDGroup = int64(1003) + testImageUserUsernameGroup = "gcr.io/cri-tools/test-image-user-username-group" + imageUserUsernameGroup = "www-data" ) var _ = framework.KubeDescribe("Image Manager", func() { @@ -66,6 +76,47 @@ var _ = framework.KubeDescribe("Image Manager", func() { }) }) + It("image status get image fields should not have Uid|Username empty [Conformance]", func() { + for _, item := range []struct { + description string + image string + uid int64 + username string + }{ + { + description: "UID only", + image: testImageUserUID, + uid: imageUserUID, + username: "", + }, + { + description: "Username only", + image: testImageUserUsername, + uid: int64(0), + username: imageUserUsername, + }, + { + description: "UID:group", + image: testImageUserUIDGroup, + uid: imageUserUIDGroup, + username: "", + }, + { + description: "Username:group", + image: testImageUserUsernameGroup, + uid: int64(0), + username: imageUserUsernameGroup, + }, + } { + framework.PullPublicImage(c, item.image) + defer removeImage(c, item.image) + + status := framework.ImageStatus(c, item.image) + Expect(status.GetUid().GetValue()).To(Equal(item.uid), fmt.Sprintf("%s, Image Uid should be %d", item.description, item.uid)) + Expect(status.GetUsername()).To(Equal(item.username), fmt.Sprintf("%s, Image Username should be %s", item.description, item.username)) + } + }) + It("listImage should get exactly 3 image in the result list [Conformance]", func() { // different tags refer to different images testImageList := []string{