Bläddra i källkod

Generate a config file for each client generated

 * Add an openvpn_server variable
 * Move ${openvpn_client}.{key,csr,crt} to
   ${openvpn_client}/client.{key,csr,crt}
 * Generate ${openvpn_client}/${openvpn_server}.ovpn config file
 * Copy over a self contained directory of file per client that can be
   imported by networkmanager in ubuntu or run directly with `sudo
   openvpn ${openvpn_server}.ovpn
Ben Ford 11 år sedan
förälder
incheckning
588582aa25
4 ändrade filer med 47 tillägg och 23 borttagningar
  1. 29
    23
      roles/vpn/tasks/openvpn.yml
  2. 16
    0
      roles/vpn/templates/client.cnf.j2
  3. 1
    0
      vars/defaults.yml
  4. 1
    0
      vars/user.yml

+ 29
- 23
roles/vpn/tasks/openvpn.yml Visa fil

17
     - ca
17
     - ca
18
     - server
18
     - server
19
 
19
 
20
+- name: Create directories for clients
21
+  file: path={{ openvpn_path}}/{{ item }} state=directory
22
+  with_items: openvpn_clients
23
+
20
 - name: Generate RSA keys for the clients
24
 - 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
25
+  command: openssl genrsa -out client.key {{ openvpn_key_size }}
26
+           chdir={{ openvpn_path }}/{{ item }}
27
+           creates=client.key
24
   with_items: openvpn_clients
28
   with_items: openvpn_clients
25
 
29
 
26
 - name: Set the proper permissions on all RSA keys
30
 - name: Set the proper permissions on all RSA keys
64
            creates=server.crt
68
            creates=server.crt
65
 
69
 
66
 - name: Generate CSRs for the clients
70
 - 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
71
+  command: openssl req -new -key client.key -out client.csr -subj "{{ openssl_request_subject }}/CN={{ item }}" 
72
+           chdir={{ openvpn_path }}/{{ item }}
73
+           creates=client.csr
70
   with_items: openvpn_clients
74
   with_items: openvpn_clients
71
 
75
 
72
 - name: Generate certificates for the clients
76
 - 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
77
+  command: openssl x509 -CA {{ openvpn_ca }}.crt -CAkey {{ openvpn_ca }}.key -CAcreateserial -req -in client.csr -out client.crt
78
+           chdir={{ openvpn_path }}/{{ item }}
79
+           creates=client.crt
80
+  with_items: openvpn_clients
81
+
82
+
83
+- name: Create the client configs
84
+  template: src=client.cnf.j2
85
+            dest={{ openvpn_path }}/{{ item }}/{{ openvpn_server }}.ovpn
76
   with_items: openvpn_clients
86
   with_items: openvpn_clients
77
 
87
 
78
 - name: Generate HMAC firewall key
88
 - name: Generate HMAC firewall key
112
   copy: src=etc_dnsmasq.conf dest=/etc/dnsmasq.conf
122
   copy: src=etc_dnsmasq.conf dest=/etc/dnsmasq.conf
113
   notify: restart dnsmasq
123
   notify: restart dnsmasq
114
 
124
 
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
125
+- name: Copy the ca.crt and ta.key files that clients will need in order to connect to the OpenVPN server
126
+  command: cp {{ openvpn_path }}/{{ item[1] }} {{ openvpn_path }}/{{ item[0] }} 
127
+  with_nested:
128
+    - openvpn_clients
129
+    - ["ca.crt", "ta.key"]
126
 
130
 
127
-- name: Retrieve the keys that clients will need in order to connect to the OpenVPN server
128
-  fetch: src={{ openvpn_path }}/{{ item }}.key
131
+- name: Retrieve the files that clients will need in order to connect to the OpenVPN server
132
+  fetch: src={{ openvpn_path }}/{{ item[0] }}/{{ item[1] }}
129
          dest=/tmp/sovereign-openvpn-files
133
          dest=/tmp/sovereign-openvpn-files
130
-  with_items: openvpn_clients
134
+  with_nested:
135
+    - openvpn_clients
136
+    - ["client.crt", "client.key", "client.config", "ca.crt", "ta.key"]
131
 
137
 
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..."
138
 - 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..."

+ 16
- 0
roles/vpn/templates/client.cnf.j2 Visa fil

1
+client
2
+dev tun
3
+proto udp
4
+remote {{ openvpn_server }} 1194
5
+resolv-retry infinite
6
+nobind
7
+persist-key
8
+persist-tun
9
+
10
+ca ca.crt
11
+cert client.crt
12
+key client.key
13
+ns-cert-type server
14
+tls-auth ta.key 1
15
+comp-lzo
16
+verb 3

+ 1
- 0
vars/defaults.yml Visa fil

78
   - laptop
78
   - laptop
79
   - phone
79
   - phone
80
   - tablet
80
   - tablet
81
+openvpn_server: acme.com
81
 
82
 
82
 # # webmail
83
 # # webmail
83
 # webmail_domain: TODO.com
84
 # webmail_domain: TODO.com

+ 1
- 0
vars/user.yml Visa fil

78
 #   - laptop
78
 #   - laptop
79
 #   - phone
79
 #   - phone
80
 #   - tablet
80
 #   - tablet
81
+# openvpn_server: acme.com
81
 
82
 
82
 # # webmail
83
 # # webmail
83
 # webmail_domain: TODO.com
84
 # webmail_domain: TODO.com

Laddar…
Avbryt
Spara