Skip to content

Commit

Permalink
Filebeat: Adds system test to check registry_file_permission
Browse files Browse the repository at this point in the history
Signed-off-by: Jaipradeesh <jaipradeesh@gmail.com>
  • Loading branch information
dolftax committed Mar 14, 2018
1 parent ad600a6 commit fd14e3a
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
1 change: 1 addition & 0 deletions filebeat/_meta/common.reference.p2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ filebeat.inputs:

# The permissions mask to apply on registry file. The default value is 0600.
# Must be a valid Unix-style file permissions mask expressed in octal notation.
# This option is not supported on Windows.
#filebeat.registry_file_permissions: 0600

# These config files must have the full filebeat config part inside, but only
Expand Down
2 changes: 2 additions & 0 deletions filebeat/docs/filebeat-general-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ That means in case there are some states where the TTL expired, these are only r

The permissions mask to apply on registry file. The default value is 0600. The permissions option must be a valid Unix-style file permissions mask expressed in octal notation. In Go, numbers in octal notation must start with 0.

This option is not supported on Windows.

Examples:

0644: give read and write access to the file owner, and read access to all others.
Expand Down
1 change: 1 addition & 0 deletions filebeat/filebeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ filebeat.inputs:

# The permissions mask to apply on registry file. The default value is 0600.
# Must be a valid Unix-style file permissions mask expressed in octal notation.
# This option is not supported on Windows.
#filebeat.registry_file_permissions: 0600

# These config files must have the full filebeat config part inside, but only
Expand Down
1 change: 1 addition & 0 deletions filebeat/tests/system/config/filebeat.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ filebeat.{{input_config | default("inputs")}}:
filebeat.shutdown_timeout: {{ shutdown_timeout|default(0) }}
{% if not skip_registry_config %}
filebeat.registry_file: {{ beat.working_dir + '/' }}{{ registryFile|default("registry")}}
filebeat.registry_file_permissions: {{ registryFilePermissions|default("0600") }}
{%endif%}

{% if reload or reload_path -%}
Expand Down
130 changes: 130 additions & 0 deletions filebeat/tests/system/test_registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import platform
import time
import shutil
import stat

from filebeat import BaseTest
from nose.plugins.skip import SkipTest
Expand Down Expand Up @@ -161,6 +162,135 @@ def test_custom_registry_file_location(self):

assert os.path.isfile(os.path.join(self.working_dir, "a/b/c/registry"))

def test_registry_file_default_permissions(self):
"""
Test that filebeat default registry permission is set
"""

if os.name == "nt":
# This test is currently skipped on windows because file permission
# configuration isn't implemented on Windows yet
raise SkipTest

self.render_config_template(
path=os.path.abspath(self.working_dir) + "/log/*",
registryFile="a/b/c/registry",
)
os.mkdir(self.working_dir + "/log/")
testfile_path = self.working_dir + "/log/test.log"
with open(testfile_path, 'w') as testfile:
testfile.write("hello world\n")
filebeat = self.start_beat()
self.wait_until(
lambda: self.output_has(lines=1),
max_timeout=15)
# wait until the registry file exist. Needed to avoid a race between
# the logging and actual writing the file. Seems to happen on Windows.
self.wait_until(
lambda: os.path.isfile(os.path.join(self.working_dir,
"a/b/c/registry")),
max_timeout=1)
filebeat.check_kill_and_wait()

registry_file_perm_mask = oct(stat.S_IMODE(os.lstat(os.path.join(self.working_dir,
"a/b/c/registry")).st_mode))
self.assertEqual(registry_file_perm_mask, "0600")

def test_registry_file_custom_permissions(self):
"""
Test that filebeat registry permission is set as per configuration
"""

if os.name == "nt":
# This test is currently skipped on windows because file permission
# configuration isn't implemented on Windows yet
raise SkipTest

self.render_config_template(
path=os.path.abspath(self.working_dir) + "/log/*",
registryFile="a/b/c/registry",
registryFilePermissions=0644
)
os.mkdir(self.working_dir + "/log/")
testfile_path = self.working_dir + "/log/test.log"
with open(testfile_path, 'w') as testfile:
testfile.write("hello world\n")
filebeat = self.start_beat()
self.wait_until(
lambda: self.output_has(lines=1),
max_timeout=15)
# wait until the registry file exist. Needed to avoid a race between
# the logging and actual writing the file. Seems to happen on Windows.
self.wait_until(
lambda: os.path.isfile(os.path.join(self.working_dir,
"a/b/c/registry")),
max_timeout=1)
filebeat.check_kill_and_wait()

registry_file_perm_mask = oct(stat.S_IMODE(os.lstat(os.path.join(self.working_dir,
"a/b/c/registry")).st_mode))
self.assertEqual(registry_file_perm_mask, "0644")

def test_registry_file_update_permissions(self):
"""
Test that filebeat registry permission is updated along with configuration
"""

if os.name == "nt":
# This test is currently skipped on windows because file permission
# configuration isn't implemented on Windows yet
raise SkipTest

self.render_config_template(
path=os.path.abspath(self.working_dir) + "/log/*",
registryFile="a/b/c/registry_x",
)
os.mkdir(self.working_dir + "/log/")
testfile_path = self.working_dir + "/log/test.log"
with open(testfile_path, 'w') as testfile:
testfile.write("hello world\n")
filebeat = self.start_beat()
self.wait_until(
lambda: self.output_has(lines=1),
max_timeout=15)
# wait until the registry file exist. Needed to avoid a race between
# the logging and actual writing the file. Seems to happen on Windows.
self.wait_until(
lambda: os.path.isfile(os.path.join(self.working_dir,
"a/b/c/registry_x")),
max_timeout=1)
filebeat.check_kill_and_wait()

registry_file_perm_mask = oct(stat.S_IMODE(os.lstat(os.path.join(self.working_dir,
"a/b/c/registry_x")).st_mode))
self.assertEqual(registry_file_perm_mask, "0600")

self.render_config_template(
path=os.path.abspath(self.working_dir) + "/log/*",
registryFile="a/b/c/registry_x",
registryFilePermissions=0644
)

filebeat = self.start_beat()
self.wait_until(
lambda: self.output_has(lines=1),
max_timeout=15)
# wait until the registry file exist. Needed to avoid a race between
# the logging and actual writing the file. Seems to happen on Windows.
self.wait_until(
lambda: os.path.isfile(os.path.join(self.working_dir,
"a/b/c/registry_x")),
max_timeout=1)

# Wait a momemt to make sure registry is completely written
time.sleep(1)

filebeat.check_kill_and_wait()

registry_file_perm_mask = oct(stat.S_IMODE(os.lstat(os.path.join(self.working_dir,
"a/b/c/registry_x")).st_mode))
self.assertEqual(registry_file_perm_mask, "0644")

def test_rotating_file(self):
"""
Checks that the registry is properly updated after a file is rotated
Expand Down

0 comments on commit fd14e3a

Please sign in to comment.