heat_template_version: 2013-05-23 description: >- OpenVPN server with public IP parameters: key_name: type: string label: Keypair Name description: Name of a KeyPair to enable SSH access to the instance. constraints: - custom_constraint: nova.keypair instance_type: type: string label: Nova flavor description: Instance type for the OpenVPN server. constraints: - custom_constraint: nova.flavor image_id: type: string label: Image description: ID of the image to use for the OpenVPN server (Tested only with ubuntu 14.04 LTS). constraints: - custom_constraint: glance.image private_net_id: type: string label: Private Network description: Private network in which OpenVPN will be linked. constraints: - custom_constraint: neutron.network vpn_cidr: type: string default: 10.8.0.0/24 description: OpenVPN CIDR. It has to be unique and must not overlap the CIDR of your private_net_id, public_net_id, and neither of your clients connecting to the VPN. floating_ip: label: Public IP type: string description: Floating IP of the server. resources: #Create security groups for OpenVPN and ssh secgroup-ovpn: type: OS::Neutron::SecurityGroup properties: description: Enable traffic external traffic on UDP:1194 for openVpn trafic rules: [{protocol: tcp, port_range_max: 1194, port_range_min: 1194},] secgroup-ssh: type: OS::Neutron::SecurityGroup properties: description: Enable traffic external traffic on SSH. rules: [{protocol: tcp, port_range_max: 22, port_range_min: 22},] secgroup-internal: type: OS::Neutron::SecurityGroup properties: description: Enable all traffic between instances. rules: [{protocol: tcp, port_range_max: 65535, port_range_min: 1, remote_mode: remote_group_id},{protocol: icmp}] # Install OpenVPN openvpn_install: type: OS::Heat::SoftwareConfig properties: group: script config: | #!/bin/bash sudo apt -f -y install openvpn easy-rsa ipcalc curl openvpn_key_gen: type: OS::Heat::SoftwareConfig properties: outputs: - name: ovpn_crt group: script config: | #!/bin/bash sudo cp -r /usr/share/easy-rsa/ /etc/openvpn sudo mkdir /etc/openvpn/easy-rsa/keys sudo sed -i 's/export KEY_COUNTRY="US"/export KEY_COUNTRY="HU"/' /etc/openvpn/easy-rsa/vars sudo sed -i 's/export KEY_PROVINCE="Budapest"/export KEY_PROVINCE="Budapest"/' /etc/openvpn/easy-rsa/vars sudo sed -i 's/export KEY_CITY="Budapest"/export KEY_CITY="Budapest"/' /etc/openvpn/easy-rsa/vars sudo sed -i 's/export KEY_ORG="MTA"/export KEY_CITY="MTA"/' /etc/openvpn/easy-rsa/vars sudo sed -i 's/export KEY_EMAIL="me@myhost.mydomain"/export KEY_EMAIL="'$public_ip'"/' /etc/openvpn/easy-rsa/vars sudo sed -i 's/export KEY_OU="me@myhost.mydomain"/export KEY_OU="MTA"/' /etc/openvpn/easy-rsa/vars sudo sed -i 's/export KEY_NAME="EasyRSA"/export KEY_NAME="server"/' /etc/openvpn/easy-rsa/vars sudo openssl dhparam -out /etc/openvpn/dh2048.pem 2048 > /dev/null cd /etc/openvpn/easy-rsa source vars > /dev/null sudo -E ./clean-all > /dev/null sudo -E ./build-ca --batch > /dev/null sudo -E ./build-key-server --batch server > /dev/null sudo cp /etc/openvpn/easy-rsa/keys/{server.crt,server.key,ca.crt} /etc/openvpn sudo cat /etc/openvpn/ca.crt openvpn_server_conf: type: OS::Heat::SoftwareConfig properties: inputs: - name: vpncidr - name: public group: script config: | #!/bin/bash export private_ip_cidr=`ip addr | grep $(curl 169.254.169.254/latest/meta-data/local-ipv4) | xargs | cut -d" " -f2` export private_net_cidr=`ipcalc -nb $private_ip_cidr | grep ^Network | awk '{print $2}'` export private_net_ip=`ipcalc -nb $private_net_cidr | grep ^Address | awk '{print $2}'` export private_net_mask=`ipcalc -nb $private_net_cidr | grep ^Netmask | awk '{print $2}'` sudo cat > /etc/openvpn/up.sh < /etc/openvpn/server.conf <> /etc/sysctl.conf sudo sysctl -p > /dev/null cat < /etc/openvpn/keystone-auth.sh <