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

[Merged by Bors] - Add CLI flag to opt in to world-readable log files #3747

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions lcli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ fn run<T: EthSpec>(
max_log_size: 0,
max_log_number: 0,
compression: false,
is_restricted: true,
})
.map_err(|e| format!("should start logger: {:?}", e))?
.build()
Expand Down
4 changes: 3 additions & 1 deletion lighthouse/environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct LoggerConfig {
pub max_log_size: u64,
pub max_log_number: usize,
pub compression: bool,
pub is_restricted: bool,
}
impl Default for LoggerConfig {
fn default() -> Self {
Expand All @@ -68,6 +69,7 @@ impl Default for LoggerConfig {
max_log_size: 200,
max_log_number: 5,
compression: false,
is_restricted: true,
}
}
}
Expand Down Expand Up @@ -257,7 +259,7 @@ impl<E: EthSpec> EnvironmentBuilder<E> {
.rotate_size(config.max_log_size)
.rotate_keep(config.max_log_number)
.rotate_compress(config.compression)
.restrict_permissions(true)
.restrict_permissions(config.is_restricted)
.build()
.map_err(|e| format!("Unable to build file logger: {}", e))?;

Expand Down
12 changes: 12 additions & 0 deletions lighthouse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ fn main() {
to store old logs.")
.global(true),
)
.arg(
Arg::with_name("logfile-no-restricted-perms")
.long("logfile-no-restricted-perms")
.help(
"If present, log files will be generated as world-readable meaning they can be read by \
any user on the machine. Note that logs can often contain sensitive information \
about your validator and so this flag should be used with caution.")
.global(true),
)
.arg(
Arg::with_name("log-format")
.long("log-format")
Expand Down Expand Up @@ -407,6 +416,8 @@ fn run<E: EthSpec>(

let logfile_compress = matches.is_present("logfile-compress");

let logfile_restricted = !matches.is_present("logfile-no-restricted-perms");

// Construct the path to the log file.
let mut log_path: Option<PathBuf> = clap_utils::parse_optional(matches, "logfile")?;
if log_path.is_none() {
Expand Down Expand Up @@ -446,6 +457,7 @@ fn run<E: EthSpec>(
max_log_size: logfile_max_size * 1_024 * 1_024,
max_log_number: logfile_max_number,
compression: logfile_compress,
is_restricted: logfile_restricted,
};

let builder = environment_builder.initialize_logger(logger_config.clone())?;
Expand Down
17 changes: 17 additions & 0 deletions lighthouse/tests/beacon_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,23 @@ fn enabled_disable_log_timestamp_flag() {
assert!(config.logger_config.disable_log_timestamp);
});
}
#[test]
fn logfile_restricted_perms_default() {
CommandLineTest::new()
.run_with_zero_port()
.with_config(|config| {
assert!(config.logger_config.is_restricted);
});
}
#[test]
fn logfile_no_restricted_perms_flag() {
CommandLineTest::new()
.flag("logfile-no-restricted-perms", None)
.run_with_zero_port()
.with_config(|config| {
assert!(config.logger_config.is_restricted == false);
});
}

#[test]
fn sync_eth1_chain_default() {
Expand Down
1 change: 1 addition & 0 deletions testing/simulator/src/eth1_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub fn run_eth1_sim(matches: &ArgMatches) -> Result<(), String> {
max_log_size: 0,
max_log_number: 0,
compression: false,
is_restricted: true,
})?
.multi_threaded_tokio_runtime()?
.build()?;
Expand Down
1 change: 1 addition & 0 deletions testing/simulator/src/no_eth1_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub fn run_no_eth1_sim(matches: &ArgMatches) -> Result<(), String> {
max_log_size: 0,
max_log_number: 0,
compression: false,
is_restricted: true,
})?
.multi_threaded_tokio_runtime()?
.build()?;
Expand Down
1 change: 1 addition & 0 deletions testing/simulator/src/sync_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fn syncing_sim(
max_log_size: 0,
max_log_number: 0,
compression: false,
is_restricted: true,
})?
.multi_threaded_tokio_runtime()?
.build()?;
Expand Down