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

feat: add da client can be initialized with the gcs seed #97

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading