Skip to content

Commit

Permalink
PVF: Add Secure Validator Mode (#2486)
Browse files Browse the repository at this point in the history
Co-authored-by: Javier Viola <javier@parity.io>
  • Loading branch information
mrcnski and pepoviola authored Dec 5, 2023
1 parent f240e02 commit c046a9d
Show file tree
Hide file tree
Showing 31 changed files with 692 additions and 471 deletions.
2 changes: 1 addition & 1 deletion .gitlab/pipeline/zombienet.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.zombienet-refs:
extends: .build-refs
variables:
ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.83"
ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.86"

include:
# substrate tests
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cumulus/client/relay-chain-inprocess-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ fn build_polkadot_full_node(

// Cumulus doesn't spawn PVF workers, so we can disable version checks.
node_version: None,
secure_validator_mode: false,
workers_path: None,
workers_names: None,

Expand Down
1 change: 1 addition & 0 deletions polkadot/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ wasm-opt = false
crate-type = ["cdylib", "rlib"]

[dependencies]
cfg-if = "1.0"
clap = { version = "4.4.10", features = ["derive"], optional = true }
log = "0.4.17"
thiserror = "1.0.48"
Expand Down
6 changes: 6 additions & 0 deletions polkadot/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ pub struct RunCmd {
#[arg(long)]
pub no_beefy: bool,

/// Allows a validator to run insecurely outside of Secure Validator Mode. Security features
/// are still enabled on a best-effort basis, but missing features are no longer required. For
/// more information see <https://github.com/w3f/polkadot-wiki/issues/4881>.
#[arg(long = "insecure-validator-i-know-what-i-do", requires = "validator")]
pub insecure_validator: bool,

/// Enable the block authoring backoff that is triggered when finality is lagging.
#[arg(long)]
pub force_authoring_backoff: bool,
Expand Down
3 changes: 3 additions & 0 deletions polkadot/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ where
let node_version =
if cli.run.disable_worker_version_check { None } else { Some(NODE_VERSION.to_string()) };

let secure_validator_mode = cli.run.base.validator && !cli.run.insecure_validator;

runner.run_node_until_exit(move |config| async move {
let hwbench = (!cli.run.no_hardware_benchmarks)
.then_some(config.database.path().map(|database_path| {
Expand All @@ -256,6 +258,7 @@ where
jaeger_agent,
telemetry_worker_handle: None,
node_version,
secure_validator_mode,
workers_path: cli.run.workers_path,
workers_names: None,
overseer_gen,
Expand Down
11 changes: 10 additions & 1 deletion polkadot/node/core/candidate-validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ pub struct Config {
pub artifacts_cache_path: PathBuf,
/// The version of the node. `None` can be passed to skip the version check (only for tests).
pub node_version: Option<String>,
/// Whether the node is attempting to run as a secure validator.
pub secure_validator_mode: bool,
/// Path to the preparation worker binary
pub prep_worker_path: PathBuf,
/// Path to the execution worker binary
Expand Down Expand Up @@ -133,12 +135,19 @@ async fn run<Context>(
mut ctx: Context,
metrics: Metrics,
pvf_metrics: polkadot_node_core_pvf::Metrics,
Config { artifacts_cache_path, node_version, prep_worker_path, exec_worker_path }: Config,
Config {
artifacts_cache_path,
node_version,
secure_validator_mode,
prep_worker_path,
exec_worker_path,
}: Config,
) -> SubsystemResult<()> {
let (validation_host, task) = polkadot_node_core_pvf::start(
polkadot_node_core_pvf::Config::new(
artifacts_cache_path,
node_version,
secure_validator_mode,
prep_worker_path,
exec_worker_path,
),
Expand Down
1 change: 1 addition & 0 deletions polkadot/node/core/pvf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pin-project = "1.0.9"
rand = "0.8.5"
slotmap = "1.0"
tempfile = "3.3.0"
thiserror = "1.0.31"
tokio = { version = "1.24.2", features = ["fs", "process"] }

parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use tokio::{runtime::Handle, sync::Mutex};
const TEST_PREPARATION_TIMEOUT: Duration = Duration::from_secs(30);

struct TestHost {
// Keep a reference to the tempdir as it gets deleted on drop.
cache_dir: tempfile::TempDir,
host: Mutex<ValidationHost>,
}

Expand All @@ -42,13 +44,14 @@ impl TestHost {
let mut config = Config::new(
cache_dir.path().to_owned(),
None,
false,
prepare_worker_path,
execute_worker_path,
);
f(&mut config);
let (host, task) = start(config, Metrics::default()).await.unwrap();
let _ = handle.spawn(task);
Self { host: Mutex::new(host) }
Self { host: Mutex::new(host), cache_dir }
}

async fn precheck_pvf(
Expand Down
12 changes: 11 additions & 1 deletion polkadot/node/core/pvf/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const LOG_TARGET: &str = "parachain::pvf-common";

pub const RUNTIME_VERSION: &str = env!("SUBSTRATE_WASMTIME_VERSION");

use parity_scale_codec::{Decode, Encode};
use std::{
io::{self, Read, Write},
mem,
Expand All @@ -47,8 +48,11 @@ pub mod tests {
}

/// Status of security features on the current system.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
#[derive(Debug, Clone, Default, PartialEq, Eq, Encode, Decode)]
pub struct SecurityStatus {
/// Whether Secure Validator Mode is enabled. This mode enforces that all required security
/// features are present. All features are enabled on a best-effort basis regardless.
pub secure_validator_mode: bool,
/// Whether the landlock features we use are fully available on this system.
pub can_enable_landlock: bool,
/// Whether the seccomp features we use are fully available on this system.
Expand All @@ -57,6 +61,12 @@ pub struct SecurityStatus {
pub can_unshare_user_namespace_and_change_root: bool,
}

/// A handshake with information for the worker.
#[derive(Debug, Encode, Decode)]
pub struct WorkerHandshake {
pub security_status: SecurityStatus,
}

/// Write some data prefixed by its length into `w`. Sync version of `framed_send` to avoid
/// dependency on tokio.
pub fn framed_send_blocking(w: &mut (impl Write + Unpin), buf: &[u8]) -> io::Result<()> {
Expand Down
Loading

0 comments on commit c046a9d

Please sign in to comment.