Skip to content

Commit

Permalink
add da client can init with gcs seed
Browse files Browse the repository at this point in the history
  • Loading branch information
JayT106 committed Nov 8, 2024
1 parent 63535ef commit ba7295d
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 17 deletions.
149 changes: 138 additions & 11 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 core/lib/config/src/configs/da_client/avail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ pub struct AvailConfig {
#[derive(Clone, Debug, PartialEq)]
pub struct AvailSecrets {
pub seed_phrase: Option<SeedPhrase>,
pub private_key: Option<String>,
}
1 change: 1 addition & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ impl Distribution<configs::secrets::DataAvailabilitySecrets> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::secrets::DataAvailabilitySecrets {
configs::secrets::DataAvailabilitySecrets::Avail(configs::da_client::avail::AvailSecrets {
seed_phrase: Some(SeedPhrase(Secret::new(self.sample(rng)))),
private_key: None,
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions core/lib/env_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@ anyhow.workspace = true
serde.workspace = true
envy.workspace = true

google-cloud-kms = "0.5.1"
google-cloud-storage = "0.22.1"
hex = "0.4.3"
tokio = { workspace = true, features = ["rt"] }
rustls = "0.23"

[dev-dependencies]
zksync_system_constants.workspace = true
24 changes: 22 additions & 2 deletions core/lib/env_config/src/da_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use zksync_config::configs::{
secrets::DataAvailabilitySecrets,
};

use crate::{envy_load, FromEnv};
use crate::{envy_load, gcloud_encrypted_seed::retrieve_seed_from_gcloud, FromEnv};

impl FromEnv for DAClientConfig {
fn from_env() -> anyhow::Result<Self> {
Expand All @@ -30,11 +30,31 @@ impl FromEnv for DataAvailabilitySecrets {
let client_tag = std::env::var("DA_CLIENT")?;
let secrets = match client_tag.as_str() {
AVAIL_CLIENT_CONFIG_NAME => {
let from_gcs = if let Some(secrets_from_gcs_tag) = env::var("DA_SECRETS_FROM_GCS").ok() {
secrets_from_gcs_tag == "true"
} else {
false
};

let _seed = match from_gcs {
true => {
let gcs_bucket_name = std::env::var("DA_SECRETS_GCS_BUCKET_NAME")
.ok()
.expect("Failed to get DA client secrets from GCS bucket");
let decrypt_key_name = std::env::var("DA_SECRETS_KMS_DECRYPT_KEY_NAME")
.ok()
.expect("Failed to get DA client secrets KMS decrypt key");

Some(retrieve_seed_from_gcloud(decrypt_key_name, gcs_bucket_name))
},
false => None,
};

let seed_phrase = env::var("DA_SECRETS_SEED_PHRASE")
.ok()
.map(|s| s.parse())
.transpose()?;
Self::Avail(AvailSecrets { seed_phrase })
Self::Avail(AvailSecrets { seed_phrase: seed_phrase, private_key: _seed})
}
_ => anyhow::bail!("Unknown DA client name: {}", client_tag),
};
Expand Down
Loading

0 comments on commit ba7295d

Please sign in to comment.