Skip to content

Commit 65a6de5

Browse files
authored
chore!(stackable-webhook): Default listen address to bind to all addresses (#1045)
* chore!(stackable-webhook): Default listen address to bind to all interfaces * changelog * interfaces -> addresses * DEFAULT_SOCKET_ADDR -> DEFAULT_SOCKET_ADDRESS * hint on IPv6 usage
1 parent 88998fc commit 65a6de5

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

crates/stackable-webhook/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@ All notable changes to this project will be documented in this file.
88

99
- Don't pull in the `aws-lc-rs` crate, as this currently fails to build in `make run-dev` ([#1043]).
1010

11+
### Changed
12+
13+
- BREAKING: The constant `DEFAULT_IP_ADDRESS` has been renamed to `DEFAULT_LISTEN_ADDRESS` and binds to all
14+
addresses (instead of only loopback) by default. This was changed because all the webhooks
15+
deployed to Kubernetes (e.g. conversion or mutating - which this crate targets) need to be
16+
accessible by it, which is not the case when only using loopback.
17+
Also, the constant `DEFAULT_SOCKET_ADDR` has been renamed to `DEFAULT_SOCKET_ADDRESS` ([#1045]).
18+
1119
[#1043]: https://github.com/stackabletech/operator-rs/pull/1043
20+
[#1045]: https://github.com/stackabletech/operator-rs/pull/1045
1221

1322
## [0.3.1] - 2024-07-10
1423

crates/stackable-webhook/src/constants.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
55
/// The default HTTPS port `8443`
66
pub const DEFAULT_HTTPS_PORT: u16 = 8443;
77

8-
/// The default IP address `127.0.0.1` the webhook server binds to.
9-
pub const DEFAULT_IP_ADDRESS: IpAddr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
8+
/// The default IP address [`Ipv4Addr::UNSPECIFIED`] (`0.0.0.0`) the webhook server binds to,
9+
/// which represents binding on all network addresses.
10+
//
11+
// TODO: We might want to switch to `Ipv6Addr::UNSPECIFIED)` here, as this *normally* binds to IPv4
12+
// and IPv6. However, it's complicated and depends on the underlying system...
13+
// If we do so, we should set `set_only_v6(false)` on the socket to not rely on system defaults.
14+
pub const DEFAULT_LISTEN_ADDRESS: IpAddr = IpAddr::V4(Ipv4Addr::UNSPECIFIED);
1015

11-
/// The default socket address `127.0.0.1:8443` the webhook server vinds to.
12-
pub const DEFAULT_SOCKET_ADDR: SocketAddr = SocketAddr::new(DEFAULT_IP_ADDRESS, DEFAULT_HTTPS_PORT);
16+
/// The default socket address `0.0.0.0:8443` the webhook server binds to.
17+
pub const DEFAULT_SOCKET_ADDRESS: SocketAddr =
18+
SocketAddr::new(DEFAULT_LISTEN_ADDRESS, DEFAULT_HTTPS_PORT);

crates/stackable-webhook/src/options.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66

77
use stackable_certs::PrivateKeyType;
88

9-
use crate::constants::DEFAULT_SOCKET_ADDR;
9+
use crate::constants::DEFAULT_SOCKET_ADDRESS;
1010

1111
/// Specifies available webhook server options.
1212
///
@@ -78,15 +78,15 @@ impl OptionsBuilder {
7878
/// Sets the IP address of the socket address the webhook server uses to
7979
/// bind for HTTPS.
8080
pub fn bind_ip(mut self, bind_ip: impl Into<IpAddr>) -> Self {
81-
let addr = self.socket_addr.get_or_insert(DEFAULT_SOCKET_ADDR);
81+
let addr = self.socket_addr.get_or_insert(DEFAULT_SOCKET_ADDRESS);
8282
addr.set_ip(bind_ip.into());
8383
self
8484
}
8585

8686
/// Sets the port of the socket address the webhook server uses to bind
8787
/// for HTTPS.
8888
pub fn bind_port(mut self, bind_port: u16) -> Self {
89-
let addr = self.socket_addr.get_or_insert(DEFAULT_SOCKET_ADDR);
89+
let addr = self.socket_addr.get_or_insert(DEFAULT_SOCKET_ADDRESS);
9090
addr.set_port(bind_port);
9191
self
9292
}
@@ -95,7 +95,7 @@ impl OptionsBuilder {
9595
/// explicitly set option.
9696
pub fn build(self) -> Options {
9797
Options {
98-
socket_addr: self.socket_addr.unwrap_or(DEFAULT_SOCKET_ADDR),
98+
socket_addr: self.socket_addr.unwrap_or(DEFAULT_SOCKET_ADDRESS),
9999
}
100100
}
101101
}

0 commit comments

Comments
 (0)