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

Add support for syslog logging #176

Merged
merged 9 commits into from
Jan 24, 2024
Merged

Add support for syslog logging #176

merged 9 commits into from
Jan 24, 2024

Conversation

sosthene-nitrokey
Copy link
Contributor

@sosthene-nitrokey sosthene-nitrokey commented Jan 17, 2024

This patch adds support for syslog logging.

On initialization errors, it will also now by default log to syslog, instead of logging to stderr. Ideally it would do both, but there doesn't appear to be an easy way to support multiple loggers at the same time.

I also want to revert 3a635b4, this seems like a security concern as it makes the log file writeable by anyone. What was the justification for this change? I also want to not panic if the file can't be opened as is currently the case.

Fix #153

Copy link

codecov bot commented Jan 17, 2024

Codecov Report

Attention: 55 lines in your changes are missing coverage. Please review.

Comparison is base (07d4dbb) 90.89% compared to head (f8dcb85) 90.37%.

Files Patch % Lines
pkcs11/src/config/logging.rs 67.48% 53 Missing ⚠️
pkcs11/src/api/mod.rs 0.00% 1 Missing ⚠️
pkcs11/src/config/config_file.rs 96.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #176      +/-   ##
==========================================
- Coverage   90.89%   90.37%   -0.53%     
==========================================
  Files          31       31              
  Lines        6457     6627     +170     
==========================================
+ Hits         5869     5989     +120     
- Misses        588      638      +50     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ansiwen
Copy link
Collaborator

ansiwen commented Jan 17, 2024

I also want to revert 3a635b4, this seems like a security concern as it makes the log file writeable by anyone. What was the justification for this change? I also want to not panic if the file can't be opened as is currently the case.

I guess that was not intended. The idea is probably to make it writable only to the owner. It sets „read_only“ to false, whatever that means. 🤷‍♂️

@sosthene-nitrokey
Copy link
Contributor Author

This methods sets the write flag for all users, this is why there's a clippy flag. I would rather do it it a more precise way to avoid the security issue, but I also feel like this isn't something that should be done silently like that.

Comment on lines 12 to 18
// On error, first try logging to syslog
if syslog::init_unix(syslog::Facility::LOG_USER, log::LevelFilter::Info).is_ok() {
return;
};
// Otherwise try to log to stderr
env_logger::try_init().ok();
return;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would make sense to log both to stderr and syslog. In some cases, messages on stderr are more intutive. Do you know if pkcs11-tool passes through stderr messages per default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does pass through stderr. Ok, i'll adapt it to log to both by default.

@robin-nitrokey
Copy link
Member

I’m also fine with dropping 3a635b4, especially as we now have improved diagnostics for issues with the log file.

@sosthene-nitrokey
Copy link
Contributor Author

Ok, I reverted 3a635b4, and made multiple loggers possible, defaulting to both env_logger and syslog.

@sosthene-nitrokey sosthene-nitrokey force-pushed the syslog branch 2 times, most recently from 46edf70 to f8957dd Compare January 23, 2024 16:45
This avoids panicking paths in the initialization, and the
module is probably not expected to change permissions for the file.
Log to stderr correctly when no file is specified
Correctly set the log_level from RUST_LOG when it's not default
@sosthene-nitrokey sosthene-nitrokey merged commit e81c093 into main Jan 24, 2024
3 of 5 checks passed
@sosthene-nitrokey sosthene-nitrokey deleted the syslog branch January 24, 2024 09:59
sosthene-nitrokey added a commit that referenced this pull request Jan 25, 2024
In #176  I wanted to allow
RUST_LOG overriding the config file, but it also made the config file be always ignored
when file logging was enabled
sosthene-nitrokey added a commit that referenced this pull request Jan 30, 2024
In #176  I wanted to allow
RUST_LOG overriding the config file, but it also made the config file be always ignored
when file logging was enabled
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.

Improved Logging (and logging to syslog) needed
3 participants