www.fridu.net

  • Increase font size
  • Default font size
  • Decrease font size

Xen mini-ISP architecture - Quick Start

Print
Article Index
Xen mini-ISP architecture
Setting Basic Infrastruture
Installing a new VM
Network Infrastructure
Zones Security Model
Quick Start
Bugs, New Feature
All Pages

 

QuickStart

Most of us are love to try without any learning curve :) Making the assumption that you have acceptable administation skills and root password of your box, starting Fridu-in-Xen architecture should take you from less than one hour to probably almost one day. When in place, creation of a new VM take excatly one minute, this for a basic but fully YaST compliant OpenSuSE-10.2.

Creating VM automaticlly

Two components will be use for this quickstart Fridu-scripts and a minimal OpenSuSE-102 distribution. Within scrips archive lvm-script is mandatory, it is the one that does automatically every step described in chapter "Installing a VM", second one firewall-script is mandatory only if for Fridu security model. Nevertheless and what ever you will chose to implement later, for a real quickstart I recomment you to use a default configuration in order to maximize "cut and paste". When your first automatically created VM will run, then it will be time for you to taillor this to your own distribution and/or network strategy, starting by trying an Ubuntu in a domu virtual machine. On Dom0 I tested Fridu-Script with OpenSuSE-10.2 Fedora-core5 and Ubuntu-6.1/server and I would expect it to work out of the box on almost any distribution.

Action:

  • get OpenSuS-102.tgz somewhere on a disk visible from your Dom0
  • untar Fridu-scripts archive and type edit ./install.sh to reflect your configuration and install scripts and samples.
  • edit /etc/sysconfig/Fridu-lvm.config to reflect your site preferences.

Assuming that you have a basic XEN configuration in place and a free LVM volume group starting Fridu-lvm.script should you take less than 15mn. Then time to create a new VM with a basic OpenSuSE-102 take on my system 180s, this from typing "return" on script create command to the point where my VM anwser to Dom-O ping.

Start xend with Fridu Network Script

 # if using Fridu security model you need to update xend network script.
  File: /etc/xen/xend-config.sxp
  Line: (network-script 'Fridu-network.script xen-br0:10.10.1.1:255.255.255.0')

  # start xen service
  /etc/init.d/xend start
  > Starting xend   'done'

 
# check  your network bridge is working
  ip link show xen-br0
     > 12: xen-br0: <BROADCAST,UP,10000> mtu 1500 qdisc noqueue
    > link/ether fe:ff:ff:ff:ff:ff brd ff:ff:ff:ff:ff:ff
   brctl show
    > bridge name     bridge id               STP enabled     interfaces
    > xen-br0         8000.000000000000       no

Note: Fridu script for VM creation will work with standard XEN brigde script (/etc/xen/scripts/network-bridge) , nevertheless Fridu security model leveraging zones requirer Fridu-Xen-network.script. The main difference in between both model is that Fridu bridge VMs by zone and later route in between zones, when default Xen script bridge your all your VM to your external NIC interface.

Check you have enough free space on your volume group disk.

You MUST have a working LVM environment to use Fridu VM creation sript, default configuration will create two Logical Volumes per VM with respectively root=5G for swap/tmpfs=1G. Note than while automatic creation of VM only work with LVM, zone security model is independent on disk layering and work perfectly with sparse image file.

  vgscan
    > Reading all physical volumes.  This may take a while...
    > Found volume group "SATA-160GA" using metadata type lvm2

  vgdisplay "SATA-160GA" | grep -i free
    > Free  PE / Size       9641 / 37,66 GB

 

Create your site config file

While every single parameter of VM creation configuration can be defined/overloaded at command line, it is usually a good practice to provide some adequate site default values, this especially for almost static element as: kernel location, bridge name, ...

 
# Minimal site config file
# --------------------------------- 
lvmvg=SATA-160GA                                                         ; # my volument group name without /dev
xenkerneldir=/export/space/xen/boot                                 ;# my xen VM kernel+initrd
linuxroot=/export/space/xen/vm/opensuse-102-lvm.tgz      ;# my linux distrib root backup
vmbr=xen-br0                                                                    ;# default bridge name
vmram=258                                                                       ;# default memory allocated to VM
#
# Check Fridu-lvm.config samples ship with script for complete liste of possible parameters.

 

Creating your first VM

If you have a correctly customized config file and stick to its default name. Then in order to create a new virtual machine, you only have to provide "name+ip-address". Obviously you may want to customize more things as: network mac adress, root filesystem, size, ... but for a basic test those two parameters should be more than enough. 

    Fridu-lvm.script create verbose=1 vmname=xen-test vmip=10.10.12.4
     > Logical volume "xen-test-root" created
     > Logical volume "xen-test-swap" created
     > .. CreateFileSystem check if /dev/SATA-160GA/xen-test-root is not formated
     > .. CreateFileSystem building root dir=/dev/SATA-160GA/xen-test-root fs=ext3
     > mke2fs 1.39 (29-May-2006)
     > .. CreateFileSystem check if /dev/SATA-160GA/xen-test-swap is not formated
     > .. CreateFileSystem building swap dir=/dev/SATA-160GA/xen-test-swap
     > Initialisation de la version de l'espace de swap 1, taille = 5368705 kB
     > .. InstallRoot mounting /dev/SATA-160GA/xen-test-root on /tmp/fridu-mnt
     > /dev/SATA-160GA/xen-test-root /tmp/fridu-mnt ext3 rw,data=ordered 0 0
     > .. InstallRoot untar of /export/space/xen/vm/opensuse-102-lvm.tgz in /dev/SATA-160GA/xen-test-root
     > .. TuneRoot mounting /SATA-160GA/xen-test-root on /tmp/fridu-mnt
     > /dev/SATA-160GA/xen-test-root /tmp/fridu-mnt ext3 rw,data=ordered 0 0
     > .. TuneRoot make VM root/passwd == to current dom-0
     > .. TuneRoot make sure dom-0 can ssh root@vm without any passwd
     > .. TuneRoot remove udev persistend mode to keep eth0 when vif/MAC change
     > .. TuneRoot remove checksump check from DHCP client
     > .. TuneRoot make sure VM will not try to update hardware clock
     > .. TuneRoot eth0 to support DHCP
     > .. CreateMac reusing existing vmmac=aa:bb:cc:dd:80:11 for vmname=xen-test
     > --
     > Congratulation xen-test is now ready to start

When using verbose=1 as in previous example you get a trace of each step the script is going trough. If needed you can restart the process step by step. Bypassing a step is done by using the option "stepname=no" in command line. By default value is "yes" for every steps except if obvisouly you changed this in your config file. 

  • Create VM 's root+tmpfs/swap logical volume group                         (lvmcreate=yes)
  • Format root LV with a filesystem (default=ext3)                              (fscreate=yes)
  • Untar your root distribution root LV                                                 (installroot=yes)
  • Custumize root distribution to run dhcp client, and few other things (tuneroot=yes)
  • Update your host /etc/hosts and /etc/ethers automatically               (updateether=yes)
  • Build and place vm config file in /etc/xen/vm                                    (createvmconf=yes)

Check you newly generated VM config file

At least at for first VM creation you should check generated config file, and see if is compliant with your site requirements. As everything is done automatically, it should be OK, but shiz.. happen !!! and I did not test on enough different configurations to garanty that it will work everyware and/or under every conditions.

fulup@logoden:~> cat /etc/xen/vm/xen-test (extract)
     > vif  = [ 'mac=aa:bb:cc:dd:80:11, bridge=xen-br0, vifname=xen-test' ]
     > disk = [ 'phy:SATA-160GA/xen-test-root,hda,w','phy:SATA-160GA/xen-test-swap,hdb,w']
     > kernel   = '/export/space/xen/boot/vmlinuz-xen'
     > ramdisk  = '/export/space/xen/boot/initrd-xen'

fulup@logoden:~> grep xen-test /etc/ethers
aa:bb:cc:dd:80:11       xen-test

fulup@logoden:~> grep xen-test /etc/hosts
10.10.12.4 xen-test

You should at least check what my script does not check:

  • Selected bidge exists and is the one you want to use for that given VM
  • IP adress you gave for VM is siting within selected bridge network mask
  • The name you gave was not already present in /etc/hosts in which case your "vmip" param has been overloaded automatically.
  • Kernel+Initrd: script check files existence, but not if it is a valid one.
  • Disk should be OK, except if you bypassed lvm/filesytem creation step.

Start your VM

If everything looks OK, you're ready to try your newly built VM, this with:

fulup@logoden:~>  xm create  -c /etc/xen/vm/xen-test
Processing config file "/etc/xen/vm/xen-test".
Started domain xen-test
Linux version 2.6.18.2-34-xen (geeko@buildhost) (gcc version 4.1.2 20061115 (prerelease) (SUSE Linux)) #1 SMP Mon Nov 27 11:46:27 UTC 2006
BIOS-provided physical RAM map:
Xen: 0000000000000000 - 0000000010a00000 (usable)
0MB HIGHMEM available.
266MB LOWMEM available.
.... Normal Linux Boot Process .........
Setting up network interfaces:
  lo        IP address: 127.0.0.1/8                                                 done
  eth0    (DHCP) . NET: Registered protocol family 17
  IP/Netmask: 10.10.12.4 / 255.255.255.0 ('xen-test')                   done
.............
Master Resource Control: runlevel 3 has been                             reached
Skipped services in runlevel 3:                                                   irq_balancer nfs splash
Welcome to openSUSE 10.2 (i586) - Kernel 2.6.18.2-34-xen (tty1).
xen-test login:  root
passwd:   (same password as on dom-0) 

This is typical Linux boot process, and it should run smoothly at least in console mode, if you have trouble it will probably come from your network config, this especially is you have many zones and mess up your config.

Distribution Dependencies

They're should not be any decencies to your preferred distribution and this script should work with any distribution. Worse case "tuneroot" will fail to understand your VM administration tree and you will have log by "xm console' to activate DHCP on the right virtual network interface.

I noted that Ubuntu is not shipped with domUloader.py as result "xm create" command cannot extract kernel directly from the VM at boot time and you have to store a local copy on VM kernel inside dom0, but generally in case of trouble it is easier to boot with a kernel from dom0. You can pre-extract kernel from virtual machine with Fridu-kernel-extract.script and then rebuilt xen config with Fridu-lvm.script.

# Extract kernel from VM and place a copy on dom0 
Fridu-kernel-extract.script vmname=xen-test
/dev/XEN-LVM/vm-test2-root /tmp/fridu-root reiserfs rw 0 0
/dev/XEN-LVM/xen-test-root /mnt ext3 rw,data=ordered 0 0
/dev/XEN-LVM/xen-test-root /tmp/fridu-mnt ext3 rw,data=ordered 0 0
----
Sucess: Kernel & Initrd copied in /dev/XEN-LVM/xen-test-root
----
# Update /etc/xen/vm/xen-test config to boot with a kernel store on dom0
Fridu-lvm.script create vmname=xen-test fscreate=no installroot=no tuneroot=no bootfrom=dom0-dir xenkerneldir=/root/boot/xen-test

 

How to delete a VM

Nothing more simple, stop your VM and remove attached logical volume

# Verify your Logical Volumes name for this VM 
1269 # lvscan | grep xen-test
  ACTIVE            '/dev/SATA-160GA/xen-test-root' [5,00 GB] inherit
  ACTIVE            '/dev/SATA-160GA/xen-test-swap' [5,00 GB] inherit
 
# Remove Logical Volume (WARNING: this delete obviously everything)
1272 # lvremove /dev/SATA-160GA/xen-test-*
Do you really want to remove active logical volume "xen-test-root"? [y/n]: y
  Logical volume "xen-test-root" successfully removed
Do you really want to remove active logical volume "xen-test-swap"? [y/n]: y
  Logical volume "xen-test-swap" successfully removed

 

How to Transfert a VM to an other host/environement.

Stop your VM, mount in Dom-0 root logical volume and send your backup.tgz to where ever you have to, at destination rerun Freidu-in-Xen create script on your received root backup.tgz.

# stop your VM 
1251 # xm shutdown xen-test  (or beter log root and halt it)
 
# mount your VM inside Dom-0
1252 # mount /dev/SATA-160GA/xen-test-root /mnt/
 
# backup your VM root WARNING: must do backup from VM root or create script won't works at destination
1253 # cd /mnt
1257 # tar -czf /tmp/xen-test-backup.tgz .
  tar: ./var/run/zmd/zmd-remoting.socket: porte (socket) ignorée
  tar: ./var/run/zmd/zmd-web.socket: porte (socket) ignorée
  .....ignore error on socket files
 
# unmount your VM root logical volume 
1257# cd /tmp
1258 # umount /mnt 

 

Hoop !!! it's not working

They are obvisouly many way to mess up. First I do not pretend that my script is perfect, it is build in bash and is very far from checking everthing it could. Secondly you're not perfect either and you may have done something wrong :)

First class of errors will break script at creation time. Potential errors are almost unlimtted and range from "not enough space" to "already used IP address", "distribution not found", ... In this case you typically restart creation script changing one parameter and bypassing previsouly succeded step. Here after few sample of typical errors.

 # trying to rebuild an existing Logical Volume
1004 # Fridu-lvm.script create vmname=xen-test
 Logical volume "xen-test-root" already exists in volume group "SATA-160GA"
 ERROR: fail to create volume group  /dev/SATA-160GA/xen-test-root
 FATAL fail to create logical volume group [must be fixed]
 Note: create your root+swap LV manually and use 'lvmcreate=no' option
 
# trying to installed on an already formated Logical Volume
1006 # Fridu-lvm.script create vmname=xen-test lvmcreate=no
  /dev/SATA-160GA/xen-test-root /tmp/fridu-mnt ext3 rw,data=ordered 0 0
  ERROR /dev/SATA-160GA/xen-test-root already formated user 'fscreate=force'
  FATAL fail to create root and/or swap filesystem [must be fixed]
  Note: create rootfs/swapfs or force reformating with fscreate=no|force' option
 
# trying to install on an existing distribution (/etc exist in Logical Volume)
1008 # Fridu-lvm.script create vmname=xen-test lvmcreate=no fscreate=no
/dev/SATA-160GA/xen-test-root /tmp/fridu-mnt ext3 rw,data=ordered 0 0
  FATAL: Logical dev=/dev/SATA-160GA/xen-test-root contains a distribution
  Note:  Bypass root install or force reinstallation with option installroot=no|force
 
# trying to install with an already affected ip address (same ip for a different vmname in /etc/hosts)
1011 # Fridu-lvm.script create vmname=xen-test vmip=10.10.12.1
 /dev/SATA-160GA/xen-test-root /tmp/fridu-mnt ext3 rw,data=ordered 0 0
  ERROR: IP=10.10.12.1 already used by xen-br0 in /etc/hosts
  Note:  restart with a different vmip=xx.xx.xx.xx or fix /etc/hosts+ethers
  Use:   ./Fridu-Xen-lvm.script vmname=xen-test vmimp=xx.xx.xx.xx lvmcreate=no fscreate=no installroot=no tuneroot=no
 
# forgeting vm ip address, when vmname is not present in /etc/hosts 
1013 # Fridu-lvm.script create vmname=xen-test  lvmcreate=no fscreate=no installroot=no
   -- missing vmip
   FATAL madatory comamnd line option missing
   Bug: even if a value is not used you MUST provide a dummy value
   **********  Retry ./Fridu-Xen-lvm.script  vmip=xxxx

Second class of errors: create command fly, but "xm create $vmname" fails. In almost every cases this is coming from your newly generated VM config file. You need to check "/etc/xen/vm/$vmame" and try to understand what went wrong. You may have an invalide config for example in your disk definition, this is especially classical when you generate a config on an existing distribution bypassing previous installation steps.

Third class or error: Your VM start, you can connect onto it with "xm console" but it does not do what you want. In most cases problems are coming from network, but you nevertheless can connect from "xm console", in rarer situations kernel will fail to boot.

  • Cannot find mandatory device. After a relatively long wait, you arrive on a "mini shell". What's happen is that your kernel failed to mount your root and you're sitting in the initrd ramdisk. This is probably coming from in invalid "root" value in one of your boot attributes, but it may also come come from a wrong initrd. A this level you have almost no commands but you still can leverage "/sys" pseudo filesystem to browse around. For example "ls /sys/block" will allow you to check which disk are visible, then make sure that "root=/dev/xxx" inside vmconfig is pointing to the good one.
  • Kernel Panic, a little more complex to handle has you do not have any running system.  In most of the case this is coming from a wrong Initrd, a typical example is trying to mount a reiserfs formated logical group with an inirtd that only contains ext3. The best option is to look messages, and eventually to mount from Dom-O your VM LV and look from inside what could be wrong.
  • Your VM start, you can connect from the console, but your network is not working. This is for sure the most typical case. The first thing is to check basic network infrastructure environment: is your DNS running ? does it listen on Dom-0 bridge port? is your VM IP within bridge IP range ?, ... If you do not find any obvious error then the best is to use "tcpdump" in conjuction with "dhcpcd-test" and ping. You connect on the console to force a request and you check from Dom-O packets coming from your VM. When this is done you need then to run tcpdump inside the VM to see if packet are passing from Dom-0 to your VM.

# From VM: Force DHCP requests

Xen-test:~# dhcpcd-test eth0
dhcpcd: MAC address = aa:bb:cc:dd:80:11   (dhcpcd will lock at this point)
 
# From Dom-0: check that packet come from VM
Dom-0:~ # tcpdump -i xen-br0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on xen-br0, link-type EN10MB (Ethernet), capture size 96 bytes
01:25:24.441978 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from xen-test, length: 01:25:24.563211 IP xen-br0.bootps > xen-test.bootpc: BOOTP/DHCP, Reply, length: 322
01:25:24.563572 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from xen-test, length: 01:25:24.508451 IP xen-br0.bootps > xen-test.bootpc: BOOTP/DHCP, Reply, length: 32
 
# Alternatively you can set VM hard assign VM IP from inside and ping
Xen-test:~# ifconfig eth0 10.10.21.4 netmask 255.255.255.0
Xen-test:~# ping 10.10.12.1  (try to ping my local dom-0 bridge)
 
# Check from Dom-0 directly on VM VIF interface
Dom-0:~ # ifconfig xen-test 
Dom-0:~ # tcpdump -i xen-test
 
Note:
  • VM(eth0) and Dom(xen-test) is the same virtual network interface seen from two different environments. When using "ifconfig" on both interfaces you should see that they have equivalent number of RX/TX packet. If this is not the case then your configuration is not what you think it is !!!
  • When making test, and after bridging/unbridging, ... I arrived to situation where my VM/eth0 was disconnected from its corresponding vif on Dom-0, changing "vifname" inside /etc/xen/vm and restarting VM is usually enough to fix the problem.   

Creating of your Firewall and Security zones

Distribution is shipped with tree samples, what ever is your target, I advice you to do is to draw your target network, and to build rule from your graphic.

Let's start with a simple case. We only have one zone, with one external IP and two Xen virtual machines.  Access to virtual machines is done by remapping ssh port from external to internal, and each VM should have a full access to Internet.

  • ssh -p 22 root@MyInternetIP (connect dom0)
  • ssh -p 23 root@MyInternetIP (connect Xen-One )
  • ssh -p 24 root@MyInternetIP (connect Xen-Two)
             ----- Internet --------------
                         |              
           Your ISP FIX Internet IP
              (dom0 10.10.11.5)   
                        |
           ---------------------------------
          (zone-0)                (Future zone)
      xen-br0(10.0.12.1)
   +---------------------------+
    |                            |
 10.10.12.4         10.10.12.5
 Xen-One             Xen-Two

 We only one one zone, each zone is defined with

  • Name (what ever you want until is it unique)
  • Network Interface, this is use to allow incomming traffic
  • External IP address, that is used to allow incomming traffic and to NAT outgoing one.
  • Bridge, which define the entry point for the given zone
  • Zone IP address and the network mark that will contain all VM IPs

We have three applications, each of them is defined with

  • Name (what ever you want until is it unique)
  • Zone name the application site in,as defined previsoully . Note that "none" is a special zone pointing on "Dom0"
  • External port/proto Internet user will see. Note that external interface and IP is inherited from zone definition.
  • Internal VM target IP and port in case we remap the application.

# My first simple sample of Firewall 
# --------------------------------------------------- 
CreateZone NAME=ZA NIC=eth0 EXT=MyExternalIP BR=xen-br0 INT=10.10.12.1 MASK=255.255.255.0
CreateApp  NAME=DOM_SSH  ZONE=none  EXT=tcp:22   INT=eth0 ;# special builtin for Dom0
CreateApp  NAME=VM1_SSH  ZONE=ZA    EXT=tcp:23   INT=10.10.12.4:22
CreateApp  NAME=VM2_SSH  ZONE=ZA    EXT=tcp:24   INT=10.10.12.5:22

An avanced sample, this is more or less the one we have for Fridu in production.

  • One Network Interface
  • Two Internet IP
  • One VPN for admin and Internal services.
  • Two zones (one per admin), First one support two VMs while second one only hold one.
  • VM-Common services(LDAP, backup, IMAP, ...)
  • VM-Fulup  (WebMail, Photos, Video Streaming, ...)
    • VM-Domi (Joomla)
    • VMs can see each other within and outside their containing zone.
    • VMs can talk route to any VPN endpoint and vice versa
             Admin Users                      Internet Users
              (10.10.95.40)                            |
                   [VPN]                    [Operater Network]
    -----------------------------------------------------------------------------------------------------------
    -                        internet
    ------------------------------------------------------------------------------------------------------------
            [VPN]                      [Nat+Dnat]                            [Nat+Dnat]
              |                                      |                                             |
       (tun0   10.10.95.38)      (eth0=91.121.65.140)         (eth0:fail=87.98.130.56)
         Admin Network                        Fridu Fix IPs at OVH
              |                                                     |
     ---------+--------------Routing----------------+-------------
                      |                                   |
             (snat:91.121.65.140)       (snat:87.98.130.56)
                      |                                   |
                  (zFulup)                       (zDomi)
             xen-br2(10.0.1.1)             xen-br3(10.10.2.1)
            +---------------------+           +---------------------------+
            |                      |                         |
          10.10.1.2    10.10.12.5            10.10.2.2
         Common           WEB-Ful          WEB-Dom
 

In this example we have two zones and, while they are both mapped on the same physical network interface (eth0) they are using different external IP adresses.

zFulup is mapped onto  91.121.65.140

  • Accept external traffic from port 25 and map it locally onto vm(Common) port 2525
  • Accept external traffic from 80 and map it onto vm(Web-Fulup) port 8080
  • Accept unlimitted internal traffic

zDomi is mapped onto 87.98.130.56

  • Accept external traffic from 80 and map it onto vm(Web-Fulup) port 8080
  • Accept external traffic from22 and map it onto 22(ssh)

Dom0 (none zone) accept port 22(ssh) and openvpn(44096+563)

  • no special restriction on zone
  • VPN(tun0) can talk to any VMs and vice versa.
  • VMs can talk inside and outside their own zone. 
# Zones definition
# -----------------
IP_ONE=91.121.65.140
IP_TWO=87.98.130.56

CreateZone NAME=zFulup   NIC=eth0 EXT=$IP_ONE BR=xen-br1 INT=10.10.1.1 MASK=255.255.255.0
CreateZone NAME=zDominig NIC=eth0 EXT=$IP_TWO BR=xen-br2 INT=10.10.2.1 MASK=255.255.255.0

# Application Port & Forwarding (default ACCEPT = none)
# ------------------------------------------------------
CreateApp  NAME=DOM0_SSH    ZONE=none      EXT=tcp:22    INT=eth0 ;# special builtin for Dom0
CreateApp  NAME=DOM0_VPNt   ZONE=none      EXT=tcp:563   INT=eth0 ;# OpenVPN in TCP
CreateApp  NAME=DOM0_VPNu   ZONE=none      EXT=udp:44096 INT=eth0 ;# check Custom Rules later

# incomming mail and web are redirected to 8080 in order to allow different vpn mappping
CreateApp  NAME=FulupSMTP   ZONE=zFulup    EXT=tcp:25    INT=10.10.1.2:2525
CreateApp  NAME=FulupWEB    ZONE=zFulup    EXT=tcp:80    INT=10.10.1.3:8080

CreateApp  NAME=DomiSMTP    ZONE=zDominig  EXT=tcp:25    INT=10.10.1.2:2525
CreateApp  NAME=DomiWEB     ZONE=zDominig  EXT=tcp:80    INT=10.10.2.2:8080
CreateApp  NAME=DomiSSH     ZONE=zDominig  EXT=tcp:22    INT=10.10.2.2:22

# Zone Restriction (default input/out ACCEPT all)
# -----------------------------------------------
# TuneZone  NAME=BR2_NOSMPT ZONE=ZA DIR=out ACTION=DROP  PORT=tcp:25
# TuneZone  NAME=BR3_NOSMPT ZONE=ZA DIR=out ACTION=DROP  PORT=tcp:25
# User Before/After Zone Custom Tables (before-input|output|forwarding, after-input|...)
# ----------------------------------------------------------------------------------
if test "$ACTION" = "start" ; then
  DoIt iptables  -A after-forwarding -i xen-br+ -o xen-br+  -j ACCEPT   # allow VM to talk together
  DoIt iptables  -A after-forwarding -i tun+    -o xen-br+  -j ACCEPT    # allow VPN talk to zones
  DoIt iptables  -A after-input         -i  tun+                    -j ACCEPT   # allow VPN talk to dom0
  DoIt iptables  -A after-forwarding -i xen-br+ -o tun+     -j ACCEPT   # allow Zones talk to VPN
fi
 
Note:  in this example we have special rules that are independent of zones, this is necessary anytime you are willing to specify something that is not automatically supported by Fridu-firewall script. The firewall has predefined chains for user custom rules, depending on the label after/before they are included before or after fridu generated chains. Technically those chains are defined in Fridu-firewall common file. The simplest way to understand firewall logic is to dump the rule and to check for result. In this previous case less than 15 lines on input, firewall generated a little more than one hundred iptables.

Guru sample, even if you do not need it today it is important to make sure that you architecture can scale to support your furtur requirements. Next case has been tested in my lab and while today I have no requirement and no money for such a configuration, and wanted to make sure it was possible.

  • Tree zones two mapped on internet with a dedicated NIC, one isolated from Internet.
  • Dom0 support SSH and OpenVPN.
  • First zone as tree VM and second two.
  • First zone handle mail, web and SIP
  • Second zone only web.
  • A tuning rule prevent second zone from sending mail.
  • Custom rules allow unlitted VPN traffic and inter zone communication.

 

 
           Admin Users                                    Internet Users
              (10.10.95.40)                                          |
                   [VPN]                                  [Operater Network]
    ------------------------------------------------------------------------------------------------
    -                                         internet
    ------------------------------------------------------------------------------------------------
           [VPN]                                           [Nat+Dnat]         [Nat+Dnat]
              |                                                         |                          |
       (tun0   10.10.95.38)                 (eth0=91.121.65.140  (eth0:fail=87.98.130.56)
         Admin Network                                    Fridu Fix IPs at OVH
              |                                                                  |
     ---------+--------------Routing----------------------------------------------------------------+-------------
         |                                          |                                                      |
   (no Internet)                     (snat:91.121.65.140)                       (snat:87.98.130.56)
         |                                          |                                                       |
     (zAdmin)                             (zFulup)                                             (zDomi)
 xen-br1(10.10.1.1)               xen-br2(10.0.2.1)                             xen-br3(10.10.3.1)
     +-------+                  +---------------------------------------+                    +--------------------+
          |                        |                  |                      |                     |                    |
     10.10.1.2         10.10.1.3     10.10.12.4      10.10.12.5       10.10.13.2      10.10.13.3
      VM-admin           SIP            Mail             WEB-Ful        WEB-Dom      Brendan

Firewall rules for this sample are defined here after. You may note that the Internet isolated zone does not have any applications defined. This is logical as applications only define autorization for external traffic, we could nevertheless have a special custom rule to prevent outgoing traffic to the external word as well. Check tune rule for zDominig zone that prevent every VM from this zone to send mail, this both externally and internally.

# Zones definition
# -----------------
IP_ONE=91.121.65.140
IP_TWO=87.98.130.56

CreateZone NAME=zAdmin   NIC=none EXT=none    BR=xen-br1 INT=10.10.1.1 MASK=255.255.255.0
CreateZone NAME=zFulup   NIC=eth0 EXT=$IP_ONE BR=xen-br2 INT=10.10.2.1 MASK=255.255.255.0
CreateZone NAME=zDominig NIC=eth0 EXT=$IP_TWO BR=xen-br3 INT=10.10.3.1 MASK=255.255.255.0

# Application Port & Forwarding (default ACCEPT = none)
# ------------------------------------------------------
CreateApp  NAME=DOM0_SSH   ZONE=none      EXT=tcp:22    INT=eth0 ;# special builtin for Dom0
CreateApp  NAME=DOM0_VPN   ZONE=none      EXT=udp:44096 INT=eth0 ;# check User Custom Rules later
CreateApp  NAME=VMA1_SIP   ZONE=zFulup    EXT=udp:5600  INT=10.10.12.3:5600
CreateApp  NAME=VMA1_SMTP  ZONE=zFulup    EXT=tcp:25    INT=10.10.12.4:25
CreateApp  NAME=VMA1_WEB   ZONE=zFulup    EXT=tcp:80    INT=10.10.12.5:8080
CreateApp  NAME=VMB1_WEB1  ZONE=zDominig  EXT=tcp:80    INT=10.10.13.2:8080
CreateApp  NAME=VMB1_WEB2  ZONE=zDominig  EXT=tcp:8080  INT=10.10.13.3:8080

# Zone Restriction (default input/out ACCEPT all)
# -----------------------------------------------
TuneZone  NAME=BR3_NOSMPT ZONE=zDominig DIR=out ACTION=DROP  PORT=tcp:25      # Prevent ZB to send mail

# User Before/After Zone Custom Tables (before-input|output|forwarding, after-input|...)
# ----------------------------------------------------------------------------------
if test "$ACTION" = "start" ; then
  DoIt iptables  -A after-forwarding -i xen-br+ -o xen-br+ -j ACCEPT   # allow VM to talk together
  DoIt iptables  -A after-forwarding -i tun+    -o xen-br+ -j ACCEPT   # allow VPN talk to zones
  DoIt iptables  -A after-input     -i tun+     -j ACCEPT              # allow VPN talk to dom0
  DoIt iptables  -A after-forwarding -i xen-br+ -o tun+    -j ACCEPT    # allow Zones talk to VPN
fi

 



 
Comments (1)
'Next >' link
1 Wednesday, 10 June 2009 03:11
Daniel
Hi,
Just wanted to point out that the two sets of 'Prev - Next' links at the footer of the page are slightly confusing. Maybe the bottom ones should be called 'Older/Newer Article'
BTW, this is a great resource. I will try to understand it and apply it in a similar scenario.
=========> Fulup respond ==============
I agree that having two next/prev link on the same page is confusing :( I kept Joomla default default config, which was not a good idea.
Conclusion: I removed the article/article navigation and kept only the on to browse current article.
Thank you for the TIP.

Add your comment

Your name:
Your email:
Subject:
Comment: