forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.5] Set default umask of 0027 for all Beats-created files (elastic#…
…14119) (elastic#14216) * Set default umask of 0027 for all Beats-created files (elastic#14119) * Set umask of 027 (on non-windows systems) for all Beats-created files * Fixing comment * Update tests * Updating docs for filebeat.registry.file_permissions * Denoting octal * Allow beats to override umask * Removing accidentally-committed file * Adding system test for default umask * Make setUmask return error * Defining ErrNotImplemented locally * Defining not implemented error locally * Fixing typo * Skip umask test on Windows * Adding missed imports * Adding CHANGELOG entry * Fixing up CHANGELOG
- Loading branch information
1 parent
7fcf9cd
commit 6140a19
Showing
9 changed files
with
121 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,6 @@ type Settings struct { | |
ILM ilm.SupportFactory | ||
|
||
Processing processing.SupportFactory | ||
|
||
Umask *int | ||
} |
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,32 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
// +build !windows | ||
|
||
package instance | ||
|
||
import ( | ||
"errors" | ||
"syscall" | ||
) | ||
|
||
var errNotImplemented = errors.New("not implemented on platform") | ||
|
||
func setUmask(newmask int) error { | ||
syscall.Umask(newmask) | ||
return nil // the umask syscall always succeeds: http://man7.org/linux/man-pages/man2/umask.2.html#RETURN_VALUE | ||
} |
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,27 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package instance | ||
|
||
import "errors" | ||
|
||
var errNotImplemented = errors.New("not implemented on windows") | ||
|
||
func setUmask(newmask int) error { | ||
// No way to set umask on Windows | ||
return errNotImplemented | ||
} |
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,36 @@ | ||
from base import BaseTest | ||
|
||
import os | ||
import stat | ||
import unittest | ||
import sys | ||
|
||
INTEGRATION_TESTS = os.environ.get('INTEGRATION_TESTS', False) | ||
|
||
|
||
class TestUmask(BaseTest): | ||
""" | ||
Test default umask | ||
""" | ||
|
||
DEFAULT_UMASK = 0027 | ||
|
||
def setUp(self): | ||
super(BaseTest, self).setUp() | ||
|
||
self.output_file_permissions = 0666 | ||
|
||
self.render_config_template(output_file_permissions=self.output_file_permissions) | ||
proc = self.start_beat() | ||
self.wait_until(lambda: self.output_lines() > 0, max_timeout=2) | ||
proc.check_kill_and_wait() | ||
|
||
@unittest.skipIf(sys.platform.startswith("win"), "umask is not available on Windows") | ||
def test_output_file_perms(self): | ||
""" | ||
Test that output file permissions respect default umask | ||
""" | ||
output_file_path = os.path.join(self.working_dir, "output", "mockbeat") | ||
perms = stat.S_IMODE(os.lstat(output_file_path).st_mode) | ||
|
||
self.assertEqual(perms, self.output_file_permissions & ~TestUmask.DEFAULT_UMASK) |