Skip to content

Commit 3857b76

Browse files
aqian01tobz
andauthored
fix(agent-data-plane): preserve DNS for hostname IPC endpoints (#2060)
## Summary Fixes issues found while reviewing the ADP backport in #2058. - Keeps DNS enabled for hostname IPC endpoints. - Disables DNS only for literal-IP and vsock endpoints. - Fixes the proxy-dumper CA certificate condition. ## Validation - `make check-fmt` - `cargo nextest run -p datadog-agent-commons ipc::client::tests` - `target/debug/panoramic list -d test/integration/cases --runtime linux` Co-authored-by: toby.lawrence <toby.lawrence@datadoghq.com>
1 parent 0025407 commit 3857b76

3 files changed

Lines changed: 47 additions & 7 deletions

File tree

docker/Dockerfile.proxy-dumper

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ FROM ${APP_IMAGE}
2222
# For local builds, the regular Ubuntu application image needs to have the CA certificates installed, but it also uses
2323
# the `root` user, so we can install them without issue. Use the repository's available version because Ubuntu
2424
# repositories do not retain old exact package versions indefinitely.
25-
RUN test -d /usr/local/share/ca-certificates || apt-get update && \
25+
RUN test -d /usr/share/ca-certificates || (apt-get update && \
2626
apt-get install -y --no-install-recommends ca-certificates && \
27-
apt-get clean
27+
apt-get clean && rm -rf /var/lib/apt/lists)
2828
COPY --from=builder /src/app/target/proxy-dumper /proxy-dumper
2929

3030
EXPOSE 8081

lib/datadog-agent/commons/src/ipc/client/mod.rs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Helpers for interacting with the Datadog Agent.
22
3-
use std::time::Duration;
3+
use std::{net::IpAddr, time::Duration};
44

55
use backon::Retryable as _;
66
use datadog_protos::agent::v1::{
@@ -18,7 +18,7 @@ use saluki_error::{generic_error, ErrorContext as _, GenericError};
1818
use saluki_io::net::client::http::HttpsCapableConnectorBuilder;
1919
use tonic::{
2020
service::interceptor::InterceptedService,
21-
transport::{Channel, Endpoint},
21+
transport::{Channel, Endpoint, Uri},
2222
Code, Request, Response,
2323
};
2424
use tracing::warn;
@@ -72,15 +72,20 @@ impl RemoteAgentClient {
7272
let auth_interceptor = BearerAuthInterceptor::from_file(&config.auth().auth_token_file_path()).await?;
7373
let ipc_cert_file_path = config.auth().ipc_cert_file_path();
7474
let client_tls_config = build_ipc_client_ipc_tls_config(ipc_cert_file_path).await?;
75-
let connector_builder = HttpsCapableConnectorBuilder::default().without_dns_resolution();
75+
let endpoint = config.endpoint()?;
76+
let connector_builder = HttpsCapableConnectorBuilder::default();
77+
let connector_builder = if endpoint_requires_dns_resolution(&endpoint) {
78+
connector_builder
79+
} else {
80+
connector_builder.without_dns_resolution()
81+
};
7682
#[cfg(target_os = "linux")]
7783
let connector_builder = if let Some(addr) = config.vsock_addr()? {
7884
connector_builder.with_vsock_addr(addr)
7985
} else {
8086
connector_builder
8187
};
8288
let https_connector = connector_builder.build(client_tls_config)?;
83-
let endpoint = config.endpoint()?;
8489
let channel = Endpoint::from(endpoint.clone())
8590
.connect_timeout(Duration::from_secs(2))
8691
.connect_with_connector(https_connector)
@@ -263,6 +268,19 @@ impl RemoteAgentClient {
263268
}
264269
}
265270

271+
fn endpoint_requires_dns_resolution(endpoint: &Uri) -> bool {
272+
match endpoint.host() {
273+
Some(host) => {
274+
let host = host
275+
.strip_prefix('[')
276+
.and_then(|host| host.strip_suffix(']'))
277+
.unwrap_or(host);
278+
host.parse::<IpAddr>().is_err()
279+
}
280+
None => false,
281+
}
282+
}
283+
266284
async fn try_query_agent_api(
267285
client: &mut AgentSecureClient<InterceptedService<Channel, BearerAuthInterceptor>>,
268286
) -> Result<(), GenericError> {
@@ -283,3 +301,25 @@ async fn try_query_agent_api(
283301
},
284302
}
285303
}
304+
305+
#[cfg(test)]
306+
mod tests {
307+
use tonic::transport::Uri;
308+
309+
use super::endpoint_requires_dns_resolution;
310+
311+
#[test]
312+
fn hostname_endpoint_requires_dns_resolution() {
313+
let endpoint = "https://datadog-agent:5001".parse::<Uri>().expect("valid URI");
314+
assert!(endpoint_requires_dns_resolution(&endpoint));
315+
}
316+
317+
#[test]
318+
fn literal_ip_endpoints_do_not_require_dns_resolution() {
319+
let ipv4_endpoint = "https://127.0.0.1:5001".parse::<Uri>().expect("valid URI");
320+
assert!(!endpoint_requires_dns_resolution(&ipv4_endpoint));
321+
322+
let ipv6_endpoint = "https://[::1]:5001".parse::<Uri>().expect("valid URI");
323+
assert!(!endpoint_requires_dns_resolution(&ipv6_endpoint));
324+
}
325+
}

lib/saluki-io/src/net/client/http/conn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ impl HttpsCapableConnectorBuilder {
483483
/// DNS, such as Unix sockets, vsock, or literal-IP TCP endpoints. Hostname-based TCP
484484
/// destinations will fail to resolve when this is enabled.
485485
///
486-
/// Defaults to enabled.
486+
/// DNS resolution is enabled by default.
487487
pub fn without_dns_resolution(mut self) -> Self {
488488
self.dns_resolution_disabled = true;
489489
self

0 commit comments

Comments
 (0)