Setup Cloud Pipe VPN in OpenStack
This article mainly re-uses the OpenStack official documentation. Since the latter has errors in it, I fixed them. It’s fully functionnal under Ubuntu 12.04 distro.
I. Cloud Pipe VPN image template
First run a new empty instance. If you use the Ubuntu Cloud repo image some extra packages are needed. From now we will work inside our fresh Ubuntu instance.
$ sudo apt-get update && sudo apt-get upgade |
Create the openvpn configuration file called server.conf.template
in /etc/openvpn/
, with the following content:
port 1194
proto udp
dev tap0
up "/etc/openvpn/up.sh br0"
down "/etc/openvpn/down.sh br0"
script-security 3 system
persist-key
persist-tun
ca ca.crt
cert server.crt
key server.key # This file should be kept secret
dh dh1024.pem
ifconfig-pool-persist ipp.txt
server-bridge VPN_IP DHCP_SUBNET DHCP_LOWER DHCP_UPPER
client-to-client
keepalive 10 120
comp-lzo
max-clients 1
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3
mute 20
Create the script which bring up the bridge network interface, call it up.sh
:
|
Create the script which bring down the bridge network interface, call it down.sh
:
|
Don’t forget to make executable!
$ sudo chmod +x /etc/openvpn/{up.sh,down.sh} |
Modify your network parameters in /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet manual
up ifconfig $IFACE 0.0.0.0 up
down ifconfig $IFACE down
auto br0
iface br0 inet dhcp
bridge_ports eth0
Eventually edit your /etc/rc.local
like so:
#!/bin/sh -e |
For those of you who are curious here is the content of the autorun.sh
script:
|
Now your instance is ready to be snapshoted and stored in Glance. The following commands will select the id of our Ubuntu template and create a new image based on it.
$ nova list |
Update your image in Glance and make it public (accessible by all tenants):
$ glance update 0bfc8fd3-1590-463b-b178-bce30be5ef7b is_public=true |
II. CloudPipe setup
II.1 Configure OpenStack to use the template
Add some options to your nova.conf
like the id of you image, this will tell nova to call the vpn profile when our vpn-image is called:
## cloud-pipe vpn client ##
--vpn_image_id=0bfc8fd3-1590-463b-b178-bce30be5ef7b
--use_project_ca=true
--cnt_vpn_clients=5
Restart all your nova services.
II.2. Create the VPN
You are ready to run your cloud-pipe instance from any tenant. The command line tool is pretty unclear:
$ nova help cloudpipe-create |
The CLI suggests to use the Name of the project but that won’t work, the correct syntax is to use the id of the tenant:
$ keystone tenant-list |
Use this command to verify:
$ nova cloudpipe-list |
II.3. Under the hood
II.3.1. Security rules
This will run a new instance called <project-id>-vpn
. In VLAN networking mode, the second IP in each private network is reserved for the cloudpipe instance. Nova network will automatically create a new security group called <project id>-vpn
, assigned this group to the vpn instance and eventually will allow those rules:
ALLOW 1194:1194 from 0.0.0.0/0
ALLOW -1:-1 from 0.0.0.0/0
II.3.2. Credentials
An SSH key has been generated here /var/lib/nova/keys
, you can use it to log into the VPN instance. Certificates are stored in /var/lib/nova/CA/projects/<tenant-id>
. Basically:
- Server CA file is located in
/var/lib/nova/CA/projects/<tenant-id>/cacert.pem
- New client cert are located in
/var/lib/nova/CA/projects/<tenant-id>/newcerts/
II.4. Generate client credentials
Default generated credentials are vpn server credential you must not use them, thus create client credentials. Don’t forget to install the nova-cert
package.
$ nova x509-create-cert |
Then fetch the server certificate:
$ nova x509-get-root-cert |
Client template, which can be find here /usr/lib/python2.7/dist-packages/nova/cloudpipe/client.ovpn.template
:
# NOVA user connection
# Edit the following lines to point to your cert files:
cert $certfile
key $keyfile
ca cacert.pem
client
dev tap
proto udp
remote $ip $port
resolv-retry infinite
nobind
# Downgrade privileges after initialization (non-Windows only)
user nobody
group nogroup
comp-lzo
# Set log file verbosity.
verb 2
keepalive 10 120
ping-timer-rem
persist-tun
persist-key
II.4. Troubleshooting
A periodic task will disassociate the fixed ip address for this instance, this task is identified in the log like:
Running periodic task VlanManager._disassociate_stale_fixed_ips from (pid=21578) periodic_tasks /usr/lib/python2.7/dist-packages/nova/manager.py:152
After this the nova cloudpipe-list
output should be empty.
However if you re-run the cloud-pipe instance too quickly you will get an error from nova-network:
ERROR nova.rpc.amqp Returning exception Fixed IP address 192.168.22.34 is already in use.
To fix this, you need to update some fields in the nova database:
mysql> USE nova; |
II.5. Bonus
See below all the nova.conf options related to the Cloud Pipe VPN:
vpn_ip = <COMPUTE_NODE_IP or PUBLIC_IP>
vpn_start = 1000
vpn_key_suffix = -vpn
vpn_client_template = /usr/lib/python2.7/dist-packages/nova/cloudpipe/client.ovpn.template
credential_vpn_file = nova-vpn.conf
vpn_image_id = IMAGE_ID
cnt_vpn_clients = 5
keys_path = /var/lib/nova/keys
ca_path = /var/lib/nova/CA
Some options can be managed by the nova-manage
command:
$ sudo nova-manage vpn change --ip=<ip> --project=<project-id> --port=<port-number> |
For an automatic installation I forked the Mirantis repo and made some minor changes. Now the scripts should be compatible with Ubuntu 12.04, I only modified the
cloudpipeconf.sh
script according to my tests, so I don’t guarantee that the full project will work for you. Many thanks to Mirantis for the original script. See my fork on Github and the automatic installation script.
Comments