Skip to content

Add restrict_permissions to FileLoggerBuilder#51

Merged
sile merged 3 commits intosile:masterfrom
macladson:restrict-permissions
Nov 3, 2021
Merged

Add restrict_permissions to FileLoggerBuilder#51
sile merged 3 commits intosile:masterfrom
macladson:restrict-permissions

Conversation

@macladson
Copy link
Contributor

Resolves #17

This PR adds a new method to FileLoggerBuilder which restricts log file permissions such that they are only readable by the file owner.
This corresponds to:

  • Setting the umask of the file to 600 on Unix systems.
  • Setting the ACL of the file to only include the SID of the file owner (which mirrors the behavior of umask 600) on Windows systems.

This is done specifically as a restriction rather than setting an arbitrary umask to ensure it worked across both Unix and Windows platforms.

@sile
Copy link
Owner

sile commented Nov 2, 2021

Thank you for your PR! I'll review it tomorrow.
BTW, though the CI / Coverage failed, it seems not relevant to the changes in this PR. So you can ignore that (I'll investigate the cause later).

Copy link
Owner

@sile sile left a comment

Choose a reason for hiding this comment

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

Thanks again. This PR looks basically good but I left a comment to reduce code complexity a bit.

///
/// This ensures the log files are not world-readable.
#[cfg(unix)]
pub fn restrict_file_permissions(file: File) -> io::Result<File> {
Copy link
Owner

Choose a reason for hiding this comment

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

How about aligning function signatures between Unix and Windows versions?

For example, I think we could do as follows:

#[cfg(unix)]
pub fn restrict_file_permissions<P: AsRef<Path>>(_path: P, file: File) -> io::Result<File> {
    ...abbrev...
    Ok(file)
}

#[cfg(windows)]
pub fn restrict_file_permissions<P: AsRef<Path>>(path: P, file: _File) -> io::Result<File> {
    ...abbrev...
    Ok(file)
}

By this change, the cfg branches in src/file.rs can be removed.

Copy link
Owner

Choose a reason for hiding this comment

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

In addition to the following comment, I thought it could be better to add another implementation for platforms other than Unix and Windows as follows:

#[cfg(not(any(unix, windows)))]
pub fn restrict_file_permissions<P: AsRef<Path>>(path: P, file: _File) -> io::Result<File> {
    Err(io::Error::new(io::ErrorKind::Other, "`restrict_permissions` feature is only available on Unix or Windows"))
}

By this addition, users, who even don't use Unix or Windows, could build sloggers without a "no such function" error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep good call. I've implemented both of these suggestions.

@coveralls
Copy link

coveralls commented Nov 3, 2021

Pull Request Test Coverage Report for Build 1414790960

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 3 of 17 (17.65%) changed or added relevant lines in 2 files are covered.
  • 21 unchanged lines in 15 files lost coverage.
  • Overall coverage decreased (-0.4%) to 49.106%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/file.rs 3 10 30.0%
src/permissions.rs 0 7 0.0%
Files with Coverage Reduction New Missed Lines %
src/config.rs 1 35.71%
src/misc.rs 1 55.0%
src/syslog/drain.rs 1 93.55%
src/syslog/facility.rs 1 39.72%
../../../../../usr/share/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/crossbeam-channel-0.5.1/src/context.rs 1 70.49%
../../../../../usr/share/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/crossbeam-channel-0.5.1/src/flavors/array.rs 1 86.87%
../../../../../usr/share/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/crossbeam-channel-0.5.1/src/flavors/tick.rs 1 0.0%
../../../../../usr/share/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.8.0/src/imp_std.rs 1 84.0%
../../../../../usr/share/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/slog-async-2.7.0/lib.rs 1 94.37%
../../../../../usr/share/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/slog-term-2.8.0/src/lib.rs 1 59.71%
Totals Coverage Status
Change from base Build 1132511506: -0.4%
Covered Lines: 1621
Relevant Lines: 3301

💛 - Coveralls

Copy link
Owner

@sile sile left a comment

Choose a reason for hiding this comment

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

Thank you for your swift action. LGTM.

@sile sile merged commit 14e1112 into sile:master Nov 3, 2021
@macladson
Copy link
Contributor Author

Thank you for the quick review and merge!

@macladson macladson deleted the restrict-permissions branch November 3, 2021 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

log file permissions ...

3 participants