mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-05 01:31:45 +00:00
Pass EL JWT secret key via cli flag (#3568)
## Proposed Changes In this change I've added a new beacon_node cli flag `--execution-jwt-secret-key` for passing the JWT secret directly as string. Without this flag, it was non-trivial to pass a secrets file containing a JWT secret key without compromising its contents into some management repo or fiddling around with manual file mounts for cloud-based deployments. When used in combination with environment variables, the secret can be injected into container-based systems like docker & friends quite easily. It's both possible to either specify the file_path to the JWT secret or pass the JWT secret directly. I've modified the docs and attached a test as well. ## Additional Info The logic has been adapted a bit so that either one of `--execution-jwt` or `--execution-jwt-secret-key` must be set when specifying `--execution-endpoint` so that it's still compatible with the semantics before this change and there's at least one secret provided.
This commit is contained in:
@@ -440,7 +440,6 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
||||
JSON-RPC connection. Uses the same endpoint to populate the \
|
||||
deposit cache.")
|
||||
.takes_value(true)
|
||||
.requires("execution-jwt")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("execution-jwt")
|
||||
@@ -452,6 +451,17 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
||||
.requires("execution-endpoint")
|
||||
.takes_value(true)
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("execution-jwt-secret-key")
|
||||
.long("execution-jwt-secret-key")
|
||||
.value_name("EXECUTION-JWT-SECRET-KEY")
|
||||
.alias("jwt-secret-key")
|
||||
.help("Hex-encoded JWT secret for the \
|
||||
execution endpoint provided in the --execution-endpoint flag.")
|
||||
.requires("execution-endpoint")
|
||||
.conflicts_with("execution-jwt")
|
||||
.takes_value(true)
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("execution-jwt-id")
|
||||
.long("execution-jwt-id")
|
||||
|
||||
@@ -3,6 +3,7 @@ use clap_utils::flags::DISABLE_MALLOC_TUNING_FLAG;
|
||||
use client::{ClientConfig, ClientGenesis};
|
||||
use directory::{DEFAULT_BEACON_NODE_DIR, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR};
|
||||
use environment::RuntimeContext;
|
||||
use execution_layer::DEFAULT_JWT_FILE;
|
||||
use genesis::Eth1Endpoint;
|
||||
use http_api::TlsConfig;
|
||||
use lighthouse_network::{multiaddr::Protocol, Enr, Multiaddr, NetworkConfig, PeerIdSerialized};
|
||||
@@ -288,12 +289,34 @@ pub fn get_config<E: EthSpec>(
|
||||
let execution_endpoint =
|
||||
parse_only_one_value(endpoints, SensitiveUrl::parse, "--execution-endpoint", log)?;
|
||||
|
||||
// Parse a single JWT secret, logging warnings if multiple are supplied.
|
||||
//
|
||||
// JWTs are required if `--execution-endpoint` is supplied.
|
||||
let secret_files: String = clap_utils::parse_required(cli_args, "execution-jwt")?;
|
||||
let secret_file =
|
||||
parse_only_one_value(&secret_files, PathBuf::from_str, "--execution-jwt", log)?;
|
||||
// JWTs are required if `--execution-endpoint` is supplied. They can be either passed via
|
||||
// file_path or directly as string.
|
||||
|
||||
let secret_file: PathBuf;
|
||||
// Parse a single JWT secret from a given file_path, logging warnings if multiple are supplied.
|
||||
if let Some(secret_files) = cli_args.value_of("execution-jwt") {
|
||||
secret_file =
|
||||
parse_only_one_value(secret_files, PathBuf::from_str, "--execution-jwt", log)?;
|
||||
|
||||
// Check if the JWT secret key is passed directly via cli flag and persist it to the default
|
||||
// file location.
|
||||
} else if let Some(jwt_secret_key) = cli_args.value_of("execution-jwt-secret-key") {
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
secret_file = client_config.data_dir.join(DEFAULT_JWT_FILE);
|
||||
let mut jwt_secret_key_file = File::create(secret_file.clone())
|
||||
.map_err(|e| format!("Error while creating jwt_secret_key file: {:?}", e))?;
|
||||
jwt_secret_key_file
|
||||
.write_all(jwt_secret_key.as_bytes())
|
||||
.map_err(|e| {
|
||||
format!(
|
||||
"Error occured while writing to jwt_secret_key file: {:?}",
|
||||
e
|
||||
)
|
||||
})?;
|
||||
} else {
|
||||
return Err("Error! Please set either --execution-jwt file_path or --execution-jwt-secret-key directly via cli when using --execution-endpoint".to_string());
|
||||
}
|
||||
|
||||
// Parse and set the payload builder, if any.
|
||||
if let Some(endpoint) = cli_args.value_of("builder") {
|
||||
|
||||
Reference in New Issue
Block a user