From 1b0d1677a60ea7974c760a437a73b0591d742036 Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Wed, 19 Jun 2024 13:02:07 +0200 Subject: [PATCH 1/2] feat: use loopback ip address instead of alias to improve compatibility Signed-off-by: Reuben Miller --- configuration/contrib/collectd/collectd.conf | 2 +- crates/common/mqtt_channel/src/config.rs | 4 ++-- .../common/tedge_config/src/tedge_config_cli/tedge_config.rs | 2 +- crates/common/tedge_config_macros/examples/macro.rs | 2 +- crates/core/tedge/src/bridge/common_mosquitto_config.rs | 4 ++-- crates/extensions/c8y_mapper_ext/src/converter.rs | 2 +- crates/extensions/tedge_mqtt_bridge/src/config.rs | 2 +- crates/extensions/tedge_mqtt_bridge/tests/bridge.rs | 4 ++-- crates/tests/mqtt_tests/src/test_mqtt_client.rs | 2 +- crates/tests/mqtt_tests/src/test_mqtt_server.rs | 2 +- tests/RobotFramework/tests/tedge/call_tedge_config_list.robot | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) diff --git a/configuration/contrib/collectd/collectd.conf b/configuration/contrib/collectd/collectd.conf index 5cdfbe76492..767c13e83b8 100644 --- a/configuration/contrib/collectd/collectd.conf +++ b/configuration/contrib/collectd/collectd.conf @@ -276,7 +276,7 @@ LoadPlugin unixsock - Host "localhost" + Host "127.0.0.1" Port 1883 ClientId "tedge-collectd" # User "user" diff --git a/crates/common/mqtt_channel/src/config.rs b/crates/common/mqtt_channel/src/config.rs index fbd1a6cfe43..19e6e522809 100644 --- a/crates/common/mqtt_channel/src/config.rs +++ b/crates/common/mqtt_channel/src/config.rs @@ -63,7 +63,7 @@ pub struct Config { pub struct BrokerConfig { /// MQTT host to connect to /// - /// Default: "localhost" + /// Default: "127.0.0.1" pub host: String, /// MQTT port to connect to. Usually it's either 1883 for insecure MQTT and @@ -156,7 +156,7 @@ impl Default for Config { fn default() -> Self { Config { broker: BrokerConfig { - host: String::from("localhost"), + host: String::from("127.0.0.1"), port: 1883, authentication: None, }, diff --git a/crates/common/tedge_config/src/tedge_config_cli/tedge_config.rs b/crates/common/tedge_config/src/tedge_config_cli/tedge_config.rs index 04bcaec5a02..9d08541291a 100644 --- a/crates/common/tedge_config/src/tedge_config_cli/tedge_config.rs +++ b/crates/common/tedge_config/src/tedge_config_cli/tedge_config.rs @@ -584,7 +584,7 @@ define_tedge_config! { client: { /// The host that the thin-edge MQTT client should connect to - #[tedge_config(example = "localhost", default(value = "localhost"))] + #[tedge_config(example = "127.0.0.1", default(value = "127.0.0.1"))] host: String, /// The port that the thin-edge MQTT client should connect to diff --git a/crates/common/tedge_config_macros/examples/macro.rs b/crates/common/tedge_config_macros/examples/macro.rs index 2bc58c01ba3..a0c9471af71 100644 --- a/crates/common/tedge_config_macros/examples/macro.rs +++ b/crates/common/tedge_config_macros/examples/macro.rs @@ -96,7 +96,7 @@ define_tedge_config! { client: { /// The host that the thin-edge MQTT client should connect to - #[tedge_config(example = "localhost", default(value = "localhost"))] + #[tedge_config(example = "127.0.0.1", default(value = "127.0.0.1"))] host: String, /// The port that the thin-edge MQTT client should connect to diff --git a/crates/core/tedge/src/bridge/common_mosquitto_config.rs b/crates/core/tedge/src/bridge/common_mosquitto_config.rs index c9fe53b66ca..60b68be9625 100644 --- a/crates/core/tedge/src/bridge/common_mosquitto_config.rs +++ b/crates/core/tedge/src/bridge/common_mosquitto_config.rs @@ -89,7 +89,7 @@ impl Default for CommonMosquittoConfig { config_file: COMMON_MOSQUITTO_CONFIG_FILENAME.into(), internal_listener: ListenerConfig { port: Some(1883), - bind_address: Some("localhost".into()), + bind_address: Some("127.0.0.1".into()), allow_anonymous: true, require_certificate: false, ..Default::default() @@ -237,7 +237,7 @@ mod tests { .collect(); let mut expected = std::collections::HashSet::new(); - expected.insert("listener 1883 localhost"); + expected.insert("listener 1883 127.0.0.1"); expected.insert("allow_anonymous true"); expected.insert("connection_messages true"); diff --git a/crates/extensions/c8y_mapper_ext/src/converter.rs b/crates/extensions/c8y_mapper_ext/src/converter.rs index 1cbd466c8a6..8f82cebb7d2 100644 --- a/crates/extensions/c8y_mapper_ext/src/converter.rs +++ b/crates/extensions/c8y_mapper_ext/src/converter.rs @@ -3556,7 +3556,7 @@ pub(crate) mod tests { let device_type = "test-device-type".into(); let tedge_config = TEdgeConfig::load_toml_str("service.ty = \"service\""); let c8y_host = "test.c8y.io".into(); - let tedge_http_host = "localhost".into(); + let tedge_http_host = "127.0.0.1".into(); let auth_proxy_addr = "127.0.0.1".into(); let auth_proxy_port = 8001; let auth_proxy_protocol = Protocol::Http; diff --git a/crates/extensions/tedge_mqtt_bridge/src/config.rs b/crates/extensions/tedge_mqtt_bridge/src/config.rs index 54370660ba2..d3c882f79fa 100644 --- a/crates/extensions/tedge_mqtt_bridge/src/config.rs +++ b/crates/extensions/tedge_mqtt_bridge/src/config.rs @@ -225,7 +225,7 @@ mod tests { #[test] fn sets_certs_in_the_provided_mqtt_config() { - let mut opts = MqttOptions::new("dummy-device", "localhost", 1883); + let mut opts = MqttOptions::new("dummy-device", "127.0.0.1", 1883); let device_cert = rcgen::generate_simple_self_signed(["dummy-device".into()]).unwrap(); let c8y_cert = rcgen::generate_simple_self_signed(["dummy-c8y".into()]).unwrap(); diff --git a/crates/extensions/tedge_mqtt_bridge/tests/bridge.rs b/crates/extensions/tedge_mqtt_bridge/tests/bridge.rs index c83fb898814..923c1435fd1 100644 --- a/crates/extensions/tedge_mqtt_bridge/tests/bridge.rs +++ b/crates/extensions/tedge_mqtt_bridge/tests/bridge.rs @@ -37,13 +37,13 @@ fn new_broker_and_client(name: &str, port: u16) -> (AsyncClient, EventLoop) { .spawn(move || broker.start().unwrap()) .unwrap(); AsyncClient::new( - MqttOptions::new(format!("{name}-test-client"), "localhost", port), + MqttOptions::new(format!("{name}-test-client"), "127.0.0.1", port), 10, ) } async fn start_mqtt_bridge(local_port: u16, cloud_port: u16, rules: BridgeConfig) { - let cloud_config = MqttOptions::new("a-device-id", "localhost", cloud_port); + let cloud_config = MqttOptions::new("a-device-id", "127.0.0.1", cloud_port); let service_name = "tedge-mapper-test"; let health_topic = format!("te/device/main/service/{service_name}/status/health") .as_str() diff --git a/crates/tests/mqtt_tests/src/test_mqtt_client.rs b/crates/tests/mqtt_tests/src/test_mqtt_client.rs index 9ec7e9bb628..3119f2cff75 100644 --- a/crates/tests/mqtt_tests/src/test_mqtt_client.rs +++ b/crates/tests/mqtt_tests/src/test_mqtt_client.rs @@ -162,7 +162,7 @@ impl TestCon { let id: String = std::iter::repeat_with(fastrand::alphanumeric) .take(10) .collect(); - let mut options = MqttOptions::new(id, "localhost", mqtt_port); + let mut options = MqttOptions::new(id, "127.0.0.1", mqtt_port); options.set_clean_session(true); let (client, eventloop) = AsyncClient::new(options, 10); diff --git a/crates/tests/mqtt_tests/src/test_mqtt_server.rs b/crates/tests/mqtt_tests/src/test_mqtt_server.rs index d4817eef998..ab465c21e51 100644 --- a/crates/tests/mqtt_tests/src/test_mqtt_server.rs +++ b/crates/tests/mqtt_tests/src/test_mqtt_server.rs @@ -132,7 +132,7 @@ fn spawn_broker() -> u16 { }; std::thread::spawn(move || { - let mut mqttoptions = rumqttc::MqttOptions::new("rumqtt-sync", "localhost", port); + let mut mqttoptions = rumqttc::MqttOptions::new("rumqtt-sync", "127.0.0.1", port); mqttoptions.set_keep_alive(Duration::from_secs(5)); let (mut client, mut connection) = rumqttc::Client::new(mqttoptions, 10); diff --git a/tests/RobotFramework/tests/tedge/call_tedge_config_list.robot b/tests/RobotFramework/tests/tedge/call_tedge_config_list.robot index 125222f05f4..6e5ebe26d34 100644 --- a/tests/RobotFramework/tests/tedge/call_tedge_config_list.robot +++ b/tests/RobotFramework/tests/tedge/call_tedge_config_list.robot @@ -299,7 +299,7 @@ set/unset mqtt.client.host # Undo the change by using the 'unset' command, value returns to default one Execute Command sudo tedge config unset mqtt.client.host ${unset} Execute Command tedge config list - Should Contain ${unset} mqtt.client.host=localhost + Should Contain ${unset} mqtt.client.host=127.0.0.1 set/unset mqtt.client.port Execute Command sudo tedge config set mqtt.client.port 1888 From e54f81a72a94b1c4ae45105c39711be24d76818c Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Wed, 19 Jun 2024 13:39:27 +0200 Subject: [PATCH 2/2] tests: include loopback address in alternative names when generating certs for localhost Signed-off-by: Reuben Miller --- crates/common/axum_tls/test_data/_regenerate_certs.sh | 2 +- .../tests/cumulocity/configuration/generate_certificates.sh | 4 ++-- tests/RobotFramework/tests/mqtt/gen_certs.sh | 2 +- tests/images/debian-systemd/files/bootstrap.sh | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/common/axum_tls/test_data/_regenerate_certs.sh b/crates/common/axum_tls/test_data/_regenerate_certs.sh index aac21b159a6..6926d40cae0 100755 --- a/crates/common/axum_tls/test_data/_regenerate_certs.sh +++ b/crates/common/axum_tls/test_data/_regenerate_certs.sh @@ -6,7 +6,7 @@ days=365000 args=("-days" "$days" "-noenc" \ -subj "/CN=localhost" \ - -addext "subjectAltName=DNS:localhost,DNS:*.localhost" \ + -addext "subjectAltName=DNS:localhost,DNS:*.localhost,IP:127.0.0.1" \ -addext "basicConstraints=critical,CA:false") set -eux diff --git a/tests/RobotFramework/tests/cumulocity/configuration/generate_certificates.sh b/tests/RobotFramework/tests/cumulocity/configuration/generate_certificates.sh index e24e047a9ff..138cc8ba806 100755 --- a/tests/RobotFramework/tests/cumulocity/configuration/generate_certificates.sh +++ b/tests/RobotFramework/tests/cumulocity/configuration/generate_certificates.sh @@ -30,7 +30,7 @@ authorityKeyIdentifier=keyid basicConstraints=CA:FALSE keyUsage = digitalSignature, keyAgreement extendedKeyUsage = serverAuth, clientAuth -subjectAltName=DNS:localhost,IP:$C8Y_PROXY_COMMON_NAME +subjectAltName=DNS:localhost,IP:$C8Y_PROXY_COMMON_NAME,IP:127.0.0.1 EOF openssl x509 -req \ @@ -49,7 +49,7 @@ authorityKeyIdentifier=keyid basicConstraints=CA:FALSE keyUsage = digitalSignature, keyAgreement extendedKeyUsage = serverAuth, clientAuth -subjectAltName=DNS:localhost,IP:$FTS_COMMON_NAME +subjectAltName=DNS:localhost,IP:$FTS_COMMON_NAME,IP:127.0.0.1 EOF openssl genrsa -out main-agent.key 2048 diff --git a/tests/RobotFramework/tests/mqtt/gen_certs.sh b/tests/RobotFramework/tests/mqtt/gen_certs.sh index 06ede937419..00db412cfb4 100644 --- a/tests/RobotFramework/tests/mqtt/gen_certs.sh +++ b/tests/RobotFramework/tests/mqtt/gen_certs.sh @@ -21,7 +21,7 @@ cat > v3.ext << EOF authorityKeyIdentifier=keyid basicConstraints=CA:FALSE keyUsage = digitalSignature, keyAgreement -subjectAltName=DNS:$(hostname),DNS:localhost +subjectAltName=DNS:$(hostname),DNS:localhost,IP:127.0.0.1 EOF openssl x509 -req \ diff --git a/tests/images/debian-systemd/files/bootstrap.sh b/tests/images/debian-systemd/files/bootstrap.sh index 259834c68d1..b0448c31837 100755 --- a/tests/images/debian-systemd/files/bootstrap.sh +++ b/tests/images/debian-systemd/files/bootstrap.sh @@ -695,7 +695,7 @@ gen_certs() { authorityKeyIdentifier=keyid basicConstraints=CA:FALSE keyUsage = digitalSignature, keyAgreement - subjectAltName=DNS:$(hostname), DNS:localhost + subjectAltName=DNS:$(hostname), DNS:localhost, IP:127.0.0.1 EOF openssl x509 -req \ @@ -774,7 +774,7 @@ authorityKeyIdentifier=keyid basicConstraints=CA:FALSE keyUsage = digitalSignature, keyAgreement extendedKeyUsage = serverAuth, clientAuth -subjectAltName=DNS:${CN},DNS:localhost +subjectAltName=DNS:${CN},DNS:localhost,IP:127.0.0.1 EOF )