Skip to content

Commit

Permalink
Allow the operator to set the listening host IP address.
Browse files Browse the repository at this point in the history
This is often useful for security reasons, e.g. only listening on
localhost or an internal IP when the service is to be proxied.

It is also useful in testing on macOS, as running the service bound to a
localhost IP (`127.0.0.1` or `::1`) means that the firewall will not be
alerted, and so the test will not trigger an allow/deny prompt.
  • Loading branch information
SamirTalwar committed Mar 12, 2024
1 parent ad26485 commit 7d6da1b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions rust-connector-sdk/src/default_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ struct ServeCommand {
configuration: PathBuf,
#[arg(long, value_name = "ENDPOINT", env = "OTEL_EXPORTER_OTLP_ENDPOINT")]
otlp_endpoint: Option<String>,
#[arg(
long,
value_name = "HOST IP",
env = "HASURA_CONNECTOR_HOST",
default_value_t = net::IpAddr::V4(net::Ipv4Addr::UNSPECIFIED),
)]
host: net::IpAddr,
#[arg(
long,
value_name = "PORT",
Expand All @@ -67,8 +74,6 @@ struct ServeCommand {
service_token_secret: Option<String>,
#[arg(long, value_name = "NAME", env = "OTEL_SERVICE_NAME")]
service_name: Option<String>,
#[arg(long, env = "HASURA_ENABLE_V2_COMPATIBILITY")]
enable_v2_compatibility: bool,
}

#[derive(Clone, Parser)]
Expand Down Expand Up @@ -233,11 +238,8 @@ where
serve_command.service_token_secret.clone(),
);

let port = serve_command.port;
let address = net::SocketAddr::new(net::IpAddr::V4(net::Ipv4Addr::UNSPECIFIED), port);

let address = net::SocketAddr::new(serve_command.host, serve_command.port);
println!("Starting server on {}", address);

axum::Server::bind(&address)
.serve(router.into_make_service())
.with_graceful_shutdown(async {
Expand Down

0 comments on commit 7d6da1b

Please sign in to comment.