Skip to content

Add outbound_addr to allow for SNAT instead of MASQ #1180

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lto-dev
Copy link

@lto-dev lto-dev commented Feb 15, 2025

Added outbound_addr to the bridge driver.

I created a bridge-snat plugin to use this feature and do SNAT instead of MASQUERADE on certain networks since i have multiple public ip's on same machine and i needed the traffic to go out on them and not on the gateway.
I can share the plugin as well if anyone wants it.

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add proper integration test in test/ for both iptables and nftables

I have not yet looked into the rules that are added and if they are correct

Also I think this would need to be added to the firewalld code as well cc @mheon

@lto-dev
Copy link
Author

lto-dev commented Feb 17, 2025

let me know if the modifications are ok

@lto-dev lto-dev requested a review from Luap99 February 19, 2025 17:40
@Luap99
Copy link
Member

Luap99 commented Feb 25, 2025

Note I do not have time to properly review the rules right now. However please make sure your commits make sense as individual unit. Currently they are pretty meaningless so I suggest you squash everything into one

Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, looking at this closer a single outbound_addr option that only accept ipv4 doesn't seem to logically if we still require ipv6 masquerading.

Should we not have two options then one for ipv4_outbound address and one for ipv6_outbound address instead then?

@mheon I assume this would have to be implemented in the firewalld driver as well?

network_setup.isolation,
network_setup.dns_port,
);
network_hash_name: network_setup.network_hash_name.clone(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is cloning the network hash now which should not be necessary AFAICS. It is always good to avoid extra clones where possible. You should keep the hash &str defined (yes that means defining a lifetime one the struct)

Comment on lines 391 to 394
outbound_addr: parse_option::<IpAddr>(
&self.info.network.options,
OPTION_OUTBOUND_ADDR,
)?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options should be parsed as first thing in validate() to return errors on incorrect values early and not once we already created the interfaces as they would have to be cleaned up again.

@mheon
Copy link
Member

mheon commented Jul 22, 2025

For firewalld, this would force all of our NAT to be through rich rules, as the standard port-forwarding rules don't allow for this. Would be a pretty significant change if we wanted to make it.

@Luap99
Copy link
Member

Luap99 commented Jul 22, 2025

For firewalld, this would force all of our NAT to be through rich rules, as the standard port-forwarding rules don't allow for this. Would be a pretty significant change if we wanted to make it.

I guess we should throw an error if firewalld is used with this option. Given the likely low usage of firewalld users I don't think we need to implement this right now for this PR then.

@lto-dev
Copy link
Author

lto-dev commented Jul 23, 2025

Should we not have two options then one for ipv4_outbound address and one for ipv6_outbound address instead then?

I was trying to mimic some of the docker behavior, i use ipv4.
I'll have to take a look into ipv6 snat for this if you decide you want it. When i started the pr i was reading ipv6 nat is discouraged so i didn't approach it.

it looks like their bridge supports ipv6...or not, documentation is kinda conflicting
com.docker.network.bridge.host_binding_ipv4 | all IPv4 and IPv6 addresses | Default IP when binding container ports.

let me know if you want it and what names to use for it

@Luap99
Copy link
Member

Luap99 commented Jul 24, 2025

I think for consistency it makes sense to have it assuming kernel wise is basically the same rule with ipv6? If it turns out to be more complicated then I am fine with leaving it.

Naming wise I think outbound_addr4 and outbound_addr6 maybe?

@lto-dev lto-dev force-pushed the main branch 2 times, most recently from 6d0c2ae to 4f27a97 Compare July 30, 2025 21:47
@lto-dev lto-dev requested a review from Luap99 July 31, 2025 17:20
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly LGTM

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @mheon PTAL

Copy link
Contributor

openshift-ci bot commented Aug 6, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lto-dev, Luap99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants