-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configuration files must not be writeable by other users (#3544)
* Configuration files must not be writeable by other users … This PR adds enforcement of ownership and file permissions on configuration files. Any configuration file must be owned by the same user that the Beat is running as and the file must not be writable by anyone other than the owner. This strict permission checking is limited to platforms with POSIX file permissions. The DACLs used by Windows are not checked at this time. The check can be disabled on the CLI with `-strict.perms=false` or by setting env var `BEAT_STRICT_PERMS=false`. * Update jenkins_ci to fix umask on git clone
- Loading branch information
1 parent
06e70d2
commit 32d4285
Showing
13 changed files
with
271 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package file | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
) | ||
|
||
// A FileInfo describes a file and is returned by Stat and Lstat. | ||
type FileInfo interface { | ||
os.FileInfo | ||
UID() (int, error) // UID of the file owner. Returns an error on non-POSIX file systems. | ||
GID() (int, error) // GID of the file owner. Returns an error on non-POSIX file systems. | ||
} | ||
|
||
// Stat returns a FileInfo describing the named file. | ||
// If there is an error, it will be of type *PathError. | ||
func Stat(name string) (FileInfo, error) { | ||
return stat(name, os.Stat) | ||
} | ||
|
||
// Lstat returns a FileInfo describing the named file. | ||
// If the file is a symbolic link, the returned FileInfo | ||
// describes the symbolic link. Lstat makes no attempt to follow the link. | ||
// If there is an error, it will be of type *PathError. | ||
func Lstat(name string) (FileInfo, error) { | ||
return stat(name, os.Lstat) | ||
} | ||
|
||
type fileInfo struct { | ||
os.FileInfo | ||
uid *int | ||
gid *int | ||
} | ||
|
||
func (f fileInfo) UID() (int, error) { | ||
if f.uid == nil { | ||
return -1, errors.New("uid not implemented") | ||
} | ||
|
||
return *f.uid, nil | ||
} | ||
|
||
func (f fileInfo) GID() (int, error) { | ||
if f.gid == nil { | ||
return -1, errors.New("gid not implemented") | ||
} | ||
|
||
return *f.gid, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// +build !windows | ||
|
||
package file_test | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/elastic/beats/libbeat/common/file" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestStat(t *testing.T) { | ||
f, err := ioutil.TempFile("", "teststat") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(f.Name()) | ||
|
||
link := filepath.Join(os.TempDir(), "teststat-link") | ||
if err := os.Symlink(f.Name(), link); err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(link) | ||
|
||
info, err := file.Stat(link) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
assert.True(t, info.Mode().IsRegular()) | ||
|
||
uid, err := info.UID() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.EqualValues(t, os.Geteuid(), uid) | ||
|
||
gid, err := info.GID() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.EqualValues(t, os.Getegid(), gid) | ||
} | ||
|
||
func TestLstat(t *testing.T) { | ||
link := filepath.Join(os.TempDir(), "link") | ||
if err := os.Symlink("dummy", link); err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(link) | ||
|
||
info, err := file.Lstat(link) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
assert.True(t, info.Mode()&os.ModeSymlink > 0) | ||
|
||
uid, err := info.UID() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.EqualValues(t, os.Geteuid(), uid) | ||
|
||
gid, err := info.GID() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.EqualValues(t, os.Getegid(), gid) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// +build !windows | ||
|
||
package file | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"syscall" | ||
) | ||
|
||
func stat(name string, statFunc func(name string) (os.FileInfo, error)) (FileInfo, error) { | ||
info, err := statFunc(name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
stat, ok := info.Sys().(*syscall.Stat_t) | ||
if !ok { | ||
return nil, errors.New("failed to get uid/gid") | ||
} | ||
|
||
uid := int(stat.Uid) | ||
gid := int(stat.Gid) | ||
return fileInfo{FileInfo: info, uid: &uid, gid: &gid}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package file | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
func stat(name string, statFunc func(name string) (os.FileInfo, error)) (FileInfo, error) { | ||
info, err := statFunc(name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return fileInfo{FileInfo: info}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters