Skip to content

Commit 62d6428

Browse files
authored
feat(signer): store proxy keys and delegations (#166)
* add proxy store * refactor exports * config and cli init * docs * clippy
1 parent a293bdb commit 62d6428

File tree

19 files changed

+370
-81
lines changed

19 files changed

+370
-81
lines changed

config.example.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ key_path = "./keys.example.json"
102102
# keys_path = ""
103103
# ValidatorsDir: path to the secrets directory
104104
# secrets_path = ""
105+
# Configuration for how the Signer module should store proxy delegations. Currently one type of store is supported:
106+
# - File: store keys and delegations from a plain text file (unsafe, use only for testing purposes)
107+
# OPTIONAL, if missing proxies are lost on restart
108+
[signer.store]
109+
# File: path to the keys file
110+
proxy_dir = "./proxies"
105111

106112
# Commit-Boost can optionally run "modules" which extend the capabilities of the sidecar.
107113
# Currently, two types of modules are supported:

crates/cli/src/docker_init.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use cb_common::{
44
config::{
55
CommitBoostConfig, LogsSettings, ModuleKind, BUILDER_PORT_ENV, BUILDER_URLS_ENV,
66
CHAIN_SPEC_ENV, CONFIG_DEFAULT, CONFIG_ENV, JWTS_ENV, LOGS_DIR_DEFAULT, LOGS_DIR_ENV,
7-
METRICS_PORT_ENV, MODULE_ID_ENV, MODULE_JWT_ENV, PBS_MODULE_NAME, SIGNER_DEFAULT,
8-
SIGNER_DIR_KEYS_DEFAULT, SIGNER_DIR_KEYS_ENV, SIGNER_DIR_SECRETS, SIGNER_DIR_SECRETS_ENV,
9-
SIGNER_KEYS_ENV, SIGNER_MODULE_NAME, SIGNER_PORT_ENV, SIGNER_URL_ENV,
7+
METRICS_PORT_ENV, MODULE_ID_ENV, MODULE_JWT_ENV, PBS_MODULE_NAME, PROXY_DIR_DEFAULT,
8+
PROXY_DIR_ENV, SIGNER_DEFAULT, SIGNER_DIR_KEYS_DEFAULT, SIGNER_DIR_KEYS_ENV,
9+
SIGNER_DIR_SECRETS_DEFAULT, SIGNER_DIR_SECRETS_ENV, SIGNER_KEYS_ENV, SIGNER_MODULE_NAME,
10+
SIGNER_PORT_ENV, SIGNER_URL_ENV,
1011
},
11-
loader::SignerLoader,
12+
signer::{ProxyStore, SignerLoader},
1213
types::ModuleId,
1314
utils::random_jwt,
1415
};
@@ -299,27 +300,47 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
299300

300301
match signer_config.loader {
301302
SignerLoader::File { key_path } => {
302-
volumes.push(Volumes::Simple(format!("./{}:{}:ro", key_path, SIGNER_DEFAULT)));
303+
volumes.push(Volumes::Simple(format!(
304+
"{}:{}:ro",
305+
key_path.display(),
306+
SIGNER_DEFAULT
307+
)));
303308
let (k, v) = get_env_val(SIGNER_KEYS_ENV, SIGNER_DEFAULT);
304309
signer_envs.insert(k, v);
305310
}
306311
SignerLoader::ValidatorsDir { keys_path, secrets_path } => {
307312
volumes.push(Volumes::Simple(format!(
308313
"{}:{}:ro",
309-
keys_path, SIGNER_DIR_KEYS_DEFAULT
314+
keys_path.display(),
315+
SIGNER_DIR_KEYS_DEFAULT
310316
)));
311317
let (k, v) = get_env_val(SIGNER_DIR_KEYS_ENV, SIGNER_DIR_KEYS_DEFAULT);
312318
signer_envs.insert(k, v);
313319

314320
volumes.push(Volumes::Simple(format!(
315321
"{}:{}:ro",
316-
secrets_path, SIGNER_DIR_SECRETS
322+
secrets_path.display(),
323+
SIGNER_DIR_SECRETS_DEFAULT
317324
)));
318-
let (k, v) = get_env_val(SIGNER_DIR_SECRETS_ENV, SIGNER_DIR_SECRETS);
325+
let (k, v) = get_env_val(SIGNER_DIR_SECRETS_ENV, SIGNER_DIR_SECRETS_DEFAULT);
319326
signer_envs.insert(k, v);
320327
}
321328
};
322329

330+
if let Some(store) = signer_config.store {
331+
match store {
332+
ProxyStore::File { proxy_dir } => {
333+
volumes.push(Volumes::Simple(format!(
334+
"{}:{}:rw",
335+
proxy_dir.display(),
336+
PROXY_DIR_DEFAULT
337+
)));
338+
let (k, v) = get_env_val(PROXY_DIR_ENV, PROXY_DIR_DEFAULT);
339+
signer_envs.insert(k, v);
340+
}
341+
}
342+
}
343+
323344
volumes.extend(get_log_volume(&cb_config.logs, SIGNER_MODULE_NAME));
324345

325346
// networks

crates/common/src/commit/client.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ use super::{
1515
},
1616
};
1717
use crate::{
18-
signer::{
19-
schemes::{bls::BlsPublicKey, ecdsa::EcdsaSignature},
20-
EcdsaPublicKey,
21-
},
18+
signer::{BlsPublicKey, EcdsaPublicKey, EcdsaSignature},
2219
DEFAULT_REQUEST_TIMEOUT,
2320
};
2421

crates/common/src/commit/request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
constants::COMMIT_BOOST_DOMAIN,
1111
error::BlstErrorWrapper,
1212
signature::verify_signed_message,
13-
signer::schemes::{bls::BlsPublicKey, ecdsa::EcdsaPublicKey},
13+
signer::{BlsPublicKey, EcdsaPublicKey},
1414
types::Chain,
1515
};
1616

crates/common/src/config/constants.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ pub const SIGNER_DIR_KEYS_ENV: &str = "CB_SIGNER_LOADER_KEYS_DIR";
4141
pub const SIGNER_DIR_KEYS_DEFAULT: &str = "/keys";
4242
/// Path to `secrets` folder
4343
pub const SIGNER_DIR_SECRETS_ENV: &str = "CB_SIGNER_LOADER_SECRETS_DIR";
44-
pub const SIGNER_DIR_SECRETS: &str = "/secrets";
44+
pub const SIGNER_DIR_SECRETS_DEFAULT: &str = "/secrets";
45+
/// Path to store proxies
46+
pub const PROXY_DIR_ENV: &str = "CB_PROXY_STORE_DIR";
47+
pub const PROXY_DIR_DEFAULT: &str = "/proxies";
4548

4649
///////////////////////// MODULES /////////////////////////
4750

crates/common/src/config/signer.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::{
88
CommitBoostConfig, SIGNER_PORT_ENV,
99
};
1010
use crate::{
11-
loader::SignerLoader,
11+
signer::{ProxyStore, SignerLoader},
1212
types::{Chain, Jwt, ModuleId},
1313
};
1414

@@ -19,6 +19,8 @@ pub struct SignerConfig {
1919
pub docker_image: String,
2020
/// Which keys to load
2121
pub loader: SignerLoader,
22+
/// How to store keys
23+
pub store: Option<ProxyStore>,
2224
}
2325

2426
fn default_signer() -> String {
@@ -29,6 +31,7 @@ fn default_signer() -> String {
2931
pub struct StartSignerConfig {
3032
pub chain: Chain,
3133
pub loader: SignerLoader,
34+
pub store: Option<ProxyStore>,
3235
pub server_port: u16,
3336
pub jwts: BiHashMap<ModuleId, Jwt>,
3437
}
@@ -40,11 +43,14 @@ impl StartSignerConfig {
4043
let jwts = load_jwts()?;
4144
let server_port = load_env_var(SIGNER_PORT_ENV)?.parse()?;
4245

46+
let signer_config = config.signer.expect("Signer config is missing");
47+
4348
Ok(StartSignerConfig {
4449
chain: config.chain,
45-
loader: config.signer.expect("Signer config is missing").loader,
50+
loader: signer_config.loader,
4651
server_port,
4752
jwts,
53+
store: signer_config.store,
4854
})
4955
}
5056
}

crates/common/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub mod commit;
44
pub mod config;
55
pub mod constants;
66
pub mod error;
7-
pub mod loader;
87
pub mod pbs;
98
pub mod signature;
109
pub mod signer;

crates/common/src/signature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tree_hash_derive::TreeHash;
55
use crate::{
66
constants::{COMMIT_BOOST_DOMAIN, GENESIS_VALIDATORS_ROOT},
77
error::BlstErrorWrapper,
8-
signer::{schemes::bls::verify_bls_signature, BlsSecretKey},
8+
signer::{verify_bls_signature, BlsSecretKey},
99
types::Chain,
1010
};
1111

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fs;
1+
use std::{fs, path::PathBuf};
22

33
use alloy::{primitives::hex::FromHex, rpc::types::beacon::BlsPublicKey};
44
use eth2_keystore::Keystore;
@@ -15,11 +15,11 @@ use crate::{
1515
pub enum SignerLoader {
1616
/// Plain text, do not use in prod
1717
File {
18-
key_path: String,
18+
key_path: PathBuf,
1919
},
2020
ValidatorsDir {
21-
keys_path: String,
22-
secrets_path: String,
21+
keys_path: PathBuf,
22+
secrets_path: PathBuf,
2323
},
2424
}
2525

crates/common/src/signer/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
pub mod schemes;
1+
mod loader;
2+
mod schemes;
3+
mod store;
4+
mod types;
25

3-
pub use schemes::{
4-
bls::{BlsPublicKey, BlsSecretKey, BlsSignature, BlsSigner},
5-
ecdsa::{EcdsaPublicKey, EcdsaSecretKey, EcdsaSignature, EcdsaSigner},
6-
};
6+
pub use loader::*;
7+
pub use schemes::*;
8+
pub use store::*;
9+
pub use types::*;
710

811
pub type ConsensusSigner = BlsSigner;

0 commit comments

Comments
 (0)