Preventing ip conflicts in xen
So lately I’m playing with xen kernel and virtualization, and I came across one relatively big problem. Let’s say i want to share my guest machines to… let’s say clients. You must give them root… because that’s whats vps-es all all about… having root access to OS without having to purchase expensive hardware. So having that in mind they are by default untrusted and unpredictable, they can do god knows what in there!
So what caught my eye?
By default xen, and all those tools, cpanels and stuff don’t really have a way of sorting out ip conflicts. So basically you have some bunch of scripts that will setup clients ip address during his machine startup, you have vif ip statment in vm_xen.conf file. But what’s really holds clients from entering:ifconfig eth0 xxx.xxx.xxx.xxx
(where xxx is ip of some super important server in same netmask).
Luckily for me I came across this problem while still in testing, but here’s what I found and came up with after 3 days intensive googling.
So basically xen supports ip declaration in vif statment of dom config file like this:
vif = ['ip=xxx.xxx.xxx.xxx, more parametars here....']
Also you can declare multiple ip’s by simply putting space between them,
like this:
vif = ['ip=xxx.xxx.xxx.xx1 xxx.xxx.xxx.xx2, more parametars here....']
For the purpose of ip conflict prevention make sure you declare unique mac
address in vif section to.
So what does this ip thingy in vif do?
Absolutely nothing! (at least not yet )
Next step is to install ebtables (http://ebtables.sourceforge.net/) on your distro.
After that all we need to do i patch up a vif-bridge script located in /etc/xen/scripts/
So here’s the diff:
[root@vps scripts]# diff -u vif-bridge-org vif-bridge --- vif-bridge-org 2008-07-30 21:26:16.000000000 +0200 +++ vif-bridge 2008-07-30 21:30:59.000000000 +0200 @@ -57,15 +57,35 @@ online) setup_bridge_port "$vif" add_to_bridge "$bridge" "$vif" - ;; - + ebtables -N $vif + ebtables -P $vif DROP + ebtables -A INPUT -i $vif -j $vif + ebtables -A FORWARD -i $vif -j $vif + ebtables -A $vif -p ARP --arp-opcode 1 -j ACCEPT + + if [ ! -z "$ip" ] + then + for oneip in $ip + do + ebtables -A $vif -p IPv4 --ip-src $oneip -j ACCEPT + ebtables -A $vif -p IPv4 --ip-dst $oneip -j ACCEPT + ebtables -A $vif -p ARP --arp-opcode 2 --arp-ip-src $oneip -j ACCEPT + done + ebtables -A $vif --log-prefix="arp-drop" --log-arp -j DROP + fi + ;; + offline) do_without_error brctl delif "$bridge" "$vif" do_without_error ifconfig "$vif" down - ;; + do_without_error ebtables -D INPUT -i $vif -j $vif + do_without_error ebtables -D FORWARD -i $vif -j $vif + do_without_error ebtables -F $vif + do_without_error ebtables -X $vif + ;; esac-handle_iptable +#handle_iptable log debug "Successful vif-bridge $command for $vif, bridge $bridge." if [ "$command" == "online" ]
Presuming you use bridging scripts this effectively binds ip address(es) from “vif = ['ip=xxx.xxx.xxx.xxx']” list to mac addresses from vif list. Binding is done while enabling vps machine and undone when powering it off. So this way untrusted user is limited only to the ip addresses defined in xen guest conf file, trying to change existing ip address into another ip on network will only render that machine unresponsive.
Related posts:
imas supač blogač:) ..sorry..al sam morao spamat malo
..idem hakirat joomle ..LOL
Please notice that as of today
ebtables -A $vif –log-prefix=”arp-drop” –log-arp -j DROP
in script above is moved outside of while loop for adding ip addresses. Thing is if it stays inside of the loop drop statement will be added after first added ip address thus rendering all ip addresses added afterwards inaccessible.
Can you amend this to stop MAC spoofing also?
The diff doesn’t with the vif-script coming with centos 5.3, xen 3.0.3-80. So i made the changes by hand. Now domU won’t boot.
Error: Device 0 (vif) could not be connected. /etc/xen/scripts/vif-bridge-custom failed; error detected.
Is there a way to find out what the error is exactly ? I tried to look at the xend log files, however can’t seem to find anything there.
Thanks
I will look into it, thanks for pointing this out. Can you tell me if ebtables are working properly on your system? Try ebtables -L
Thanks for the reply.
Yes they seem to be working.
ebtables -L
Bridge table: filter
Bridge chain: INPUT, entries: 0, policy: ACCEPT
Bridge chain: FORWARD, entries: 0, policy: ACCEPT
Bridge chain: OUTPUT, entries: 0, policy: ACCEPT
Bridge chain: new, entries: 0, policy: ACCEPT
Here is the diff of the changes i made, if its of any help.
diff -u vif-bridge vif-bridge-custom
— vif-bridge 2009-04-14 23:35:08.000000000 -0400
+++ vif-bridge-custom 2009-04-15 01:33:39.000000000 -0400
@@ -57,15 +57,37 @@
online)
setup_bridge_port “$vif”
add_to_bridge “$bridge” “$vif”
+ ebtables -N $vif
+ ebtables -P $vif DROP
+ ebtables -A INPUT -i $vif -j $vif
+ ebtables -A FORWARD -i $vif -j $vif
+ ebtables -A $vif -p ARP –arp-opcode 1 -j ACCEPT
+
+ if [ ! -z "$ip" ]
+ then
+ for oneip in $ip
+ do
+ ebtables -A $vif -p IPv4 –ip-src $oneip -j ACCEPT
+ ebtables -A $vif -p IPv4 –ip-dst $oneip -j ACCEPT
+ ebtables -A $vif -p ARP –arp-opcode 2 –arp-ip-src $oneip -j ACCEPT
+ done
+
+ ebtables -A $vif –log-prefix=”arp-drop” –log-arp -j DROP
+
+ fi
;;
offline)
do_without_error brctl delif “$bridge” “$vif”
do_without_error ifconfig “$vif” down
+ do_without_error ebtables -D INPUT -i $vif -j $vif
+ do_without_error ebtables -D FORWARD -i $vif -j $vif
+ do_without_error ebtables -F $vif
+ do_without_error ebtables -X $vif
;;
esac
-handle_iptable
+#handle_iptable
log debug “Successful vif-bridge $command for $vif, bridge $bridge.”
if [ "$command" == "online" ]
Is is possible that we can communicate over email ?
So after a while of chating we figured this is infact the correct diff for centos 5.3
I’m including my whole vif-bridge script for centos 5.3 that eventualy worked: Centos 5.3 vif-bridge script
Hi,
I’ve tried this solution, but unfortunately it seems to me that it doesn’t give the expected results. Problem with IP spoofing is still there.
So if you really want to prevent stealing IP adressess inside of XEN domU, here is my tested an 120% working solution – http://xdaan.envirobyte.sk/rand.php?x=xen-ip-conflict