From 2ff043e75f441b5e5a3f149e572289d7f84d003a Mon Sep 17 00:00:00 2001 From: Paul Morie Date: Mon, 19 Oct 2015 18:15:37 -0400 Subject: [PATCH] Add ownership inspection to mount tester image --- hack/verify-flags/excluded-flags.txt | 2 ++ test/images/mount-tester-user/Dockerfile | 2 +- test/images/mount-tester-user/Makefile | 2 +- test/images/mount-tester/Makefile | 2 +- test/images/mount-tester/mt.go | 30 ++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/hack/verify-flags/excluded-flags.txt b/hack/verify-flags/excluded-flags.txt index 260c496bbbc..0b31b008e62 100644 --- a/hack/verify-flags/excluded-flags.txt +++ b/hack/verify-flags/excluded-flags.txt @@ -3,6 +3,7 @@ concurrent_rc_syncs etcd_mutation_timeout file_content file_mode +file_owner file_perm fs_type gke_context @@ -12,6 +13,7 @@ kube_master_url max_in_flight max_par new_file_0644 +new_file_0660 new_file_0666 new_file_0777 pods_per_node diff --git a/test/images/mount-tester-user/Dockerfile b/test/images/mount-tester-user/Dockerfile index 732dc6788f5..b3cee3958d3 100644 --- a/test/images/mount-tester-user/Dockerfile +++ b/test/images/mount-tester-user/Dockerfile @@ -12,5 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM gcr.io/google_containers/mounttest:0.4 +FROM gcr.io/google_containers/mounttest:0.5 USER 1001 diff --git a/test/images/mount-tester-user/Makefile b/test/images/mount-tester-user/Makefile index 2d12d0badb2..5600d1815ac 100644 --- a/test/images/mount-tester-user/Makefile +++ b/test/images/mount-tester-user/Makefile @@ -1,6 +1,6 @@ all: push -TAG = 0.2 +TAG = 0.3 image: sudo docker build -t gcr.io/google_containers/mounttest-user:$(TAG) . diff --git a/test/images/mount-tester/Makefile b/test/images/mount-tester/Makefile index 0d012c70c11..9985c8557b9 100644 --- a/test/images/mount-tester/Makefile +++ b/test/images/mount-tester/Makefile @@ -1,6 +1,6 @@ all: push -TAG = 0.4 +TAG = 0.5 mt: mt.go CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-w' ./mt.go diff --git a/test/images/mount-tester/mt.go b/test/images/mount-tester/mt.go index a481228d473..7b9a1e85e56 100644 --- a/test/images/mount-tester/mt.go +++ b/test/images/mount-tester/mt.go @@ -29,8 +29,10 @@ var ( fsTypePath = "" fileModePath = "" filePermPath = "" + fileOwnerPath = "" newFilePath0644 = "" newFilePath0666 = "" + newFilePath0660 = "" newFilePath0777 = "" readFileContentPath = "" readFileContentInLoopPath = "" @@ -41,8 +43,10 @@ func init() { flag.StringVar(&fsTypePath, "fs_type", "", "Path to print the fs type for") flag.StringVar(&fileModePath, "file_mode", "", "Path to print the mode bits of") flag.StringVar(&filePermPath, "file_perm", "", "Path to print the perms of") + flag.StringVar(&fileOwnerPath, "file_owner", "", "Path to print the owning UID and GID of") flag.StringVar(&newFilePath0644, "new_file_0644", "", "Path to write to and read from with perm 0644") flag.StringVar(&newFilePath0666, "new_file_0666", "", "Path to write to and read from with perm 0666") + flag.StringVar(&newFilePath0660, "new_file_0660", "", "Path to write to and read from with perm 0660") flag.StringVar(&newFilePath0777, "new_file_0777", "", "Path to write to and read from with perm 0777") flag.StringVar(&readFileContentPath, "file_content", "", "Path to read the file content from") flag.StringVar(&readFileContentInLoopPath, "file_content_in_loop", "", "Path to read the file content in loop from") @@ -86,6 +90,11 @@ func main() { errs = append(errs, err) } + err = readWriteNewFile(newFilePath0660, 0660) + if err != nil { + errs = append(errs, err) + } + err = readWriteNewFile(newFilePath0777, 0777) if err != nil { errs = append(errs, err) @@ -101,6 +110,11 @@ func main() { errs = append(errs, err) } + err = fileOwner(fileOwnerPath) + if err != nil { + errs = append(errs, err) + } + err = readFileContent(readFileContentPath) if err != nil { errs = append(errs, err) @@ -171,6 +185,22 @@ func filePerm(path string) error { return nil } +func fileOwner(path string) error { + if path == "" { + return nil + } + + buf := syscall.Stat_t{} + if err := syscall.Stat(path, &buf); err != nil { + fmt.Printf("error from stat(%q): %v\n", path, err) + return err + } + + fmt.Printf("owner UID of %q: %v\n", path, buf.Uid) + fmt.Printf("owner GID of %q: %v\n", path, buf.Gid) + return nil +} + func readFileContent(path string) error { if path == "" { return nil