|
@@ -3,50 +3,97 @@
|
3
|
3
|
# ref: https://library.linode.com/networking/openvpn/debian-6-squeeze
|
4
|
4
|
|
5
|
5
|
- name: Install OpenVPN and dependencies from apt
|
6
|
|
- apt: pkg=$item state=installed
|
|
6
|
+ apt: pkg={{ item }} state=installed
|
7
|
7
|
with_items:
|
8
|
8
|
- openvpn
|
9
|
9
|
- udev
|
10
|
10
|
- dnsmasq
|
11
|
11
|
|
12
|
|
-- name: Copy setup scripts into place
|
13
|
|
- command: cp -R /usr/share/doc/openvpn/examples/easy-rsa/ /etc/openvpn
|
|
12
|
+- name: Generate RSA keys for the CA and Server
|
|
13
|
+ command: openssl genrsa -out {{ item }}.key {{ openvpn_key_size }}
|
|
14
|
+ chdir={{ openvpn_path }}
|
|
15
|
+ creates={{ item }}.key
|
|
16
|
+ with_items:
|
|
17
|
+ - ca
|
|
18
|
+ - server
|
14
|
19
|
|
15
|
|
-- name: Put easy-rsa parameter settings in place
|
16
|
|
- template: src=etc_openvpn_easy-rsa_2.0_vars.j2 dest=/etc/openvpn/easy-rsa/2.0/vars
|
|
20
|
+- name: Generate RSA keys for the clients
|
|
21
|
+ command: openssl genrsa -out {{ item }}.key {{ openvpn_key_size }}
|
|
22
|
+ chdir={{ openvpn_path }}
|
|
23
|
+ creates={{ item }}.key
|
|
24
|
+ with_items: openvpn_clients
|
17
|
25
|
|
18
|
|
-###### manually:
|
19
|
|
-# cd /etc/openvpn/easy-rsa/2.0/
|
20
|
|
-# . /etc/openvpn/easy-rsa/2.0/vars
|
21
|
|
-# . /etc/openvpn/easy-rsa/2.0/clean-all
|
22
|
|
-# . /etc/openvpn/easy-rsa/2.0/build-ca
|
23
|
|
-# . /etc/openvpn/easy-rsa/2.0/build-key-server server
|
24
|
|
-#
|
25
|
|
-# for each client:
|
26
|
|
-# . /etc/openvpn/easy-rsa/2.0/build-key $client_name
|
27
|
|
-#####
|
|
26
|
+- name: Set the proper permissions on all RSA keys
|
|
27
|
+ file: path={{ openvpn_path }}
|
|
28
|
+ recurse=yes
|
|
29
|
+ state=directory
|
|
30
|
+ owner=root
|
|
31
|
+ group=root
|
|
32
|
+ mode=600
|
28
|
33
|
|
29
|
|
-- name: Generate Diffie-Hellman parameters
|
30
|
|
- command: . /etc/openvpn/easy-rsa/2.0/build-dh creates=/etc/openvpn/easy-rsa/2.0/keys/dh1024.pem
|
|
34
|
+- name: Generate CA certificate
|
|
35
|
+ command: openssl req -nodes -batch -new -x509 -key {{ openvpn_ca }}.key -out {{ openvpn_ca }}.crt -subj "{{ openssl_request_subject }}/CN=ca-certificate"
|
|
36
|
+ creates={{ openvpn_ca }}.crt
|
31
|
37
|
|
32
|
|
-- name: Copy certificates and key files into place
|
33
|
|
- command: cp /etc/openvpn/easy-rsa/2.0/keys/$item /etc/openvpn creates=/etc/openvpn/$item
|
34
|
|
- with_items:
|
35
|
|
- - ca.crt
|
36
|
|
- - ca.key
|
37
|
|
- - dh1024.pem
|
38
|
|
- - server.crt
|
39
|
|
- - server.key
|
|
38
|
+- name: Generate the OpenSSL configuration that will be used for the Server certificate's req and ca commands
|
|
39
|
+ # Properly sets the attributes that are described here:
|
|
40
|
+ # openvpn.net/index.php/open-source/documentation/howto.html#mitm
|
|
41
|
+ #
|
|
42
|
+ # This is required in order for the 'ns-cert-type server' option to
|
|
43
|
+ # work, which is enabled by default in most standard client.conf
|
|
44
|
+ # files.
|
|
45
|
+ template: src=openssl-server-certificate.cnf.j2
|
|
46
|
+ dest={{ openvpn_path }}/openssl-server-certificate.cnf
|
|
47
|
+
|
|
48
|
+- name: Seed a blank database file that will be used when generating the Server's certificate
|
|
49
|
+ command: touch {{ openvpn_path }}/index.txt
|
|
50
|
+ creates={{ openvpn_path }}/index.txt
|
|
51
|
+
|
|
52
|
+- name: Seed a serial file that will be used when generating the Server's certificate
|
|
53
|
+ shell: echo 01 > {{ openvpn_path }}/serial
|
|
54
|
+ creates={{ openvpn_path }}/serial
|
|
55
|
+
|
|
56
|
+- name: Generate CSR for the Server
|
|
57
|
+ command: openssl req -batch -extensions server -new -key server.key -out server.csr -config {{ openvpn_path }}/openssl-server-certificate.cnf
|
|
58
|
+ chdir={{ openvpn_path }}
|
|
59
|
+ creates=server.csr
|
|
60
|
+
|
|
61
|
+- name: Generate certificate for the Server
|
|
62
|
+ command: openssl ca -batch -extensions server -in server.csr -out server.crt -config openssl-server-certificate.cnf
|
|
63
|
+ chdir={{ openvpn_path }}
|
|
64
|
+ creates=server.crt
|
|
65
|
+
|
|
66
|
+- name: Generate CSRs for the clients
|
|
67
|
+ command: openssl req -new -key {{ item }}.key -out {{ item }}.csr -subj "{{ openssl_request_subject }}/CN={{ item }}"
|
|
68
|
+ chdir={{ openvpn_path }}
|
|
69
|
+ creates={{ item }}.csr
|
|
70
|
+ with_items: openvpn_clients
|
|
71
|
+
|
|
72
|
+- name: Generate certificates for the clients
|
|
73
|
+ command: openssl x509 -CA {{ openvpn_ca }}.crt -CAkey {{ openvpn_ca }}.key -CAcreateserial -req -in {{ item }}.csr -out {{ item }}.crt
|
|
74
|
+ chdir={{ openvpn_path }}
|
|
75
|
+ creates={{ item }}.crt
|
|
76
|
+ with_items: openvpn_clients
|
|
77
|
+
|
|
78
|
+- name: Generate HMAC firewall key
|
|
79
|
+ command: openvpn --genkey --secret {{ openvpn_hmac_firewall }}
|
|
80
|
+ creates={{ openvpn_hmac_firewall }}
|
|
81
|
+
|
|
82
|
+- name: Generate Diffie–Hellman parameters (this will take a while)
|
|
83
|
+ command: openssl dhparam -out {{ openvpn_dhparam }} {{ openvpn_key_size }}
|
|
84
|
+ creates={{ openvpn_dhparam }}
|
40
|
85
|
|
41
|
86
|
- name: Copy rc.local with firewall and dnsmasq rules into place
|
42
|
87
|
copy: src=etc_rc.local dest=/etc/rc.local
|
43
|
88
|
|
44
|
89
|
- name: Enable IPv4 traffic forwarding
|
45
|
|
- lineinfile: dest=/etc/sysctl.conf regexp="^net.ipv4.ip_forward" line="net.ipv4.ip_forward=1"
|
46
|
|
-- command: echo 1 > /proc/sys/net/ipv4/ip_forward
|
|
90
|
+ lineinfile: dest=/etc/sysctl.conf
|
|
91
|
+ regexp="^#?net.ipv4.ip_forward"
|
|
92
|
+ line="net.ipv4.ip_forward=1"
|
|
93
|
+- shell: echo 1 > /proc/sys/net/ipv4/ip_forward
|
47
|
94
|
|
48
|
|
-- name: Allow OpenVPN through firewall
|
49
|
|
- command: $item
|
|
95
|
+- name: Allow OpenVPN through the firewall
|
|
96
|
+ command: "{{ item }}"
|
50
|
97
|
with_items:
|
51
|
98
|
- iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
|
52
|
99
|
- iptables -A FORWARD -s 10.8.0.0/24 -j ACCEPT
|
|
@@ -57,7 +104,29 @@
|
57
|
104
|
template: src=etc_openvpn_server.conf.j2 dest=/etc/openvpn/server.conf
|
58
|
105
|
notify: restart openvpn
|
59
|
106
|
|
|
107
|
+# OpenVPN must restart first so the 10.8.0.0 interface is available
|
|
108
|
+# to dnsmasq
|
|
109
|
+- meta: flush_handlers
|
|
110
|
+
|
60
|
111
|
- name: Copy dnsmasq configuration file into place
|
61
|
112
|
copy: src=etc_dnsmasq.conf dest=/etc/dnsmasq.conf
|
62
|
113
|
notify: restart dnsmasq
|
63
|
114
|
|
|
115
|
+- name: Retrieve the ca.crt and ta.key files that clients will need in order to connect to the OpenVPN server
|
|
116
|
+ fetch: src={{ openvpn_path }}/{{ item }}
|
|
117
|
+ dest=/tmp/sovereign-openvpn-files
|
|
118
|
+ with_items:
|
|
119
|
+ - ca.crt
|
|
120
|
+ - ta.key
|
|
121
|
+
|
|
122
|
+- name: Retrieve the certificates that clients will need in order to connect to the OpenVPN server
|
|
123
|
+ fetch: src={{ openvpn_path }}/{{ item }}.crt
|
|
124
|
+ dest=/tmp/sovereign-openvpn-files
|
|
125
|
+ with_items: openvpn_clients
|
|
126
|
+
|
|
127
|
+- name: Retrieve the keys that clients will need in order to connect to the OpenVPN server
|
|
128
|
+ fetch: src={{ openvpn_path }}/{{ item }}.key
|
|
129
|
+ dest=/tmp/sovereign-openvpn-files
|
|
130
|
+ with_items: openvpn_clients
|
|
131
|
+
|
|
132
|
+- pause: prompt="You are ready to set up your OpenVPN clients. The files that you need are in /tmp/sovereign-openvpn-files. Make sure LZO compression is enabled and that you provide the ta.key file for the TLS-Auth option with a direction of '1'. Press any key to continue..."
|