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

PVF: Add Secure Validator Mode #2486

Merged
merged 28 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4cb5913
PVF: Add Secure Validator Mode
mrcnski Nov 21, 2023
c3d512c
Merge branch 'master' into mrcnski/pvf-add-secure-validator-mode
mrcnski Nov 21, 2023
f44ca5f
Minor fix
mrcnski Nov 21, 2023
bd80771
Properly handle missing security features worker-side; big refactor
mrcnski Nov 22, 2023
69c117f
Merge branch 'master' into mrcnski/pvf-add-secure-validator-mode
mrcnski Nov 23, 2023
cb91ed1
Make only one FS security feature required
mrcnski Nov 24, 2023
61b80d8
Refactor secure mode code a bit
mrcnski Nov 24, 2023
ba03492
Fix check_seccomp and check_landlock errs not being logged to stderr
mrcnski Nov 24, 2023
0ce35ab
Merge branch 'master' into mrcnski/pvf-add-secure-validator-mode
mrcnski Nov 24, 2023
ec9bd4b
Fix unshare error (cannot run in multithreaded context)
mrcnski Nov 24, 2023
090d2d9
Update some comments
mrcnski Nov 24, 2023
dc7961d
Some fixes
mrcnski Nov 24, 2023
8a72556
Fix bench
mrcnski Nov 24, 2023
a4d173c
Merge branch 'master' into mrcnski/pvf-add-secure-validator-mode
mrcnski Nov 26, 2023
6520dd8
fix CI
mrcnski Nov 26, 2023
f5f11bd
Remove old TODO
mrcnski Nov 27, 2023
3aa8bd4
Merge remote-tracking branch 'origin/mrcnski/pvf-add-secure-validator…
mrcnski Nov 28, 2023
da7127c
Address some review comments
mrcnski Nov 29, 2023
13f5e92
Merge branch 'master' into mrcnski/pvf-add-secure-validator-mode
mrcnski Nov 29, 2023
26ca19c
Update doc
mrcnski Nov 29, 2023
fccc36a
Merge branch 'master' into mrcnski/pvf-add-secure-validator-mode
mrcnski Dec 1, 2023
0ffa527
Fix rustdoc warning
mrcnski Dec 1, 2023
8fa147f
bump zombienet version
pepoviola Dec 1, 2023
f1b3539
Baby's first prdoc
mrcnski Dec 1, 2023
5509b31
Zombienet, add script to update cmd and fix upgrade-node test
pepoviola Dec 4, 2023
2209855
bump zombienet version
pepoviola Dec 4, 2023
0469f56
Merge branch 'master' into mrcnski/pvf-add-secure-validator-mode
mrcnski Dec 5, 2023
27b45a0
Fix prdoc 😢
mrcnski Dec 5, 2023
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
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.6", 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