Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

CLI: Restrict os/arch for secure validators, add flag for insecure mode #7073

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ pub struct RunCmd {
#[arg(long)]
pub beefy: bool,

/// Allows the validator to run insecurely if they know what they're doing.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is visible to the user in --help, right? In which case a slightly longer explanation would be nice. (Or as I've said in the other comment, maybe a link to somewhere where it's explained in more detail.)

#[arg(long = "insecure-validator-i-know-what-i-do", requires = "validator")]
pub insecure_validator: bool,

/// Add the destination address to the jaeger agent.
///
/// Must be valid socket address, of format `IP:Port`
Expand Down
20 changes: 20 additions & 0 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ where
return Err(Error::Other("BEEFY disallowed on production networks".to_string()))
}

if cli.run.base.validator && !cli.run.insecure_validator {
if let Err(e) = can_run_as_secure_validator() {
return Err(Error::InsecureValidator(e))
}
}

set_default_ss58_version(chain_spec);

let grandpa_pause = if cli.run.grandpa_pause.is_empty() {
Expand Down Expand Up @@ -732,3 +738,17 @@ pub fn run() -> Result<()> {
}
Ok(())
}

/// Returns an error if a secure validator cannot be built for the target OS and architecture.
fn can_run_as_secure_validator() -> std::result::Result<(), String> {
#[cfg(not(target_os = "linux"))]
let result = Err("Must be on Linux to run a validator securely.".into());

#[cfg(all(target_os = "linux", not(target_arch = "x86_64")))]
let result = Err("Must be on x86_64 to run a validator securely.".into());
Comment on lines +744 to +748
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a little bit less jargon-y? Normal users might not necessarily know what x86_64 is.

Suggested change
#[cfg(not(target_os = "linux"))]
let result = Err("Must be on Linux to run a validator securely.".into());
#[cfg(all(target_os = "linux", not(target_arch = "x86_64")))]
let result = Err("Must be on x86_64 to run a validator securely.".into());
#[cfg(not(target_os = "linux"))]
let result = Err("Running a validator is only supported on Linux.".into());
#[cfg(all(target_os = "linux", not(target_arch = "x86_64")))]
let result = Err("Running a validator is only supported on CPUs from the x86_64 family (usually Intel or AMD).".into());


#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
let result = Ok(());

result
}
3 changes: 3 additions & 0 deletions cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ pub enum Error {

#[error("This subcommand is only available when compiled with `{feature}`")]
FeatureNotEnabled { feature: &'static str },

#[error("Insecure validator: {0} Run with --insecure-validator-i-know-what-i-do if you understand and accept the risks of running insecurely.")]
Copy link
Contributor

Choose a reason for hiding this comment

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

"Insecure validator" can be kinda vague, maybe something like this?

Suggested change
#[error("Insecure validator: {0} Run with --insecure-validator-i-know-what-i-do if you understand and accept the risks of running insecurely.")]
#[error("Your system cannot securely run a validator: {0}\nYou can ignore this requirement by using the `--insecure-validator-i-know-what-i-do` command line argument if you understand and accept the risks of running insecurely.")]

Also, I think in this case it'd be nice to maybe e.g. put a link to the docs with a longer explanation of why this is and what will be the consequences when running in unsecure mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like the idea, just don't know where the doc should go. Maybe on the validators guide?

InsecureValidator(String),
}