Skip to content

Commit 40d34aa

Browse files
committed
Merge branch 'main' into add-ip-bind-to-signer
2 parents fc872ac + 988d606 commit 40d34aa

14 files changed

Lines changed: 92 additions & 86 deletions

File tree

.github/workflows/release.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,12 @@ jobs:
180180

181181
- name: Extract binaries
182182
run: |
183-
mkdir -p ./artifacts/bin
183+
mkdir -p ./artifacts/bin/linux_amd64
184+
mkdir -p ./artifacts/bin/linux_arm64
184185
tar -xzf ./artifacts/commit-boost-pbs-${{ github.ref_name }}-linux_x86-64/commit-boost-pbs-${{ github.ref_name }}-linux_x86-64.tar.gz -C ./artifacts/bin
185-
mv ./artifacts/bin/commit-boost-pbs ./artifacts/bin/commit-boost-pbs-linux-amd64
186+
mv ./artifacts/bin/commit-boost-pbs ./artifacts/bin/linux_amd64/commit-boost-pbs
186187
tar -xzf ./artifacts/commit-boost-pbs-${{ github.ref_name }}-linux_arm64/commit-boost-pbs-${{ github.ref_name }}-linux_arm64.tar.gz -C ./artifacts/bin
187-
mv ./artifacts/bin/commit-boost-pbs ./artifacts/bin/commit-boost-pbs-linux-arm64
188+
mv ./artifacts/bin/commit-boost-pbs ./artifacts/bin/linux_arm64/commit-boost-pbs
188189
189190
- name: Set up QEMU
190191
uses: docker/setup-qemu-action@v3
@@ -232,11 +233,12 @@ jobs:
232233

233234
- name: Extract binaries
234235
run: |
235-
mkdir -p ./artifacts/bin
236+
mkdir -p ./artifacts/bin/linux_amd64
237+
mkdir -p ./artifacts/bin/linux_arm64
236238
tar -xzf ./artifacts/commit-boost-signer-${{ github.ref_name }}-linux_x86-64/commit-boost-signer-${{ github.ref_name }}-linux_x86-64.tar.gz -C ./artifacts/bin
237-
mv ./artifacts/bin/commit-boost-signer ./artifacts/bin/commit-boost-signer-linux-amd64
239+
mv ./artifacts/bin/commit-boost-signer ./artifacts/bin/linux_amd64/commit-boost-signer
238240
tar -xzf ./artifacts/commit-boost-signer-${{ github.ref_name }}-linux_arm64/commit-boost-signer-${{ github.ref_name }}-linux_arm64.tar.gz -C ./artifacts/bin
239-
mv ./artifacts/bin/commit-boost-signer ./artifacts/bin/commit-boost-signer-linux-arm64
241+
mv ./artifacts/bin/commit-boost-signer ./artifacts/bin/linux_arm64/commit-boost-signer
240242
241243
- name: Set up QEMU
242244
uses: docker/setup-qemu-action@v3

Cargo.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resolver = "2"
55
[workspace.package]
66
edition = "2021"
77
rust-version = "1.83"
8-
version = "0.8.0-rc.1"
8+
version = "0.8.0-rc.2"
99

1010
[workspace.dependencies]
1111
aes = "0.8"
@@ -44,6 +44,7 @@ eyre = "0.6.12"
4444
futures = "0.3.30"
4545
headers = "0.4.0"
4646
indexmap = "2.2.6"
47+
jsonwebtoken = { version = "9.3.1", default-features = false }
4748
lazy_static = "1.5.0"
4849
parking_lot = "0.12.3"
4950
pbkdf2 = "0.12.2"
@@ -70,4 +71,3 @@ typenum = "1.17.0"
7071
unicode-normalization = "0.1.24"
7172
url = { version = "2.5.0", features = ["serde"] }
7273
uuid = { version = "1.8.0", features = ["fast-rng", "serde", "v4"] }
73-
jsonwebtoken = { version = "9.3.1", default-features = false }

crates/cli/src/docker_init.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ use std::{
66

77
use cb_common::{
88
config::{
9-
load_optional_env_var, CommitBoostConfig, LogsSettings, ModuleKind, SignerConfig,
10-
SignerType, BUILDER_PORT_ENV, BUILDER_URLS_ENV, CHAIN_SPEC_ENV, CONFIG_DEFAULT, CONFIG_ENV,
11-
DIRK_CA_CERT_DEFAULT, DIRK_CA_CERT_ENV, DIRK_CERT_DEFAULT, DIRK_CERT_ENV,
12-
DIRK_DIR_SECRETS_DEFAULT, DIRK_DIR_SECRETS_ENV, DIRK_KEY_DEFAULT, DIRK_KEY_ENV, JWTS_ENV,
13-
LOGS_DIR_DEFAULT, LOGS_DIR_ENV, METRICS_PORT_ENV, MODULE_ID_ENV, MODULE_JWT_ENV,
14-
PBS_ENDPOINT_ENV, PBS_MODULE_NAME, PROXY_DIR_DEFAULT, PROXY_DIR_ENV,
15-
PROXY_DIR_KEYS_DEFAULT, PROXY_DIR_KEYS_ENV, PROXY_DIR_SECRETS_DEFAULT,
16-
PROXY_DIR_SECRETS_ENV, SIGNER_DEFAULT, SIGNER_DIR_KEYS_DEFAULT, SIGNER_DIR_KEYS_ENV,
17-
SIGNER_DIR_SECRETS_DEFAULT, SIGNER_DIR_SECRETS_ENV, SIGNER_ENDPOINT_ENV,
18-
SIGNER_JWT_SECRET_ENV, SIGNER_KEYS_ENV, SIGNER_MODULE_NAME, SIGNER_URL_ENV,
9+
CommitBoostConfig, LogsSettings, ModuleKind, SignerConfig, SignerType, BUILDER_PORT_ENV,
10+
BUILDER_URLS_ENV, CHAIN_SPEC_ENV, CONFIG_DEFAULT, CONFIG_ENV, DIRK_CA_CERT_DEFAULT,
11+
DIRK_CA_CERT_ENV, DIRK_CERT_DEFAULT, DIRK_CERT_ENV, DIRK_DIR_SECRETS_DEFAULT,
12+
DIRK_DIR_SECRETS_ENV, DIRK_KEY_DEFAULT, DIRK_KEY_ENV, JWTS_ENV, LOGS_DIR_DEFAULT,
13+
LOGS_DIR_ENV, METRICS_PORT_ENV, MODULE_ID_ENV, MODULE_JWT_ENV, PBS_ENDPOINT_ENV,
14+
PBS_MODULE_NAME, PROXY_DIR_DEFAULT, PROXY_DIR_ENV, PROXY_DIR_KEYS_DEFAULT,
15+
PROXY_DIR_KEYS_ENV, PROXY_DIR_SECRETS_DEFAULT, PROXY_DIR_SECRETS_ENV, SIGNER_DEFAULT,
16+
SIGNER_DIR_KEYS_DEFAULT, SIGNER_DIR_KEYS_ENV, SIGNER_DIR_SECRETS_DEFAULT,
17+
SIGNER_DIR_SECRETS_ENV, SIGNER_ENDPOINT_ENV, SIGNER_KEYS_ENV, SIGNER_MODULE_NAME,
18+
SIGNER_URL_ENV,
1919
},
2020
pbs::{BUILDER_API_PATH, GET_STATUS_PATH},
2121
signer::{ProxyStore, SignerLoader, DEFAULT_SIGNER_PORT},
@@ -105,8 +105,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
105105
ModuleKind::Commit => {
106106
let mut ports = vec![];
107107

108-
let jwt_secret = load_optional_env_var(SIGNER_JWT_SECRET_ENV)
109-
.unwrap_or_else(random_jwt_secret);
108+
let jwt_secret = random_jwt_secret();
110109
let jwt_name = format!("CB_JWT_{}", module.id.to_uppercase());
111110

112111
// module ids are assumed unique, so envs dont override each other

crates/common/src/config/constants.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ pub const SIGNER_ENDPOINT_ENV: &str = "CB_SIGNER_ENDPOINT";
3737

3838
/// Comma separated list module_id=jwt_secret
3939
pub const JWTS_ENV: &str = "CB_JWTS";
40-
/// The JWT secret for the signer to validate the modules requests
41-
pub const SIGNER_JWT_SECRET_ENV: &str = "CB_SIGNER_JWT_SECRET";
4240

4341
/// Path to json file with plaintext keys (testing only)
4442
pub const SIGNER_KEYS_ENV: &str = "CB_SIGNER_LOADER_FILE";

crates/common/src/config/mux.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ async fn fetch_lido_registry_keys(
242242
let total_keys =
243243
registry.getTotalSigningKeyCount(node_operator_id).call().await?._0.try_into()?;
244244

245+
if total_keys == 0 {
246+
return Ok(Vec::new());
247+
}
248+
245249
debug!("fetching {total_keys} total keys");
246250

247251
const CALL_BATCH_SIZE: u64 = 250u64;

crates/common/src/signer/loader.rs

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ impl SignerLoader {
5757
pub fn load_from_env(self) -> eyre::Result<Vec<ConsensusSigner>> {
5858
Ok(match self {
5959
SignerLoader::File { key_path } => {
60-
let path = load_env_var(SIGNER_KEYS_ENV).unwrap_or(
61-
key_path.to_str().ok_or_eyre("Missing signer key path")?.to_string(),
62-
);
60+
let path = load_env_var(SIGNER_KEYS_ENV).map(PathBuf::from).unwrap_or(key_path);
6361
let file = std::fs::read_to_string(path)
6462
.unwrap_or_else(|_| panic!("Unable to find keys file"));
6563

@@ -73,12 +71,10 @@ impl SignerLoader {
7371
SignerLoader::ValidatorsDir { keys_path, secrets_path, format } => {
7472
// TODO: hacky way to load for now, we should support reading the
7573
// definitions.yml file
76-
let keys_path = load_env_var(SIGNER_DIR_KEYS_ENV).unwrap_or(
77-
keys_path.to_str().ok_or_eyre("Missing signer keys path")?.to_string(),
78-
);
79-
let secrets_path = load_env_var(SIGNER_DIR_SECRETS_ENV).unwrap_or(
80-
secrets_path.to_str().ok_or_eyre("Missing signer secrets path")?.to_string(),
81-
);
74+
let keys_path =
75+
load_env_var(SIGNER_DIR_KEYS_ENV).map(PathBuf::from).unwrap_or(keys_path);
76+
let secrets_path =
77+
load_env_var(SIGNER_DIR_SECRETS_ENV).map(PathBuf::from).unwrap_or(secrets_path);
8278

8379
return match format {
8480
ValidatorKeysFormat::Lighthouse => {
@@ -114,8 +110,8 @@ impl<'de> Deserialize<'de> for FileKey {
114110
}
115111

116112
fn load_from_lighthouse_format(
117-
keys_path: String,
118-
secrets_path: String,
113+
keys_path: PathBuf,
114+
secrets_path: PathBuf,
119115
) -> eyre::Result<Vec<ConsensusSigner>> {
120116
let entries = fs::read_dir(keys_path.clone())?;
121117

@@ -129,8 +125,8 @@ fn load_from_lighthouse_format(
129125
if path.is_dir() {
130126
if let Some(maybe_pubkey) = path.file_name().and_then(|d| d.to_str()) {
131127
if let Ok(pubkey) = BlsPublicKey::from_hex(maybe_pubkey) {
132-
let ks_path = format!("{}/{}/voting-keystore.json", keys_path, maybe_pubkey);
133-
let pw_path = format!("{}/{}", secrets_path, pubkey);
128+
let ks_path = keys_path.join(maybe_pubkey).join("voting-keystore.json");
129+
let pw_path = secrets_path.join(pubkey.to_string());
134130

135131
match load_one(ks_path, pw_path) {
136132
Ok(signer) => signers.push(signer),
@@ -147,8 +143,8 @@ fn load_from_lighthouse_format(
147143
}
148144

149145
fn load_from_teku_format(
150-
keys_path: String,
151-
secrets_path: String,
146+
keys_path: PathBuf,
147+
secrets_path: PathBuf,
152148
) -> eyre::Result<Vec<ConsensusSigner>> {
153149
let entries = fs::read_dir(keys_path.clone())?;
154150
let mut signers = Vec::new();
@@ -171,8 +167,8 @@ fn load_from_teku_format(
171167
.0;
172168

173169
match load_one(
174-
format!("{keys_path}/{file_name}.json"),
175-
format!("{secrets_path}/{file_name}.txt"),
170+
keys_path.join(format!("{file_name}.json")),
171+
secrets_path.join(format!("{file_name}.txt")),
176172
) {
177173
Ok(signer) => signers.push(signer),
178174
Err(e) => warn!("Sign load error: {e}"),
@@ -183,8 +179,8 @@ fn load_from_teku_format(
183179
}
184180

185181
fn load_from_lodestar_format(
186-
keys_path: String,
187-
password_path: String,
182+
keys_path: PathBuf,
183+
password_path: PathBuf,
188184
) -> eyre::Result<Vec<ConsensusSigner>> {
189185
let entries = fs::read_dir(keys_path)?;
190186
let mut signers = Vec::new();
@@ -198,15 +194,7 @@ fn load_from_lodestar_format(
198194
continue;
199195
}
200196

201-
let key_path = match path.as_os_str().to_str() {
202-
Some(key_path) => key_path,
203-
None => {
204-
warn!("Path {path:?} cannot be converted to string");
205-
continue;
206-
}
207-
};
208-
209-
match load_one(key_path.to_string(), password_path.clone()) {
197+
match load_one(path, password_path.clone()) {
210198
Ok(signer) => signers.push(signer),
211199
Err(e) => warn!("Sign load error: {e}"),
212200
}
@@ -233,8 +221,8 @@ fn load_from_lodestar_format(
233221
/// }
234222
/// ```
235223
fn load_from_prysm_format(
236-
accounts_path: String,
237-
password_path: String,
224+
accounts_path: PathBuf,
225+
password_path: PathBuf,
238226
) -> eyre::Result<Vec<ConsensusSigner>> {
239227
let accounts_file = File::open(accounts_path)?;
240228
let accounts_reader = BufReader::new(accounts_file);
@@ -281,25 +269,26 @@ fn load_from_prysm_format(
281269
Ok(signers)
282270
}
283271

284-
fn load_one(ks_path: String, pw_path: String) -> eyre::Result<ConsensusSigner> {
272+
fn load_one(ks_path: PathBuf, pw_path: PathBuf) -> eyre::Result<ConsensusSigner> {
285273
let keystore = Keystore::from_json_file(ks_path).map_err(|_| eyre!("failed reading json"))?;
286-
let password =
287-
fs::read(pw_path.clone()).map_err(|e| eyre!("Failed to read password ({pw_path}): {e}"))?;
274+
let password = fs::read(pw_path.clone())
275+
.map_err(|e| eyre!("Failed to read password ({}): {e}", pw_path.display()))?;
288276
let key =
289277
keystore.decrypt_keypair(&password).map_err(|_| eyre!("failed decrypting keypair"))?;
290278
ConsensusSigner::new_from_bytes(key.sk.serialize().as_bytes())
291279
}
292280

293281
pub fn load_bls_signer(keys_path: PathBuf, secrets_path: PathBuf) -> eyre::Result<BlsSigner> {
294-
load_one(keys_path.to_string_lossy().to_string(), secrets_path.to_string_lossy().to_string())
282+
load_one(keys_path, secrets_path)
295283
}
296284

297285
pub fn load_ecdsa_signer(keys_path: PathBuf, secrets_path: PathBuf) -> eyre::Result<EcdsaSigner> {
298-
let key_file = std::fs::File::open(keys_path.to_string_lossy().to_string())?;
286+
let key_file = std::fs::File::open(keys_path)?;
299287
let key_reader = std::io::BufReader::new(key_file);
300288
let keystore: JsonKeystore = serde_json::from_reader(key_reader)?;
301289
let password = std::fs::read(secrets_path)?;
302-
let decrypted_password = eth2_keystore::decrypt(&password, &keystore.crypto).unwrap();
290+
let decrypted_password = eth2_keystore::decrypt(&password, &keystore.crypto)
291+
.map_err(|_| eyre::eyre!("Error decrypting ECDSA keystore"))?;
303292

304293
EcdsaSigner::new_from_bytes(decrypted_password.as_bytes())
305294
}

crates/common/src/signer/schemes/ecdsa.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{ops::Deref, str::FromStr};
22

33
use alloy::{
4-
primitives::{Address, PrimitiveSignature, B256},
4+
primitives::{Address, PrimitiveSignature},
55
signers::{local::PrivateKeySigner, SignerSync},
66
};
77
use eyre::ensure;
@@ -63,8 +63,7 @@ pub enum EcdsaSigner {
6363

6464
impl EcdsaSigner {
6565
pub fn new_random() -> Self {
66-
let secret = B256::random();
67-
Self::new_from_bytes(secret.as_slice()).unwrap()
66+
Self::Local(PrivateKeySigner::random())
6867
}
6968

7069
pub fn new_from_bytes(bytes: &[u8]) -> eyre::Result<Self> {

0 commit comments

Comments
 (0)