-
Notifications
You must be signed in to change notification settings - Fork 383
fix(server)!: reject a wildcard bind with no advertised address #3923
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
Open
chengxilo
wants to merge
16
commits into
apache:master
Choose a base branch
from
chengxilo:fix-unreachable-roster-candidates
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2b6fc1a
fix(server)!: reject a wildcard bind with no advertised address
chengxilo 7f78459
fix(test): add env for test container for Csharp and Python
chengxilo 20031ae
retry-ci
chengxilo 8611c14
Merge branch 'master' into fix-unreachable-roster-candidates
chengxilo 0bd9d96
Merge branch 'master' into fix-unreachable-roster-candidates
chengxilo 2c5c5c5
Merge branch 'master' into fix-unreachable-roster-candidates
chengxilo 219d539
fix(configs): restore serde default on personal access token
chengxilo 201b6bc
fix(configs): reject the v4-mapped spelling of the wildcard address
chengxilo 3317d35
fix(server): compare roster and bind addresses on the canonical form
chengxilo 3a23b62
fix(docker): advertise a dialable address in docker compose
chengxilo fab6dc2
update Java test container env for new rule
chengxilo 8fbfa25
fix(doc): update the command example
chengxilo 4e03b36
feat(helm): refuse setting the advertised address two ways at once
chengxilo 1806876
fix(server): publish the single node's advertised address normalized
chengxilo 7a4d1d0
fix(configs): reject an unspecified address at roster node conversion
chengxilo 850c340
fix(server): warn when the derived address misses a listener
chengxilo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| // This node's own client-facing identity, for the cluster-disabled server. | ||
|
|
||
| use super::COMPONENT; | ||
| use super::cluster::AdvertisedAddress; | ||
| use crate::ConfigurationError; | ||
| use configs::ConfigEnv; | ||
| use iggy_common::Validatable; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// Named to match its roster counterpart: `advertised_address` here and | ||
| /// `cluster.nodes[*].advertised_address` there are the same setting for the | ||
| /// same question, and an operator moving between the two modes should not have | ||
| /// to learn a second spelling. | ||
| #[derive(Debug, Default, Deserialize, Serialize, Clone, ConfigEnv)] | ||
| #[serde(deny_unknown_fields)] | ||
| pub struct NodeConfig { | ||
| /// Client-facing address: a literal IP or a DNS hostname. `None` leaves | ||
| /// the server deriving one from its bind address. | ||
| #[serde(default)] | ||
| pub advertised_address: Option<String>, | ||
| } | ||
|
|
||
| impl Validatable<ConfigurationError> for NodeConfig { | ||
| fn validate(&self) -> Result<(), ConfigurationError> { | ||
| let Some(address) = self.advertised_address.as_deref() else { | ||
| return Ok(()); | ||
| }; | ||
|
|
||
| let parsed = address.parse::<AdvertisedAddress>().map_err(|error| { | ||
| eprintln!("{COMPONENT} - node.advertised_address '{address}': {error}"); | ||
| ConfigurationError::InvalidConfigurationValue | ||
| })?; | ||
|
|
||
| if parsed.is_unspecified() { | ||
| eprintln!( | ||
| "{COMPONENT} - node.advertised_address '{address}' is the unspecified address, \ | ||
| which tells a client which interfaces this node accepts on rather than where to \ | ||
| reach it; declare a routable address or leave it unset" | ||
| ); | ||
| return Err(ConfigurationError::InvalidConfigurationValue); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| fn advertised(address: &str) -> NodeConfig { | ||
| NodeConfig { | ||
| advertised_address: Some(address.to_owned()), | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn validate_accepts_an_unset_address() { | ||
| assert!(NodeConfig::default().validate().is_ok()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn validate_accepts_a_routable_address() { | ||
| assert!(advertised("203.0.113.10").validate().is_ok()); | ||
| assert!(advertised("broker-1.example.com").validate().is_ok()); | ||
| assert!(advertised("2001:db8::1").validate().is_ok()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn validate_rejects_an_unspecified_address() { | ||
| assert!(advertised("0.0.0.0").validate().is_err()); | ||
| assert!(advertised("::").validate().is_err()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn validate_rejects_an_unparsable_address() { | ||
| assert!(advertised("broker-1.example.com:8090").validate().is_err()); | ||
| assert!(advertised("10.0.0.256").validate().is_err()); | ||
| assert!(advertised("").validate().is_err()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
core/integration/tests/server/cluster_metadata_advertised.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| //! `node.advertised_address` on a cluster-disabled server: what a client is | ||
| //! told about the one node in the roster. | ||
| //! | ||
| //! Without a roster the server has only its own bind address to reason from, | ||
| //! and a bind address answers which interfaces it accepts on - never where a | ||
| //! client reaches it. Behind any NAT (published container ports, a Service, a | ||
| //! load balancer) the two are different addresses, and this setting is the | ||
| //! only way to state the second one. The bind-derived fallback and the empty | ||
| //! answer for a wildcard bind are pinned at unit level (`cluster_meta.rs`) | ||
| //! and across the SDKs in `bdd/`; what needs a real server is that a declared | ||
| //! address survives config load and reaches the wire. | ||
|
|
||
| use iggy::prelude::*; | ||
| use integration::iggy_harness; | ||
|
|
||
| const ADVERTISED_ADDRESS: &str = "broker-1.example.com"; | ||
|
|
||
| // The harness runs a VSR cluster by default, where the roster answers the | ||
| // client-facing address per node and this setting is deliberately ignored. One | ||
| // node with clustering off is the shape that reaches the self-synthesized | ||
| // path: `--replica-id 0` stays valid without a cluster, any higher id does not. | ||
| #[iggy_harness( | ||
| cluster_nodes = 1, | ||
| server(cluster.enabled = false, node.advertised_address = "broker-1.example.com") | ||
| )] | ||
| async fn given_a_declared_advertised_address_when_getting_cluster_metadata_should_publish_it( | ||
| harness: &TestHarness, | ||
| ) { | ||
| let client = harness | ||
| .node(0) | ||
| .tcp_client() | ||
| .expect("tcp client") | ||
| .with_root_login() | ||
| .connect() | ||
| .await | ||
| .expect("connect"); | ||
|
|
||
| let metadata = client | ||
| .get_cluster_metadata() | ||
| .await | ||
| .expect("get cluster metadata"); | ||
|
|
||
| assert_eq!( | ||
| metadata.nodes.len(), | ||
| 1, | ||
| "a cluster-disabled server reports itself alone, got {metadata}" | ||
| ); | ||
| assert!( | ||
| !metadata.name.is_empty(), | ||
| "the single-node label still names the cluster" | ||
| ); | ||
| let node = &metadata.nodes[0]; | ||
| // The harness binds a concrete loopback address, so this also pins the | ||
| // precedence: a declaration outranks an address the bind could vouch for, | ||
| // because only the declaration is a claim about reachability. | ||
| assert_eq!( | ||
| node.ip, ADVERTISED_ADDRESS, | ||
| "the declared address must reach the wire verbatim" | ||
| ); | ||
| assert_ne!( | ||
| node.endpoints.tcp, 0, | ||
| "the self node reports its real tcp port alongside the declared address" | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.