Skip to content

Skip is_writeable check for log files in /dev/ - #62263

Closed
mcnewton wants to merge 1 commit into
saltstack:developfrom
mcnewton:develop
Closed

mcnewton wants to merge 1 commit into
saltstack:developfrom
mcnewton:develop

Conversation

@mcnewton

@mcnewton mcnewton commented Jul 1, 2022

Copy link
Copy Markdown

What does this PR do?

The documented way to write to syslog is to use the config: log_file: file:///dev/log.

This breaks in some circumstances when running as non-root, for example, when log_level: info is set. In that case, /dev/log is not "writeable", so the code falls back to writing to /root/.salt/master.log, which is definitely not writeable by the non-root user salt is configured to run as.

Files in /dev/ are unlikely to be normal files. There are other solutions that might, for example, try and test to see if the file is a socket, but these will be a lot more complicated - they will need to recognise and remove the file:// prefix, parse the line (the documented format permits e.g. a /<log-facility> suffix), and may not be cross-platform compatible. This seems the simplest solution and will fix the issue in the vast majority of cases.

What issues does this PR fix or reference?

Likely also fixes: #61286

The test to see if the file is writeable was added in #7875

Previous Behavior

Salt will try and write logs to /root/.salt/master.log, which is inaccessible when running as non-root, which means salt-master crashes out with a permissions error.

New Behavior

There is no check to see if /dev/log is writeable or not, so salt-master starts correctly.

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.

The documented way to write to syslog, "log_file: file:///dev/log",
breaks in some circumstances when running as non-root (for
example, when "log_level: info" is set). Files in /dev/ are
unlikely to be normal files, so the simplest solution is to just
exclude them from the check.
@mcnewton
mcnewton requested a review from a team as a code owner July 1, 2022 14:04
@mcnewton
mcnewton requested review from MKLeb and removed request for a team July 1, 2022 14:04
@MKLeb

MKLeb commented Sep 13, 2022

Copy link
Copy Markdown
Contributor

Hi @mcnewton, I guess I'm a little confused. From looking at the code, it looks like it should fall back to the current user's home directory via os.path.expanduser(). So if it falls back to /root/.salt/master.log, it feels like you are running as root, or at the very least the current user should have access to this directory since it is their home directory, but I may be wrong (I have not tried to repro the original bug).

Also, would you mind porting this to a PR into the master branch? We no longer use develop.

@MKLeb MKLeb added needs-testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases needs-changelog labels Sep 13, 2022
@MKLeb

MKLeb commented Sep 27, 2022

Copy link
Copy Markdown
Contributor

@mcnewton any updates here?

@mcnewton

Copy link
Copy Markdown
Author

Hi @MKLeb - I've been travelling a lot in August and September. Hope to take a look in the next couple of weeks or so.

@MKLeb

MKLeb commented Sep 27, 2022

Copy link
Copy Markdown
Contributor

Hi @MKLeb - I've been travelling a lot in August and September. Hope to take a look in the next couple of weeks or so.

No worries, enjoy your travelling!

@MKLeb

MKLeb commented Oct 10, 2022

Copy link
Copy Markdown
Contributor

@mcnewton Have you been able to circle back to this one yet?

@MKLeb

MKLeb commented Nov 22, 2022

Copy link
Copy Markdown
Contributor

Going to close this for now. Feel free to open up another PR onto the master branch.

@MKLeb MKLeb closed this Nov 22, 2022
@mcnewton

Copy link
Copy Markdown
Author

Sorry, working on other things for the moment and it fell off my to-do list. Will revisit when I get back to the original thing I was looking at again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-changelog needs-testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases pending-close

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants