-
Notifications
You must be signed in to change notification settings - Fork 260
Addressing security concerns in Linux Multitenancy #387
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ba0f6ae
Block IP Sppofing in linux multitenacy by verifying the source IP bas…
tamilmani1989 a39b57e
removed tag while adding portto ovs bridge
tamilmani1989 2da96db
addressed review comments
tamilmani1989 71c2047
addressed review comments
tamilmani1989 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,13 @@ const ( | |
| defaultMacForArpResponse = "12:34:56:78:9a:bc" | ||
| ) | ||
|
|
||
| // Open flow rule priorities. Higher the number higher the priority | ||
| const ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider adding priority to the name and switch to enum? |
||
| low = 10 | ||
| mid = 15 | ||
| high = 20 | ||
| ) | ||
|
|
||
| func CreateOVSBridge(bridgeName string) error { | ||
| log.Printf("[ovs] Creating OVS Bridge %v", bridgeName) | ||
|
|
||
|
|
@@ -41,13 +48,7 @@ func DeleteOVSBridge(bridgeName string) error { | |
| } | ||
|
|
||
| func AddPortOnOVSBridge(hostIfName string, bridgeName string, vlanID int) error { | ||
| cmd := "" | ||
|
|
||
| if vlanID == 0 { | ||
| cmd = fmt.Sprintf("ovs-vsctl add-port %s %s", bridgeName, hostIfName) | ||
| } else { | ||
| cmd = fmt.Sprintf("ovs-vsctl add-port %s %s tag=%d", bridgeName, hostIfName, vlanID) | ||
| } | ||
| cmd := fmt.Sprintf("ovs-vsctl add-port %s %s", bridgeName, hostIfName) | ||
| _, err := platform.ExecuteCommand(cmd) | ||
| if err != nil { | ||
| log.Printf("[ovs] Error while setting OVS as master to primary interface %v", err) | ||
|
|
@@ -69,7 +70,7 @@ func GetOVSPortNumber(interfaceName string) (string, error) { | |
| } | ||
|
|
||
| func AddVMIpAcceptRule(bridgeName string, primaryIP string, mac string) error { | ||
| cmd := fmt.Sprintf("ovs-ofctl add-flow %s ip,nw_dst=%s,dl_dst=%s,priority=20,actions=normal", bridgeName, primaryIP, mac) | ||
| cmd := fmt.Sprintf("ovs-ofctl add-flow %s ip,nw_dst=%s,dl_dst=%s,priority=%d,actions=normal", bridgeName, primaryIP, mac, high) | ||
| _, err := platform.ExecuteCommand(cmd) | ||
| if err != nil { | ||
| log.Printf("[ovs] Adding SNAT rule failed with error %v", err) | ||
|
|
@@ -80,8 +81,8 @@ func AddVMIpAcceptRule(bridgeName string, primaryIP string, mac string) error { | |
| } | ||
|
|
||
| func AddArpSnatRule(bridgeName string, mac string, macHex string, ofport string) error { | ||
| cmd := fmt.Sprintf(`ovs-ofctl add-flow %v table=1,priority=10,arp,arp_op=1,actions='mod_dl_src:%s, | ||
| load:0x%s->NXM_NX_ARP_SHA[],output:%s'`, bridgeName, mac, macHex, ofport) | ||
| cmd := fmt.Sprintf(`ovs-ofctl add-flow %v table=1,priority=%d,arp,arp_op=1,actions='mod_dl_src:%s, | ||
| load:0x%s->NXM_NX_ARP_SHA[],output:%s'`, bridgeName, low, mac, macHex, ofport) | ||
| _, err := platform.ExecuteCommand(cmd) | ||
| if err != nil { | ||
| log.Printf("[ovs] Adding ARP SNAT rule failed with error %v", err) | ||
|
|
@@ -91,21 +92,32 @@ func AddArpSnatRule(bridgeName string, mac string, macHex string, ofport string) | |
| return nil | ||
| } | ||
|
|
||
| func AddIpSnatRule(bridgeName string, port string, mac string, outport string) error { | ||
| // IP SNAT Rule - Change src mac to VM Mac for packets coming from container host veth port. | ||
| func AddIpSnatRule(bridgeName string, ip net.IP, vlanID int, port string, mac string, outport string) error { | ||
| var cmd string | ||
| if outport == "" { | ||
| outport = "normal" | ||
| } | ||
|
|
||
| cmd := fmt.Sprintf("ovs-ofctl add-flow %v priority=20,ip,in_port=%s,vlan_tci=0,actions=mod_dl_src:%s,strip_vlan,%v", | ||
| bridgeName, port, mac, outport) | ||
| commonPrefix := fmt.Sprintf("ovs-ofctl add-flow %v priority=%d,ip,nw_src=%s,in_port=%s,vlan_tci=0,actions=mod_dl_src:%s", bridgeName, high, ip.String(), port, mac) | ||
|
|
||
| // This rule also checks if packets coming from right source ip based on the ovs port to prevent ip spoofing. | ||
| // Otherwise it drops the packet. | ||
| if vlanID != 0 { | ||
| cmd = fmt.Sprintf("%s,mod_vlan_vid:%v,%v", commonPrefix, vlanID, outport) | ||
| } else { | ||
| cmd = fmt.Sprintf("%s,strip_vlan,%v", commonPrefix, outport) | ||
| } | ||
|
|
||
| _, err := platform.ExecuteCommand(cmd) | ||
| if err != nil { | ||
| log.Printf("[ovs] Adding IP SNAT rule failed with error %v", err) | ||
| return err | ||
| } | ||
|
|
||
| cmd = fmt.Sprintf("ovs-ofctl add-flow %v priority=10,ip,in_port=%s,actions=drop", | ||
| bridgeName, port) | ||
| // Drop other packets which doesn't satisfy above condition | ||
| cmd = fmt.Sprintf("ovs-ofctl add-flow %v priority=%d,ip,in_port=%s,actions=drop", | ||
| bridgeName, low, port) | ||
| _, err = platform.ExecuteCommand(cmd) | ||
| if err != nil { | ||
| log.Printf("[ovs] Dropping vlantag packet rule failed with error %v", err) | ||
|
|
@@ -134,11 +146,11 @@ func AddFakeArpReply(bridgeName string, ip net.IP) error { | |
| ipAddrInt := common.IpToInt(ip) | ||
|
|
||
| log.Printf("[ovs] Adding ARP reply rule for IP address %v ", ip.String()) | ||
| cmd := fmt.Sprintf(`ovs-ofctl add-flow %s arp,arp_op=1,priority=20,actions='load:0x2->NXM_OF_ARP_OP[], | ||
| cmd := fmt.Sprintf(`ovs-ofctl add-flow %s arp,arp_op=1,priority=%d,actions='load:0x2->NXM_OF_ARP_OP[], | ||
| move:NXM_OF_ETH_SRC[]->NXM_OF_ETH_DST[],mod_dl_src:%s, | ||
| move:NXM_NX_ARP_SHA[]->NXM_NX_ARP_THA[],move:NXM_OF_ARP_TPA[]->NXM_OF_ARP_SPA[], | ||
| load:0x%s->NXM_NX_ARP_SHA[],load:0x%x->NXM_OF_ARP_TPA[],IN_PORT'`, | ||
| bridgeName, defaultMacForArpResponse, macAddrHex, ipAddrInt) | ||
| bridgeName, high, defaultMacForArpResponse, macAddrHex, ipAddrInt) | ||
| _, err := platform.ExecuteCommand(cmd) | ||
| if err != nil { | ||
| log.Printf("[ovs] Adding ARP reply rule failed with error %v", err) | ||
|
|
@@ -163,11 +175,11 @@ func AddArpReplyRule(bridgeName string, port string, ip net.IP, mac string, vlan | |
|
|
||
| // If arp fields matches, set arp reply rule for the request | ||
| log.Printf("[ovs] Adding ARP reply rule for IP address %v and vlanid %v.", ip, vlanid) | ||
| cmd = fmt.Sprintf(`ovs-ofctl add-flow %s table=1,arp,arp_tpa=%s,dl_vlan=%v,arp_op=1,priority=20,actions='load:0x2->NXM_OF_ARP_OP[], | ||
| cmd = fmt.Sprintf(`ovs-ofctl add-flow %s table=1,arp,arp_tpa=%s,dl_vlan=%v,arp_op=1,priority=%d,actions='load:0x2->NXM_OF_ARP_OP[], | ||
| move:NXM_OF_ETH_SRC[]->NXM_OF_ETH_DST[],mod_dl_src:%s, | ||
| move:NXM_NX_ARP_SHA[]->NXM_NX_ARP_THA[],move:NXM_OF_ARP_SPA[]->NXM_OF_ARP_TPA[], | ||
| load:0x%s->NXM_NX_ARP_SHA[],load:0x%x->NXM_OF_ARP_SPA[],strip_vlan,IN_PORT'`, | ||
| bridgeName, ip.String(), vlanid, mac, macAddrHex, ipAddrInt) | ||
| bridgeName, ip.String(), vlanid, high, mac, macAddrHex, ipAddrInt) | ||
| _, err = platform.ExecuteCommand(cmd) | ||
| if err != nil { | ||
| log.Printf("[ovs] Adding ARP reply rule failed with error %v", err) | ||
|
|
@@ -177,15 +189,17 @@ func AddArpReplyRule(bridgeName string, port string, ip net.IP, mac string, vlan | |
| return nil | ||
| } | ||
|
|
||
| func AddMacDnatRule(bridgeName string, port string, ip net.IP, mac string, vlanid int) error { | ||
| // Add MAC DNAT rule based on dst ip and vlanid | ||
| func AddMacDnatRule(bridgeName string, port string, ip net.IP, mac string, vlanid int, containerPort string) error { | ||
| var cmd string | ||
| // This rule changes the destination mac to speciifed mac based on the ip and vlanid. | ||
| // and forwards the packet to corresponding container hostveth port | ||
|
|
||
| commonPrefix := fmt.Sprintf("ovs-ofctl add-flow %s ip,nw_dst=%s,in_port=%s", bridgeName, ip.String(), port) | ||
| if vlanid != 0 { | ||
| cmd = fmt.Sprintf("ovs-ofctl add-flow %s ip,nw_dst=%s,dl_vlan=%v,in_port=%s,actions=mod_dl_dst:%s,normal", | ||
| bridgeName, ip.String(), vlanid, port, mac) | ||
| cmd = fmt.Sprintf("%s,dl_vlan=%v,actions=mod_dl_dst:%s,strip_vlan,%s", commonPrefix, vlanid, mac, containerPort) | ||
| } else { | ||
| cmd = fmt.Sprintf("ovs-ofctl add-flow %s ip,nw_dst=%s,in_port=%s,actions=mod_dl_dst:%s,normal", | ||
| bridgeName, ip.String(), port, mac) | ||
| cmd = fmt.Sprintf("%s,actions=mod_dl_dst:%s,strip_vlan,%s", commonPrefix, mac, containerPort) | ||
| } | ||
| _, err := platform.ExecuteCommand(cmd) | ||
| if err != nil { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.