Skip to content

chore!(stackable-webhook): Default listen address to bind to all addresses #1045

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

Merged
merged 6 commits into from
May 21, 2025
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
9 changes: 9 additions & 0 deletions crates/stackable-webhook/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ All notable changes to this project will be documented in this file.

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

### Changed

- BREAKING: The constant `DEFAULT_IP_ADDRESS` has been renamed to `DEFAULT_LISTEN_ADDRESS` and binds to all
addresses (instead of only loopback) by default. This was changed because all the webhooks
deployed to Kubernetes (e.g. conversion or mutating - which this crate targets) need to be
accessible by it, which is not the case when only using loopback.
Also, the constant `DEFAULT_SOCKET_ADDR` has been renamed to `DEFAULT_SOCKET_ADDRESS` ([#1045]).

[#1043]: https://github.com/stackabletech/operator-rs/pull/1043
[#1045]: https://github.com/stackabletech/operator-rs/pull/1045

## [0.3.1] - 2024-07-10

Expand Down
14 changes: 10 additions & 4 deletions crates/stackable-webhook/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
/// The default HTTPS port `8443`
pub const DEFAULT_HTTPS_PORT: u16 = 8443;

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

/// The default socket address `127.0.0.1:8443` the webhook server vinds to.
pub const DEFAULT_SOCKET_ADDR: SocketAddr = SocketAddr::new(DEFAULT_IP_ADDRESS, DEFAULT_HTTPS_PORT);
/// The default socket address `0.0.0.0:8443` the webhook server binds to.
pub const DEFAULT_SOCKET_ADDRESS: SocketAddr =
SocketAddr::new(DEFAULT_LISTEN_ADDRESS, DEFAULT_HTTPS_PORT);
8 changes: 4 additions & 4 deletions crates/stackable-webhook/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use stackable_certs::PrivateKeyType;

use crate::constants::DEFAULT_SOCKET_ADDR;
use crate::constants::DEFAULT_SOCKET_ADDRESS;

/// Specifies available webhook server options.
///
Expand Down Expand Up @@ -78,15 +78,15 @@ impl OptionsBuilder {
/// Sets the IP address of the socket address the webhook server uses to
/// bind for HTTPS.
pub fn bind_ip(mut self, bind_ip: impl Into<IpAddr>) -> Self {
let addr = self.socket_addr.get_or_insert(DEFAULT_SOCKET_ADDR);
let addr = self.socket_addr.get_or_insert(DEFAULT_SOCKET_ADDRESS);
addr.set_ip(bind_ip.into());
self
}

/// Sets the port of the socket address the webhook server uses to bind
/// for HTTPS.
pub fn bind_port(mut self, bind_port: u16) -> Self {
let addr = self.socket_addr.get_or_insert(DEFAULT_SOCKET_ADDR);
let addr = self.socket_addr.get_or_insert(DEFAULT_SOCKET_ADDRESS);
addr.set_port(bind_port);
self
}
Expand All @@ -95,7 +95,7 @@ impl OptionsBuilder {
/// explicitly set option.
pub fn build(self) -> Options {
Options {
socket_addr: self.socket_addr.unwrap_or(DEFAULT_SOCKET_ADDR),
socket_addr: self.socket_addr.unwrap_or(DEFAULT_SOCKET_ADDRESS),
}
}
}
Expand Down
Loading