PDA

View Full Version : OpenVPN server in jail (using a tun device)


Mattias
February 28th, 2011, 02:23
This text tries to describe how to get an OpenVPN (security/openvpn) server running inside a jail. The server will use a TUN device, but the same general procedures might work out with a TAP device.


Contents

Assumptions
The problem
The solution
Troubleshooting
References




Assumptions
Assumptions


The jail setup is similar to the one described in the handbook, 15.6 Application of Jails. [1]
OpenVPN is installed inside the jail and configured to use a TUN device. See the official how-to [2] and the sample configuration under Troubleshooting.
Personal customizations are taken into account. I.e firewall settings, built-in and left-out jail capabilities, security considerations etc.


TheProblem
The problem

On startup OpenVPN tries to (re-)establish a TUN/TAP device and some routes along with it. Since jails doesn't allow this we might be left with some of the following error messages (in log, if not on stdout):

openvpn: writing to routing socket: No such process
Cannot open TUN/TAP dev /dev/tun0: No such file or directory (errno=2)
ioctl(TUNSIFMODE): Device busy: Device busy (errno=16)
ifconfig: ioctl (set mtu): Operation not permitted
ifconfig: up: permission denied
ifconfig failed: external program exited with error status: 1



TheSolution
The solution

Create the TUN device on the host. [3, 4]
Give the jail access to the device. [5, 6]
Configure the TUN interface when jail boots. [7]
Prevent OpenVPN from trying to configure interfaces. [8]


Start off at the host by creating the TUN device...:
# ifconfig tun create
tun0


...on every boot:
vi /etc/rc.conf

Add the following line before any jail settings:
cloned_interfaces="tun"

Check for the new tun interface:
% ifconfig
tun0: flags=8010<POINTOPOINT,MULTICAST> metric 0 mtu 1500
options=80000<LINKSTATE>


Back-up the file defining rules for device access...:
cp /etc/defaults/devfs.rules /etc/defaults/devfs.rules_$(date +%F_%H%M)

...and edit it:
vi /etc/defaults/devfs.rules

Add the following lines, but make sure it fits with your existing rules. Also, substitute <rule #> with the appropriate rule ID's and <jail name> with the name of your jail:

# Support for TUN devices
#
[devfsrules_unhide_tun=<rule #>]
add path tun0 unhide

# Rules for jail <jail name>
#
[devfsrules_jail_<jail name>=<rule #>]
add include $devfsrules_hide_all
add include $devfsrules_unhide_basic
add include $devfsrules_unhide_login
add include $devfsrules_unhide_tun


Add the necessary settings for the jail:
vi /etc/rc.conf

Depending on your current jail and OpenVPN settings you may need to change some of the values:
see rc.conf for information on jail_⟨jname⟩_ip_multi⟨n⟩
the TUN settings wary with your OpenVPN server option, which in the following case is:
server 10.8.0.0 255.255.255.0

With that in mind add the following lines where suitable:
jail_<jail name>_ip_multi0="tun0|10.8.0.1 10.8.0.2 mtu 1500 netmask 255.255.255.255"
jail_<jail name>_devfs_enable="YES"
jail_<jail name>_devfs_ruleset="devfsrules_jail_<jail name>"

Restart the jail and step in:
/etc/rc.d/jail restart <jail name>
jexec <jail ID> su

In the jail, make sure the TUN interface shows up configured and ready for use by OpenVPN:
% ifconfig
tun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> metric 0 mtu 1500
options=80000<LINKSTATE>
inet 10.8.0.1 --> 10.8.0.2 netmask 0xffffffff


Finally, a very crucial option needs to be added to the OpenVPN configuration:
echo 'ifconfig-noexec' >> /path/to/openvpn/server.conf

To start the server...:
openvpn /path/to/openvpn/server.conf

...on every jail boot:
vi /etc/rc.conf

Add the following lines, but change the path to your configuration file:

openvpn_enable="YES"
openvpn_configfile="/path/to/openvpn/server.conf"


From the host, you should now be able to see the jail listening on port 1194:
# netstat -anf inet
[...]
udp4 0 <jail IP>.1194 *.*
[...]


A successful port scan from a remote host could look something like this:
# nmap -sU <jail IP> -p1194-1195
[...]
1194/udp open|filtered openvpn
1195/udp closed unknown
[...]



Troubleshooting
Troubleshooting

When following the above steps, take careful notice on possible differences in path and device names, jail name and IP, devfs rule names and ID's.


Make sure the TUN device exists on the host and in the jail:
ls -l /dev/tun*


Start off with a basic OpenVPN settings. Example:

local <jail IP>
port 1194
proto udp
dev tun0
server 10.8.0.0 255.255.255.0
ca /path/to/ca.crt
cert /path/to/server.crt
key /path/to/server.key
dh /path/to/dh2048.pem
keepalive 10 120
comp-lzo
user nobody
group nobody
persist-key
persist-tun
ifconfig-pool-persist /var/tmp/openvpn.pool
status /var/tmp/openvpn.status
log-append /var/log/openvpn.log
verb 4
mute 20
ifconfig-noexec


When asking for help include:

configuration files (host and jail rc.conf, OpenVPN config)
output from ifconfig, netstat -r and netstat -anf inet.
information on firewalling etc.



References
References

The Handbook: 15.6 Application of Jails, http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/jails-application.html
WWW: OpenVPN HOWTO, http://openvpn.net/index.php/open-source/documentation/howto.html
Man page: ifconfig, see 'create'.
Man page: rc.conf, see 'cloned_interfaces'.
Mail: isc-dhcp3-server in a jail?, David N, http://lists.freebsd.org/pipermail/freebsd-questions/2007-June/151008.html
Mail: dhcpd possible within jail?, Bjoern A. Zeeb, http://lists.freebsd.org/pipermail/freebsd-jail/2008-November/000579.html
Man page: rc.conf, see 'jail_⟨jname⟩_ip_multi⟨n⟩'.
WWW: Linux VServer FAQs, http://linux-vserver.org/Frequently_Asked_Questions#Can_I_run_an_OpenVPN_Se rver_in_a_guest.3F

ghostcorps
May 31st, 2011, 04:29
Hi :)

This is exactly what I am looking for!!! :D

But I get a bit confused here:


With that in mind add the following lines where suitable:
jail_<jail name>_ip_multi0="tun0|10.8.0.1 10.8.0.2 mtu 1500 netmask 255.255.255.255"
jail_<jail name>_devfs_enable="YES"
jail_<jail name>_devfs_ruleset="devfsrules_jail_<jail name>"


I have OpenVPN working perfectly on the host, I can ssh into it etc, but I can not see Webserver (the jail) once on the VPN. What else do I need to add to rc.conf to allow this?

Here are the current configurations upto this point, as requested:

Host
/etc/defaults/devfs.rules

# Support for TUN devices
#
[devfsrules_unhide_tun=4]
add path tun0 unhide

# Devices usually found in a jail.
#
[devfsrules_jail=5]
add include $devfsrules_hide_all
add include $devfsrules_unhide_basic
add include $devfsrules_unhide_login
add include $devfsrules_unhide_tun


Host
/etc/rc.conf

hostname="my.domain.com"
sshd_enable="YES"
ifconfig_em0="inet xxx.xxx.xxx.xx2 netmask 255.255.255.248"
defaultrouter="xxx.xxx.xxx.xx9"
gateway_enable="YES"
firewall_enable="YES"
firewall_script="/etc/ipfw.rules"
firewall_type="closed"
openvpn_enable="YES"
openvpn_configfile="/usr/local/etc/openvpn/server.conf"
openvpn_if="tap"
...
cloned_interfaces="tun"
jail_set_hostname_allow="NO"
jail_enable="YES"
jail_list="webserver"
jail_interface="em0"
jail_devfs_enable="YES"
jail_procfs_enable="YES"
jail_webserver_rootdir="/usr/gaols/webserver"
jail_webserver_interface="em0"
jail_webserver_hostname="webserver"
jail_webserver_ip="xxx.xxx.xxx.xx3"
jail_webserver_devfs_ruleset="devfsrules_jail"


Host
/etc/hosts

::1 localhost localhost.my.domain
127.0.0.1 localhost localhost.my.domain my my.domain.com
xxx.xxx.xxx.xx2 my my.domain.com
192.168.254.1 host
192.168.254.2 webserver


Host
/usr/local/etc/openvpn/server.conf

port 1194
proto udp
dev tap
ca /usr/local/etc/openvpn/keys/ca.crt
cert /usr/local/etc/openvpn/keys/server.crt
key /usr/local/etc/openvpn/keys/server.key # This file should be kept secret
dh /usr/local/etc/openvpn/keys/dh1024.pem
server 192.168.254.0 255.255.255.0
ifconfig-pool-persist ipp.txt
peer-to-peer
keepalive 10 120
comp-lzo
max-clients 10
user root
persist-key
persist-tun
status /var/log/openvpn-status.log
log-append /var/log/openvpn.log
verb 3


Host
#ifconfig
# ifconfig
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM>
ether xx:xx:xx:xx:xx:xx
inet xxx.xxx.xx2 netmask 0xfffffff8 broadcast xxx.xxx.xx5
inet xxx.xxx.xx3 netmask 0xffffffff broadcast xxx.xxx.xx3
inet 1xxx.xxx.xx4 netmask 0xffffffff broadcast xxx.xxx.xx4
media: Ethernet autoselect (1000baseT <full-duplex>)
status: active

...

tap0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=80000<LINKSTATE>
ether 00:bd:8e:20:00:00
inet 192.168.254.1 netmask 0xffffff00 broadcast 192.168.254.255
Opened by PID 20612
tun0: flags=8010<POINTOPOINT,MULTICAST> metric 0 mtu 1500
options=80000<LINKSTATE>


Host
# netstat -r
# netstat -r
Routing tables

Internet:
Destination Gateway Flags Refs Use Netif Expire
default 174.137.139.209 UGS 2 13748 em0
localhost link#5 UH 0 4 lo0
xxx.xxx.xxx.xx8/29 link#1 U 0 0 em0
domain link#1 UHS 0 222 lo0
xxx.xxx.xxx.xx3 link#1 UHS 0 3673 lo0 =>
xxx.xxx.xxx.xx3/32 link#1 U 0 0 em0
xxx.xxx.xxx.xx4 link#1 UHS 0 769 lo0 =>
xxx.xxx.xxx.xx4/32 link#1 U 0 0 em0
192.168.254.0 link#6 U 1 1422 tap0
host link#6 UHS 0 0 lo0

Internet6:
Destination Gateway Flags Netif Expire
localhost localhost UH lo0
fe80::%lo0 link#5 U lo0
fe80::1%lo0 link#5 UHS lo0
ff01:5:: fe80::1%lo0 U lo0
ff02::%lo0 fe80::1%lo0 U lo0


Host
# netstat -anf inet

# netstat -anf inet
Active Internet connections (including servers)
Proto Recv-Q Send-Q Local Address Foreign Address (state)
tcp4 0 52 192.168.254.1.22 192.168.254.3.3813 ESTABLISHED
tcp4 0 0 192.168.254.1.22 *.* LISTEN
tcp4 0 0 xxx.xxx.xxx.xx3.5080 *.* LISTEN
tcp4 0 0 xxx.xxx.xxx.xx3.1935 *.* LISTEN
tcp4 0 0 xxx.xxx.xxx.xx3.10085 *.* LISTEN
tcp4 0 0 xxx.xxx.xxx.xx3.9999 *.* LISTEN
tcp4 0 0 xxx.xxx.xxx.xx3.443 *.* LISTEN
tcp4 0 0 xxx.xxx.xxx.xx3.80 *.* LISTEN
tcp4 0 0 xxx.xxx.xxx.xx4.8080 *.* LISTEN
tcp4 0 0 xxx.xxx.xxx.xx3.21 *.* LISTEN
tcp4 0 0 192.168.254.1.22 192.168.254.4.1761 ESTABLISHED
tcp4 0 0 xxx.xxx.xxx.xx3.21 *.* LISTEN
udp4 0 0 xxx.xxx.xxx.xx2.2501 *.*
udp4 0 0 xxx.xxx.xxx.xx4.514 *.*
udp4 0 0 xxx.xxx.xxx.xx3.514 *.*
udp4 0 0 xxx.xxx.xxx.xx3.514 *.*
udp4 0 0 *.514 *.*


Host nb. Unfortunately, ipfw refuses to be 'closed' so I need to write in all of the closed rules, hence why it is so messy.
# ipfw show
# ipfw show
00010 258 23524 allow ip from any to any via lo0
00011 0 0 allow ip from me to me
00020 0 0 check-state
00030 32 2926 allow icmp from any to any
00060 2096 325045 allow ip from any to xxx.xxx.xxx.xx2 dst-port 1024-7999
00070 0 0 allow ip from any to xxx.xxx.xxx.xx2 dst-port 8001-8088
00080 0 0 allow ip from any to xxx.xxx.xxx.xx2 dst-port 8090-9998
00090 13 960 allow ip from any to xxx.xxx.xxx.xx2 dst-port 10000-65535
00100 0 0 allow ip from any to xxx.xxx.xxx.xx3 dst-port 1024-5079
00110 0 0 allow ip from any to xxx.xxx.xxx.xx3 dst-port 5081-7999
00120 0 0 allow ip from any to xxx.xxx.xxx.xx3 dst-port 8001-8087
00120 0 0 allow ip from any to xxx.xxx.xxx.xx3 dst-port 8090-9998
00120 7 1127 allow ip from any to xxx.xxx.xxx.xx3 dst-port 10000-65535
00800 0 0 deny log logamount 5 ip from any to xxx.xxx.xxx.xx2 dst-port 1-1023
00800 0 0 deny log logamount 5 ip from any to xxx.xxx.xxx.xx3 dst-port 1-19
00800 0 0 deny log logamount 5 ip from any to xxx.xxx.xxx.xx3 dst-port 444-1934
00810 0 0 deny log logamount 5 ip from any to xxx.xxx.xxx.xx3 dst-port 22-79
00810 0 0 deny log logamount 5 ip from any to xxx.xxx.xxx.xx3 dst-port 1936-1023
00820 0 0 deny log logamount 5 ip from any to xxx.xxx.xxx.xx3 dst-port 81-442
00830 0 0 deny ip from any to 1xxx.xxx.xxx.xx2 dst-port 8089
00840 0 0 deny ip from any to xxx.xxx.xxx.xx2 dst-port 9999
00950 0 0 deny ip from any to xxx.xxx.xxx.xx2 dst-port 8000
01010 0 0 deny ip from any to xxx.xxx.xxx.xx3 dst-port 5080
01020 0 0 deny ip from any to xxx.xxx.xxx.xx3 dst-port 8088
01030 0 0 deny ip from any to xxx.xxx.xxx.xx3 dst-port 8089
01040 0 0 deny ip from any to xxx.xxx.xxx.xx3 dst-port 8000
01050 0 0 deny ip from any to xxx.xxx.xxx.xx3 dst-port 9999
02000 0 0 deny ip from any to xxx.xxx.xxx.xx4
65535 36436 5479174 allow ip from any to any


Webserver (jail)
/etc/rc.conf

hostname="my.other.domain.com"
ifconfig_em0="inet xxx.xxx.xxx.xx3 netmask 255.255.255.255"
defaultrouter="xxx.xxx.xxx.xx9"
...
kern_securelevel_enable="YES"
kern_securelevel="3"
portmap_enable="NO"
log_in_vain="YES"
pureftpd_enable="YES"
red5_enable="YES"
openvpn_enable="YES"
openvpn_configfile="/usr/local/etc/openvpn/client.conf"
openvpn_if="tap"

Schnigges
November 16th, 2011, 23:24
First of all, thanks for the great tutorial!
Do you have any hints on how to do the setup for a bridged openvpn? I guess I would have to create a tap device on the host instead of a tun, but I am having trouble creating one (not entirely sure if this would even be the right way). When I try

ifconfig tap0 create 192.168.178.96 up

I get the following error: ifconfig: SIOCIFCREATE2: Invalid argument

Mattias
November 24th, 2011, 09:34
I'm unable to recreate that error, but ifconfig's stderr isn't to be blindly trusted (see example below) :) Maybe try resetting your config related to devices (devfs.rules, rc.conf) as much as possible and make sure the device is destroyed between every try.


# ifconfig tap0 create 1.2.3,4 [notice the comma]
ifconfig: 1.2.3,4: bad value

# ifconfig tap0 create 1.2.3.4 [comma corrected]
ifconfig: create: bad value [create is a bad value]

# ifconfig tap0
tap0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500
[...]

lockdoc
March 6th, 2012, 14:37
I also have a problem on this.

I am using tun1, as tun0 is for my internet connection. From the openvpn.log on the jail side I get the following error:

Tue Mar 6 13:33:45 2012 us=282808 mode = 1
Tue Mar 6 13:33:45 2012 us=282840 show_ciphers = DISABLED
Tue Mar 6 13:33:45 2012 us=282869 show_digests = DISABLED
Tue Mar 6 13:33:45 2012 us=282897 show_engines = DISABLED
Tue Mar 6 13:33:45 2012 us=282924 genkey = DISABLED
Tue Mar 6 13:33:45 2012 us=283012 key_pass_file = '[UNDEF]'
Tue Mar 6 13:33:45 2012 us=283041 show_tls_ciphers = DISABLED
Tue Mar 6 13:33:45 2012 us=283069 Connection profiles [default]:
Tue Mar 6 13:33:45 2012 us=283098 proto = udp
Tue Mar 6 13:33:45 2012 us=283125 local = '[UNDEF]'
Tue Mar 6 13:33:45 2012 us=283150 local_port = 1194
Tue Mar 6 13:33:45 2012 us=283176 remote = '[UNDEF]'
Tue Mar 6 13:33:45 2012 us=283201 remote_port = 1194
Tue Mar 6 13:33:45 2012 us=283226 remote_float = DISABLED
Tue Mar 6 13:33:45 2012 us=283293 bind_defined = DISABLED
Tue Mar 6 13:33:45 2012 us=283318 bind_local = ENABLED
Tue Mar 6 13:33:45 2012 us=283397 NOTE: --mute triggered...
Tue Mar 6 13:33:45 2012 us=283429 194 variation(s) on previous 20 message(s) suppressed by --mute
Tue Mar 6 13:33:45 2012 us=283461 OpenVPN 2.2.2 amd64-portbld-freebsd9.0 [SSL] [LZO2] [eurephia] built on Mar 6 2012
openvpn: writing to routing socket: No such process
Tue Mar 6 13:33:45 2012 us=283727 NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
Tue Mar 6 13:33:45 2012 us=287101 Diffie-Hellman initialized with 1024 bit key
Tue Mar 6 13:33:45 2012 us=287865 TLS-Auth MTU parms [ L:1542 D:138 EF:38 EB:0 ET:0 EL:0 ]
Tue Mar 6 13:33:45 2012 us=287916 Socket Buffers: R=[42080->65536] S=[9216->65536]
openvpn: writing to routing socket: No such process
openvpn: writing to routing socket: No such process
Tue Mar 6 13:33:45 2012 us=288149 ROUTE: default_gateway=UNDEF
Tue Mar 6 13:33:45 2012 us=288222 TUN/TAP device /dev/tun1 opened
openvpn: writing to routing socket: No such process
Tue Mar 6 13:33:45 2012 us=288346 /sbin/route add -net 10.8.0.0 10.8.0.2 255.255.255.0
route: writing to routing socket: Operation not permitted
Tue Mar 6 13:33:45 2012 us=289457 ERROR: FreeBSD route add command failed: external program exited with error status: 1
Tue Mar 6 13:33:45 2012 us=289550 Data Channel MTU parms [ L:1542 D:1450 EF:42 EB:135 ET:0 EL:0 AF:3/1 ]
Tue Mar 6 13:33:45 2012 us=289954 UDPv4 link local (bound): [undef]:1194
Tue Mar 6 13:33:45 2012 us=289998 UDPv4 link remote: [undef]
Tue Mar 6 13:33:45 2012 us=290028 MULTI: multi_init called, r=256 v=256
Tue Mar 6 13:33:45 2012 us=290128 IFCONFIG POOL: base=10.8.0.4 size=62
Tue Mar 6 13:33:45 2012 us=290166 IFCONFIG POOL LIST
Tue Mar 6 13:33:45 2012 us=290247 Initialization Sequence Completed


The client side gives me the following:

Tue Mar 06 14:39:18 2012 us=421000 OpenVPN 2.2.1 Win32-MSVC++ [SSL] [LZO2] built on Jul 1 2011
Tue Mar 06 14:39:18 2012 us=421000 NOTE: OpenVPN 2.1 requires '--script-security 2' or higher to call user-defined scripts or executables
Tue Mar 06 14:39:18 2012 us=750000 LZO compression initialized
Tue Mar 06 14:39:18 2012 us=750000 Control Channel MTU parms [ L:1542 D:138 EF:38 EB:0 ET:0 EL:0 ]
Tue Mar 06 14:39:18 2012 us=750000 Socket Buffers: R=[8192->8192] S=[8192->8192]
Tue Mar 06 14:39:18 2012 us=750000 Data Channel MTU parms [ L:1542 D:1450 EF:42 EB:135 ET:0 EL:0 AF:3/1 ]
Tue Mar 06 14:39:18 2012 us=765000 Local Options String: 'V4,dev-type tun,link-mtu 1542,tun-mtu 1500,proto UDPv4,comp-lzo,cipher BF-CBC,auth SHA1,keysize 128,key-method 2,tls-client'
Tue Mar 06 14:39:18 2012 us=765000 Expected Remote Options String: 'V4,dev-type tun,link-mtu 1542,tun-mtu 1500,proto UDPv4,comp-lzo,cipher BF-CBC,auth SHA1,keysize 128,key-method 2,tls-server'
Tue Mar 06 14:39:18 2012 us=765000 Local Options hash (VER=V4): '41690919'
Tue Mar 06 14:39:18 2012 us=765000 Expected Remote Options hash (VER=V4): '530fdded'
Tue Mar 06 14:39:18 2012 us=765000 UDPv4 link local: [undef]
Tue Mar 06 14:39:18 2012 us=765000 UDPv4 link remote: 192.168.0.5:1194
Tue Mar 06 14:39:25 2012 write UDPv4: Interrupted system call (WSAEINTR) (code=10004)
Tue Mar 06 14:39:33 2012 us=296000 write UDPv4: Interrupted system call (WSAEINTR) (code=10004)


Is the problem with not being able to add routes?

LJackson
March 11th, 2012, 07:08
In general, these instructions do appear to work with a TAP device, and without using OpenVPN's client-config-dir as discussed on http://forums.freebsd.org/showthread.php?t=24063&highlight=jail+openvpn. First, placing if_tap_load="YES" in /boot/loader.conf will prevent situations where all the interfaces appeared to be configured correctly, but the OpenVPN client stalls with errors like "Connection Reset by Peer".

Ensure OpenVPN can use the TAP device (the last two lines are key):

# sysctl -a | grep link.tap
net.link.tap.debug: 0
net.link.tap.devfs_cloning: 1
net.link.tap.up_on_open: 1
net.link.tap.user_open: 1

Next, setup the bridge and configure the interfaces. The following applies to /etc/rc.conf. My host has a re0 interface (10.0.0.70), is running Samba, and has OpenVPN in a jail addressed as 10.0.0.74.

cloned_interfaces="tap0 bridge0"
ifconfig_bridge0="addm re0 addm tap0 up"
ifconfig_re0="up" # All interfaces must be up
ifconfig_tap0="up"

ipv4_addrs_bridge0="10.0.0.70/24" # Host IP (Samba), 74 is on re0

## Note: ifconfig_bridge0 should work in place of ipv4_addrs_bridge0

ifconfig_re0="10.0.0.74/24" # OpenVPN's IP


I found placing OpenVPN's IP on the bridge as an alias (ifconfig_bridge0_alias0="inet 10.0.0.74 netmask 255.255.255.255") yielded mixed results: using ssh to contact the host would still work, but Samba wouldn't. Placing both on re0 also appeared to work, but goes against convention. (If the host is to have an IP address it should go on the host. See http://www.freebsd.org/doc/handbook/network-bridging.html.) Making the TAP device sticky is interesting. (See the aforementioned handbook.)

The TAP device is set using either

ifconfig_tap0="10.8.0.50 netmask 255.255.255.0"

or

jail_<OpenVPN>_ip_multi0="tap0|10.8.0.50/24"

In my case, both appeared to work, but the latter is preferred for consistency.

Depending on how you are using your host and the bridge the gateway_enable="YES" in /etc/rc.conf may not be required.

As reported for the TUN device http://forums.freebsd.org/showthread.php?t=27934&highlight=openvpn+jail, I did find if OpenVPN is stopped the IP address assigned to the TAP device is removed. I wouldn't have thought that is possible, maybe something to do with the sysctl values?

My OpenVPN server.conf file looks like:

server-bridge 10.8.0.50 255.255.255.0 10.8.0.51 10.8.0.99

proto udp
dev tap

ca /usr/local/etc/openvpn/keys/ca.crt
cert /usr/local/etc/openvpn/keys/server.crt
key /usr/local/etc/openvpn/keys/server.key
dh /usr/local/etc/openvpn/keys/dh1024.pem
tls-auth /usr/local/etc/openvpn/keys/ta.key 0

client-to-client

ifconfig-noexec

push "dhcp-option DNS 10.0.0.1"
push "dhcp-option WINS 10.0.0.70"
push "dhcp-option NBT 8"

mssfix 1450

ping 10
ping-restart 120
push "ping 10"
push "ping-restart 60"
push "route 10.0.0.0 255.255.255.0" # Advertise Server's LAN to VPN clients

comp-lzo
user nobody
group nobody

status /var/log/openvpn/openvpn-status.log
log-append /var/log/openvpn/openvpn.log
verb 3


and the client file for a Microsoft XP system and a MacBook Pro OS X Lion looks like (The host is also acting as a Time Machine Server.)

client
dev tap
proto udp
remote <yours.com> 1194

tls-client

nobind

ca <your ca.crt>
cert <your client.crt>
key <your client.key>
tls-auth <your ta.key> 1

tun-mtu 1500
tun-mtu-extra 32
mssfix 1450

pull

comp-lzo
verb 3