mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 12:11:59 +00:00
Add TLS capability to the beacon node HTTP API (#2668)
Currently, the beacon node has no ability to serve the HTTP API over TLS. Adding this functionality would be helpful for certain use cases, such as when you need a validator client to connect to a backup beacon node which is outside your local network, and the use of an SSH tunnel or reverse proxy would be inappropriate. ## Proposed Changes - Add three new CLI flags to the beacon node - `--http-enable-tls`: enables TLS - `--http-tls-cert`: to specify the path to the certificate file - `--http-tls-key`: to specify the path to the key file - Update the HTTP API to optionally use `warp`'s [`TlsServer`](https://docs.rs/warp/0.3.1/warp/struct.TlsServer.html) depending on the presence of the `--http-enable-tls` flag - Update tests and docs - Use a custom branch for `warp` to ensure proper error handling ## Additional Info Serving the API over TLS should currently be considered experimental. The reason for this is that it uses code from an [unmerged PR](https://github.com/seanmonstar/warp/pull/717). This commit provides the `try_bind_with_graceful_shutdown` method to `warp`, which is helpful for controlling error flow when the TLS configuration is invalid (cert/key files don't exist, incorrect permissions, etc). I've implemented the same code in my [branch here](https://github.com/macladson/warp/tree/tls). Once the code has been reviewed and merged upstream into `warp`, we can remove the dependency on my branch and the feature can be considered more stable. Currently, the private key file must not be password-protected in order to be read into Lighthouse.
This commit is contained in:
@@ -217,6 +217,29 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
||||
.help("Disable serving of legacy data on the /config/spec endpoint. May be \
|
||||
disabled by default in a future release.")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("http-enable-tls")
|
||||
.long("http-enable-tls")
|
||||
.help("Serves the RESTful HTTP API server over TLS. This feature is currently \
|
||||
experimental.")
|
||||
.takes_value(false)
|
||||
.requires("http-tls-cert")
|
||||
.requires("http-tls-key")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("http-tls-cert")
|
||||
.long("http-tls-cert")
|
||||
.help("The path of the certificate to be used when serving the HTTP API server \
|
||||
over TLS.")
|
||||
.takes_value(true)
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("http-tls-key")
|
||||
.long("http-tls-key")
|
||||
.help("The path of the private key to be used when serving the HTTP API server \
|
||||
over TLS. Must not be password-protected.")
|
||||
.takes_value(true)
|
||||
)
|
||||
/* Prometheus metrics HTTP server related arguments */
|
||||
.arg(
|
||||
Arg::with_name("metrics")
|
||||
|
||||
@@ -4,6 +4,7 @@ use client::{ClientConfig, ClientGenesis};
|
||||
use directory::{DEFAULT_BEACON_NODE_DIR, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR};
|
||||
use eth2_libp2p::{multiaddr::Protocol, Enr, Multiaddr, NetworkConfig, PeerIdSerialized};
|
||||
use eth2_network_config::{Eth2NetworkConfig, DEFAULT_HARDCODED_NETWORK};
|
||||
use http_api::TlsConfig;
|
||||
use sensitive_url::SensitiveUrl;
|
||||
use slog::{info, warn, Logger};
|
||||
use std::cmp;
|
||||
@@ -111,6 +112,21 @@ pub fn get_config<E: EthSpec>(
|
||||
client_config.http_api.serve_legacy_spec = false;
|
||||
}
|
||||
|
||||
if cli_args.is_present("http-enable-tls") {
|
||||
client_config.http_api.tls_config = Some(TlsConfig {
|
||||
cert: cli_args
|
||||
.value_of("http-tls-cert")
|
||||
.ok_or("--http-tls-cert was not provided.")?
|
||||
.parse::<PathBuf>()
|
||||
.map_err(|_| "http-tls-cert is not a valid path name.")?,
|
||||
key: cli_args
|
||||
.value_of("http-tls-key")
|
||||
.ok_or("--http-tls-key was not provided.")?
|
||||
.parse::<PathBuf>()
|
||||
.map_err(|_| "http-tls-key is not a valid path name.")?,
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Prometheus metrics HTTP server
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user