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

Stop following symlinks. #1767

Merged
merged 5 commits into from
Jun 1, 2016
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ https://github.com/elastic/beats/compare/v5.0.0-alpha3...master[Check the HEAD d

*Filebeat*

- Stop following symlink. Symlinks are now ignored: {pull}1686[1686]

*Winlogbeat*


Expand Down Expand Up @@ -79,7 +81,7 @@ https://github.com/elastic/beats/compare/v5.0.0alpha2...v5.0.0-alpha3[View commi
*Affecting all Beats*

- All configuration settings under `shipper:` are moved to be top level configuration settings. I.e.
`shipper.name:` becomes `name:` in the configuration file. #1570
`shipper.name:` becomes `name:` in the configuration file. {pull}1570[1570]

*Packetbeat*

Expand Down
6 changes: 5 additions & 1 deletion filebeat/crawler/prospector_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ func (p *ProspectorLog) getFiles() map[string]os.FileInfo {
}

// Stat the file, following any symlinks.
Copy link
Member

Choose a reason for hiding this comment

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

The comment here is out of date, right? os.Lstat doesn't follow symlinks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, will remove it.

fileinfo, err := os.Stat(file)
fileinfo, err := os.Lstat(file)
if err != nil {
logp.Debug("prospector", "stat(%s) failed: %s", file, err)
continue
}
if fileinfo.Mode()&os.ModeSymlink != 0 {
logp.Debug("prospector", "File %s skipped as it is a symlink.", file)
continue
}

if fileinfo.IsDir() {
logp.Debug("prospector", "Skipping directory: %s", file)
Expand Down
42 changes: 42 additions & 0 deletions filebeat/tests/system/test_prospector.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,45 @@ def test_close_older_file_rotation_and_removal(self):
max_timeout=10)

filebeat.check_kill_and_wait()

def test_skip_symlinks(self):
"""
Test that symlinks are skipped
"""
self.render_config_template(
path=os.path.abspath(self.working_dir) + "/log/*",
)

os.mkdir(self.working_dir + "/log/")
testfile = self.working_dir + "/log/test-2016.log"
symlink_file = self.working_dir + "/log/test.log"

# write first line
with open(testfile, 'a') as file:
file.write("Hello world\n")

if os.name == "nt":
import win32file
win32file.CreateSymbolicLink(symlink_file, testfile, 1)
Copy link
Member

@andrewkroh andrewkroh May 31, 2016

Choose a reason for hiding this comment

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

The link points to a file so the last parameter should be 0. https://msdn.microsoft.com/en-us/library/windows/desktop/aa363866(v=vs.85).aspx

Hopefully that will fix the issue with 7z on AppVeyor.

else:
os.symlink(testfile, symlink_file)

filebeat = self.start_beat()

# wait for file to be skipped
self.wait_until(
lambda: self.log_contains("skipped as it is a symlink"),
max_timeout=10)

# wait for log to be read
self.wait_until(
lambda: self.output_has(lines=1),
max_timeout=15)

time.sleep(5)
filebeat.check_kill_and_wait()

data = self.read_output()

# Make sure there is only one entry, means it didn't follow the symlink
assert len(data) == 1