diff --git a/docs/schema.yaml b/docs/schema.yaml index 730aebda7..16b22709d 100644 --- a/docs/schema.yaml +++ b/docs/schema.yaml @@ -111,9 +111,13 @@ definitions: owner: type: string default: root + uid: + type: integer group: type: string default: root + gid: + type: integer filetype: type: string default: file diff --git a/integration-tests/goss/goss-shared.yaml b/integration-tests/goss/goss-shared.yaml index 4fdef9148..a0ff79827 100644 --- a/integration-tests/goss/goss-shared.yaml +++ b/integration-tests/goss/goss-shared.yaml @@ -23,7 +23,9 @@ file: exists: true mode: '0644' owner: root + uid: 0 group: root + gid: 0 filetype: file contents: - root diff --git a/integration-tests/test.sh b/integration-tests/test.sh index 058b510b6..3225d37bf 100755 --- a/integration-tests/test.sh +++ b/integration-tests/test.sh @@ -48,9 +48,9 @@ out=$(docker_exec "/goss/$os/goss-linux-$arch" --vars "/goss/vars.yaml" --vars-i echo "$out" if [[ $os == "arch" ]]; then - egrep -q 'Count: 100, Failed: 0, Skipped: 3' <<<"$out" + egrep -q 'Count: 104, Failed: 0, Skipped: 3' <<<"$out" else - egrep -q 'Count: 121, Failed: 0, Skipped: 5' <<<"$out" + egrep -q 'Count: 125, Failed: 0, Skipped: 5' <<<"$out" fi if [[ ! $os == "arch" ]]; then diff --git a/resource/file.go b/resource/file.go index dcb7f5a0e..97356a193 100644 --- a/resource/file.go +++ b/resource/file.go @@ -18,7 +18,9 @@ type File struct { Mode matcher `json:"mode,omitempty" yaml:"mode,omitempty"` Size matcher `json:"size,omitempty" yaml:"size,omitempty"` Owner matcher `json:"owner,omitempty" yaml:"owner,omitempty"` + Uid matcher `json:"uid,omitempty" yaml:"uid,omitempty"` Group matcher `json:"group,omitempty" yaml:"group,omitempty"` + Gid matcher `json:"gid,omitempty" yaml:"gid,omitempty"` LinkedTo matcher `json:"linked-to,omitempty" yaml:"linked-to,omitempty"` Filetype matcher `json:"filetype,omitempty" yaml:"filetype,omitempty"` Contains matcher `json:"contains,omitempty" yaml:"contains,omitempty"` @@ -74,9 +76,15 @@ func (f *File) Validate(sys *system.System) []TestResult { if f.Owner != nil { results = append(results, ValidateValue(f, "owner", f.Owner, sysFile.Owner, skip)) } + if f.Uid != nil { + results = append(results, ValidateValue(f, "uid", f.Uid, sysFile.Uid, skip)) + } if f.Group != nil { results = append(results, ValidateValue(f, "group", f.Group, sysFile.Group, skip)) } + if f.Gid != nil { + results = append(results, ValidateValue(f, "gid", f.Gid, sysFile.Gid, skip)) + } if f.LinkedTo != nil { results = append(results, ValidateValue(f, "linkedto", f.LinkedTo, sysFile.LinkedTo, skip)) } diff --git a/system/file.go b/system/file.go index 736c25ee8..6927d910f 100644 --- a/system/file.go +++ b/system/file.go @@ -25,7 +25,9 @@ type File interface { Size() (int, error) Filetype() (string, error) Owner() (string, error) + Uid() (int, error) Group() (string, error) + Gid() (int, error) LinkedTo() (string, error) Md5() (string, error) Sha256() (string, error) diff --git a/system/file_posix.go b/system/file_posix.go index 491751eaa..53db903c1 100644 --- a/system/file_posix.go +++ b/system/file_posix.go @@ -37,6 +37,21 @@ func (f *DefFile) Owner() (string, error) { return getUserForUid(uid) } +func (f *DefFile) Uid() (int, error) { + uidS, err := f.getFileInfo(func(fi os.FileInfo) string { + return fmt.Sprint(fi.Sys().(*syscall.Stat_t).Uid) + }) + if err != nil { + return -1, err + } + + uid, err := strconv.Atoi(uidS) + if err != nil { + return -1, err + } + return uid, nil +} + func (f *DefFile) Group() (string, error) { gidS, err := f.getFileInfo(func(fi os.FileInfo) string { return fmt.Sprint(fi.Sys().(*syscall.Stat_t).Gid) @@ -52,6 +67,21 @@ func (f *DefFile) Group() (string, error) { return getGroupForGid(gid) } +func (f *DefFile) Gid() (int, error) { + gidS, err := f.getFileInfo(func(fi os.FileInfo) string { + return fmt.Sprint(fi.Sys().(*syscall.Stat_t).Gid) + }) + if err != nil { + return -1, err + } + + gid, err := strconv.Atoi(gidS) + if err != nil { + return -1, err + } + return gid, nil +} + func (f *DefFile) getFileInfo(selectorFunc func(os.FileInfo) string) (string, error) { if err := f.setup(); err != nil { return "", err diff --git a/system/file_windows.go b/system/file_windows.go index c91c9fd5c..909ffbd79 100644 --- a/system/file_windows.go +++ b/system/file_windows.go @@ -11,6 +11,14 @@ func (f *DefFile) Owner() (string, error) { return "-1", nil // not applicable on Windows } +func (f *DefFile) Uid() (int, error) { + return -1, nil // not applicable on Windows +} + func (f *DefFile) Group() (string, error) { return "-1", nil // not applicable on Windows } + +func (f *DefFile) Gid() (int, error) { + return -1, nil // not applicable on Windows +}