Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 0600 for files created by Beats #3387

Merged
merged 3 commits into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff]
- The limit for the number of fields is increased via the mapping template. {pull}3275[3275]
- Updated to Go 1.7.4. {pull}3277[3277]
- Added a NOTICE file containing the notices and licenses of the dependencies. {pull}3334[3334].
- Files created by Beats (logs, registry, file output) will have 0600 permissions. {pull}3387[3387].

*Metricbeat*

Expand Down
4 changes: 2 additions & 2 deletions filebeat/registrar/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *Registrar) Init() error {

// Create directory if it does not already exist.
registryPath := filepath.Dir(r.registryFile)
err := os.MkdirAll(registryPath, 0755)
err := os.MkdirAll(registryPath, 0750)
if err != nil {
return fmt.Errorf("Failed to created registry file dir %s: %v", registryPath, err)
}
Expand Down Expand Up @@ -298,7 +298,7 @@ func (r *Registrar) writeRegistry() error {
logp.Debug("registrar", "Write registry file: %s", r.registryFile)

tempfile := r.registryFile + ".new"
f, err := os.Create(tempfile)
f, err := os.OpenFile(tempfile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could put these flags into a constant as we reuse them in several places or have a function in libbeat to open files which automatically applies flags and correct access rights.

if err != nil {
logp.Err("Failed to create tempfile (%s) for writing: %s", tempfile, err)
return err
Expand Down
4 changes: 2 additions & 2 deletions libbeat/logp/file_rotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (rotator *FileRotator) CreateDirectory() error {
}

if os.IsNotExist(err) {
err = os.MkdirAll(rotator.Path, 0755)
err = os.MkdirAll(rotator.Path, 0750)
if err != nil {
return err
}
Expand Down Expand Up @@ -145,7 +145,7 @@ func (rotator *FileRotator) Rotate() error {

// create the new file
path := rotator.FilePath(0)
current, err := os.Create(path)
current, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions libbeat/paths/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ func New() *Path {

// InitPaths sets the default paths in the configuration based on CLI flags,
// configuration file and default values. It also tries to create the data
// path with mode 0755 and returns an error on failure.
// path with mode 0750 and returns an error on failure.
func (paths *Path) InitPaths(cfg *Path) error {
err := paths.initPaths(cfg)
if err != nil {
return err
}

// make sure the data path exists
err = os.MkdirAll(paths.Data, 0755)
err = os.MkdirAll(paths.Data, 0750)
if err != nil {
return fmt.Errorf("Failed to create data path %s: %v", paths.Data, err)
}
Expand All @@ -73,7 +73,7 @@ func (paths *Path) InitPaths(cfg *Path) error {

// InitPaths sets the default paths in the configuration based on CLI flags,
// configuration file and default values. It also tries to create the data
// path with mode 0755 and returns an error on failure.
// path with mode 0750 and returns an error on failure.
func InitPaths(cfg *Path) error {
return Paths.InitPaths(cfg)
}
Expand Down
2 changes: 1 addition & 1 deletion winlogbeat/checkpoint/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (c *Checkpoint) flush() error {
if os.IsNotExist(err) {
// Try to create directory if it does not exist.
if createDirErr := c.createDir(); createDirErr == nil {
file, err = os.Create(tempFile)
file, err = create(tempFile)
}
}

Expand Down
2 changes: 1 addition & 1 deletion winlogbeat/checkpoint/file_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ package checkpoint
import "os"

func create(path string) (*os.File, error) {
return os.Create(path)
return os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
}