Skip to content

Commit

Permalink
Add ownership inspection to mount tester image
Browse files Browse the repository at this point in the history
  • Loading branch information
pmorie committed Oct 19, 2015
1 parent b896a66 commit 2ff043e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions hack/verify-flags/excluded-flags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ concurrent_rc_syncs
etcd_mutation_timeout
file_content
file_mode
file_owner
file_perm
fs_type
gke_context
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/images/mount-tester-user/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/images/mount-tester-user/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
all: push

TAG = 0.2
TAG = 0.3

image:
sudo docker build -t gcr.io/google_containers/mounttest-user:$(TAG) .
Expand Down
2 changes: 1 addition & 1 deletion test/images/mount-tester/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 30 additions & 0 deletions test/images/mount-tester/mt.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ var (
fsTypePath = ""
fileModePath = ""
filePermPath = ""
fileOwnerPath = ""
newFilePath0644 = ""
newFilePath0666 = ""
newFilePath0660 = ""
newFilePath0777 = ""
readFileContentPath = ""
readFileContentInLoopPath = ""
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2ff043e

Please sign in to comment.