Skip to content
Draft
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
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use crate::{identity, state};
use {crate::test_helpers::MpscAckReceiver, crate::xds::LocalConfig, tokio::sync::Mutex};

const ENABLE_PROXY: &str = "ENABLE_PROXY";
const TRANSPARENT_NETWORK_POLICIES: &str = "TRANSPARENT_NETWORK_POLICIES";
const KUBERNETES_SERVICE_HOST: &str = "KUBERNETES_SERVICE_HOST";
const NETWORK: &str = "NETWORK";
const NODE_NAME: &str = "NODE_NAME";
Expand Down Expand Up @@ -185,6 +186,8 @@ pub struct Config {
pub proxy: bool,
/// If true, a DNS proxy will be used.
pub dns_proxy: bool,
/// If true, the communicatin will be stablished by the original destination port.
pub transparent_network_policies: bool,

pub window_size: u32,
pub connection_window_size: u32,
Expand Down Expand Up @@ -705,6 +708,7 @@ pub fn construct_config(pc: ProxyConfig) -> Result<Config, Error> {

validate_config(Config {
proxy: parse_default(ENABLE_PROXY, true)?,
transparent_network_policies: parse_default(TRANSPARENT_NETWORK_POLICIES, false)?,
// Enable by default; running the server is not an issue, clients still need to opt-in to sending their
// DNS requests to Ztunnel.
dns_proxy: pc
Expand Down
13 changes: 9 additions & 4 deletions src/proxy/outbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,17 @@ impl OutboundConnection {
.selected_workload_ip
.ok_or(Error::NoValidDestination(Box::new((*us.workload).clone())))?;

let original_destination = us.workload_socket_addr()
.ok_or(Error::NoValidDestination(Box::new((*us.workload).clone())))?;

// only change the port if we're sending HBONE
let actual_destination = match us.workload.protocol {
InboundProtocol::HBONE => SocketAddr::from((selected_workload_ip, self.hbone_port)),
InboundProtocol::TCP => us
.workload_socket_addr()
.ok_or(Error::NoValidDestination(Box::new((*us.workload).clone())))?,
InboundProtocol::HBONE => if self.pi.cfg.transparent_network_policies {
original_destination
} else {
SocketAddr::from((selected_workload_ip, self.hbone_port))
},
InboundProtocol::TCP => original_destination,
};
let hbone_target_destination = match us.workload.protocol {
InboundProtocol::HBONE => Some(HboneAddress::SocketAddr(
Expand Down