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

Commit

Permalink
CLI: Restrict os/arch for secure validators, add flag for insecure mode
Browse files Browse the repository at this point in the history
Due to #4718 becoming high-priority for parathreads, we are now forced to provide a secure validator mode only for Linux x86-64 (to start).

We will still support MacOS with an `--insecure-validator-i-know-what-i-do` flag. (Naming follows [`interpreted-i-know-what-i-do`](https://github.com/paritytech/substrate/blob//client/cli/src/arg_enums.rs#L58).)

See https://github.com/paritytech/polkadot/issues/4718#issuecomment-1484137059

Closes https://github.com/paritytech/polkadot/issues/4720
  • Loading branch information
mrcnski committed Apr 13, 2023
1 parent f1a45b3 commit 24c984e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
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.
#[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());

#[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.")]
InsecureValidator(String),
}

0 comments on commit 24c984e

Please sign in to comment.