-
Notifications
You must be signed in to change notification settings - Fork 260
fix: block wireserver port 80 traffic in multitenancy #2395
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
Conversation
2a4d40d to
c6acc01
Compare
82e82a1 to
658d3c9
Compare
|
|
||
| func BlockWireserverTraffic() error { | ||
| // iptables -t filter -I FORWARD -j DROP -d <wireserver ip>/32 -p tcp -m tcp --dport 80 | ||
| dropWireserver := fmt.Sprintf("-d %s/32 -p tcp -m tcp --dport 80", AzureDNS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should drop for udp as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replicating capz rule to block for tcp protocol only as we discussed.
| return nil | ||
| } | ||
|
|
||
| func BlockWireserverTraffic() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can it be BlockEgressTrafficFromContainer(ipAddress, port)?
987e54b to
744d816
Compare
network/network_linux.go
Outdated
| } | ||
| logger.Info("Ipv4 forwarding enabled") | ||
| if err := networkutils.BlockEgressTrafficFromContainer(networkutils.AzureDNS, iptables.HTTPPort); err != nil { | ||
| return nil, fmt.Errorf("unable to insert vm iptables rule drop all wireserver port 80 packets: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Port 80 in the error message is from iptables.HTTPPort ? if so can we use the variable instead of hard coding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Should we be using errors.wrapf (not sure but want to keep the cni files consistent going forward)?
@tamilmani1989
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Port 80 in the error message is from
iptables.HTTPPort? if so can we use the variable instead of hard coding.
The insert ip table function calls the ExecuteCommand function (which logs the command itself) so I'll probably remove the details (like port or ip) from the error message altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we should errors.Wrapf .. @QxBytes can you make that change?
| func BlockEgressTrafficFromContainer(ipAddress string, port int) error { | ||
| // iptables -t filter -I FORWARD -j DROP -d <ip>/32 -p tcp -m tcp --dport <port> | ||
| dropTraffic := fmt.Sprintf("-d %s/32 -p tcp -m tcp --dport %d", ipAddress, port) | ||
| return errors.Wrap(iptables.InsertIptableRule(iptables.V4, iptables.Filter, iptables.Forward, dropTraffic, iptables.Drop), "iptables block traffic failed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are just blocking ipv4 ? Should we make the function intake the type of address as well ? (ipv4 or ipv6)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no ipv6 wireserver endpoint. but i asked @QxBytes to create separate PR for blocking all ipv6 addrs from pod.
aa25ae8 to
87aee51
Compare
| return nil | ||
| } | ||
|
|
||
| func BlockEgressTrafficFromContainer(ipAddress string, port int) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we take protocol also as part of arg?
| func BlockEgressTrafficFromContainer(ipAddress string, port int) error { | ||
| // iptables -t filter -I FORWARD -j DROP -d <ip>/32 -p tcp -m tcp --dport <port> | ||
| dropTraffic := fmt.Sprintf("-d %s/32 -p tcp -m tcp --dport %d", ipAddress, port) | ||
| return errors.Wrap(iptables.InsertIptableRule(iptables.V4, iptables.Filter, iptables.Forward, dropTraffic, iptables.Drop), "iptables block traffic failed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no ipv6 wireserver endpoint. but i asked @QxBytes to create separate PR for blocking all ipv6 addrs from pod.
network/network_linux.go
Outdated
| } | ||
| logger.Info("Ipv4 forwarding enabled") | ||
| if err := networkutils.BlockEgressTrafficFromContainer(networkutils.AzureDNS, iptables.HTTPPort); err != nil { | ||
| return nil, fmt.Errorf("unable to insert vm iptables rule drop all wireserver port 80 packets: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we should errors.Wrapf .. @QxBytes can you make that change?
network/network_linux.go
Outdated
| } | ||
| logger.Info("Ipv4 forwarding enabled") | ||
| if err := networkutils.BlockEgressTrafficFromContainer(iptables.V4, networkutils.AzureDNS, iptables.HTTPPort); err != nil { | ||
| return nil, fmt.Errorf("unable to insert vm iptables rule drop wireserver packets: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use errors.wrapf
2d7b3b2 to
90e6e83
Compare
| if err := iptables.InsertIptableRule(iptables.V4, "mangle", "PREROUTING", match, "ACCEPT"); err != nil { | ||
| return errors.Wrap(err, "unable to insert iptables rule accept all incoming from vlan interface") | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment this is for blocking wireserver traffic from customer vnet nic
| return nil, errors.Wrap(err, "ipv4 forwarding failed") | ||
| } | ||
| logger.Info("Ipv4 forwarding enabled") | ||
| if err := networkutils.BlockEgressTrafficFromContainer(iptables.V4, networkutils.AzureDNS, iptables.TCP, iptables.HTTPPort); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a comment this is for blocking wireserver traffic from apipa nic
252da62 to
317948f
Compare
317948f to
79a2698
Compare
* Add vm and vnet ns block wireserver port 80 rule * Use existing variable for known ip * Move code to networkutils * Address feedback * Address iptables version feedback * Address protocol and format feedback * Add comments * Remove cidr in case ipv6 is used
Reason for Change:
Pods should not be able to communicate with the wireserver on port 80.
Issue Fixed:
See above.
Requirements:
Notes: