Browse Source

modified vpn role to allow routing to private net

Thomas Buck 3 years ago
parent
commit
10b859df14

+ 57
- 0
roles/vpn/README.md View File

1
+# OpenVPN
2
+
3
+This is the standard 'upstream' sovereign OpenVPN stuff.
4
+The files that you need are now in secret/sovereign-openvpn-files.
5
+Make sure LZO compression is enabled and that you provide the ta.key file for the TLS-Auth option with a direction of '1'.
6
+
7
+The one major change is the option of enabling 'openvpn_enable_sub_routing' in your config.
8
+See the defaults in here for the available settings.
9
+
10
+This then looks something like:
11
+
12
+       ----------
13
+      | VPS      |
14
+      | 10.8.0.1 |
15
+       ----------
16
+         |
17
+         | Internet
18
+         | VPN
19
+         |            -----------
20
+         |-----------| Phone     |
21
+         |           | 10.8.0.42 |
22
+         |            -----------
23
+         |
24
+       --|------------------------------------------
25
+      |  |                                     Home |
26
+      |  |                                          |
27
+      |  |      -------------       -------------   |
28
+      |  |     | Router      |     | Bridge      |  |
29
+      |   -----| 192.168.0.1 |-----| 192.168.0.2 |  |
30
+      |        |             |     | 10.8.0.2    |  |
31
+      |         -------------       -------------   |
32
+      |               |                             |
33
+      |               |                             |
34
+      |         -------------                       |
35
+      |        | Server      |                      |
36
+      |        | 192.168.0.3 |                      |
37
+      |         -------------                       |
38
+       ---------------------------------------------
39
+
40
+In this scenario, your devices 'on the go', like the Phone above, want to connect to devices in your home network, like the Server, via the VPN connection over our sovereign VPS.
41
+This can easily accomplished with these configs.
42
+For the devices in your home network to be able to reach the devices on the VPN network, you need to add a static route to the Router above, that routes all traffic for 10.8.0.0/24 via 192.168.0.2, the Bridge.
43
+
44
+On the Bridge, do something like this, after installing eg. Ubuntu Server on the machine:
45
+
46
+    ssh-copy-id -i ~/.ssh/id_ecdsa thomas@vpn-bridge
47
+    scp sovereign/secret/sovereign-openvpn-files/eddie.xythobuz.de/etc/openvpn/nas/xythobuz.de.ovpn bridge:~/client.ovpn
48
+    ssh bridge
49
+    sudo apt-get install openvpn
50
+    sudo cp client.ovpn /etc/openvpn/client_vpn.conf
51
+    
52
+    sudo vim /etc/sysctl.conf
53
+    # uncomment line net.ipv4.ip_forward=1
54
+    
55
+    sudo reboot
56
+
57
+This will then allow devices connected to the VPN to just reach the 192.168.0.X devices without any further configuration.

+ 6
- 2
roles/vpn/defaults/main.yml View File

1
 # Notes about security: https://blog.g3rt.nl/openvpn-security-tips.html
1
 # Notes about security: https://blog.g3rt.nl/openvpn-security-tips.html
2
 # Check privacy: http://witch.valdikss.org.ru/
2
 # Check privacy: http://witch.valdikss.org.ru/
3
 
3
 
4
-openvpn_ip_start: "10.8.0"
5
-
6
 openvpn_key_country:  "US"
4
 openvpn_key_country:  "US"
7
 openvpn_key_province: "California"
5
 openvpn_key_province: "California"
8
 openvpn_key_city: "Beverly Hills"
6
 openvpn_key_city: "Beverly Hills"
26
 openvpn_tls_version_min: "tls-version-min 1.2"
24
 openvpn_tls_version_min: "tls-version-min 1.2"
27
 openvpn_tls_cipher: "tls-cipher TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256:TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256:TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-256-CBC-SHA256"
25
 openvpn_tls_cipher: "tls-cipher TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256:TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256:TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-256-CBC-SHA256"
28
 openvpn_clients: []
26
 openvpn_clients: []
27
+openvpn_ip_start: "10.8.0" # VPN Net XX.XX.XX.ZZ, server is always XX.XX.XX.1. Enter XX.XX.XX here. using /24
28
+openvpn_enable_sub_routing: 0
29
+openvpn_sub_routing_client: "nas"
30
+openvpn_sub_routing_network: "192.168.0.0"
31
+openvpn_enable_custom_dns: 0
32
+openvpn_custom_dns: ""

+ 9
- 4
roles/vpn/tasks/openvpn.yml View File

146
   template: src=etc_openvpn_server.conf.j2 dest=/etc/openvpn/server.conf
146
   template: src=etc_openvpn_server.conf.j2 dest=/etc/openvpn/server.conf
147
   notify: restart openvpn
147
   notify: restart openvpn
148
 
148
 
149
+- name: Create client specific config directory
150
+  file: state=directory path=/etc/openvpn/ccd owner=root group=root
151
+  when: openvpn_enable_sub_routing == 1
152
+
153
+- name: Copy OpenVPN configuration file into place
154
+  template: src=etc_openvpn_ccd_{{ openvpn_sub_routing_client }}.j2 dest=/etc/openvpn/ccd/{{ openvpn_sub_routing_client }} owner=root group=root mode=0666
155
+  notify: restart openvpn
156
+  when: openvpn_enable_sub_routing == 1
157
+
149
 - name: Enable OpenVPN server systemd service unit
158
 - name: Enable OpenVPN server systemd service unit
150
   service: name=openvpn@server enabled=yes
159
   service: name=openvpn@server enabled=yes
151
 
160
 
172
   with_nested:
181
   with_nested:
173
     - "{{ openvpn_clients }}"
182
     - "{{ openvpn_clients }}"
174
     - ["client.crt", "client.key", "ca.crt", "ta.key", "{{ openvpn_server }}.ovpn"]
183
     - ["client.crt", "client.key", "ca.crt", "ta.key", "{{ openvpn_server }}.ovpn"]
175
-
176
-- name: Pause 5s seconds for OpenVPN ready
177
-  pause: seconds=5
178
-         prompt="You are ready to set up your OpenVPN clients. The files that you need are in {{ secret }}/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..."

+ 2
- 0
roles/vpn/templates/etc_openvpn_ccd_nas.j2 View File

1
+iroute {{ openvpn_sub_routing_network }} 255.255.255.0
2
+ifconfig-push {{ openvpn_ip_start }}.2 255.255.255.0

+ 31
- 2
roles/vpn/templates/etc_openvpn_server.conf.j2 View File

96
 # Each client will be able to reach the server
96
 # Each client will be able to reach the server
97
 # on 10.8.0.1. Comment this line out if you are
97
 # on 10.8.0.1. Comment this line out if you are
98
 # ethernet bridging. See the man page for more info.
98
 # ethernet bridging. See the man page for more info.
99
+
100
+{% if openvpn_enable_sub_routing == 1 %}
101
+
102
+mode server
103
+tls-server
104
+topology "subnet"
105
+push "topology subnet"
106
+
107
+ifconfig {{ openvpn_ip_start }}.1 255.255.255.0
108
+push "route-gateway {{ openvpn_ip_start }}.1"
109
+ifconfig-pool {{ openvpn_ip_start }}.50 {{ openvpn_ip_start }}.250 255.255.255.0
110
+
111
+client-config-dir /etc/openvpn/ccd
112
+route {{ openvpn_sub_routing_network }} 255.255.255.0
113
+
114
+{% else %}
115
+
99
 server {{ openvpn_ip_start }}.0 255.255.255.0
116
 server {{ openvpn_ip_start }}.0 255.255.255.0
100
 
117
 
118
+{% endif %}
119
+
101
 # Maintain a record of client <-> virtual IP address
120
 # Maintain a record of client <-> virtual IP address
102
 # associations in this file.  If OpenVPN goes down or
121
 # associations in this file.  If OpenVPN goes down or
103
 # is restarted, reconnecting clients can be assigned
122
 # is restarted, reconnecting clients can be assigned
188
 # or bridge the TUN/TAP interface to the internet
207
 # or bridge the TUN/TAP interface to the internet
189
 # in order for this to work properly).
208
 # in order for this to work properly).
190
 push "redirect-gateway def1"
209
 push "redirect-gateway def1"
210
+
211
+
212
+{% if openvpn_enable_custom_dns == 1 %}
213
+
214
+push "dhcp-option DNS {{ openvpn_custom_dns }}"
215
+
216
+{% else %}
217
+
191
 push "dhcp-option DNS {{ openvpn_ip_start }}.1"
218
 push "dhcp-option DNS {{ openvpn_ip_start }}.1"
192
 
219
 
220
+{% endif %}
221
+
193
 # Certain Windows-specific network settings
222
 # Certain Windows-specific network settings
194
 # can be pushed to clients, such as DNS
223
 # can be pushed to clients, such as DNS
195
 # or WINS server addresses.  CAVEAT:
224
 # or WINS server addresses.  CAVEAT:
265
 #
294
 #
266
 # You can uncomment this out on
295
 # You can uncomment this out on
267
 # non-Windows systems.
296
 # non-Windows systems.
268
-user nobody
269
-group nogroup
297
+#user nobody
298
+#group nogroup
270
 
299
 
271
 # The persist options will try to avoid
300
 # The persist options will try to avoid
272
 # accessing certain resources on restart
301
 # accessing certain resources on restart

+ 3
- 2
site.yml View File

14
     - mailserver
14
     - mailserver
15
     - webmail
15
     - webmail
16
     - gitea
16
     - gitea
17
-  #  - vpn
18
-    - monitoring
17
+    - vpn
18
+    - backup
19
+    - monitoring # Monitoring role should be last. See roles/monitoring/README.md
19
 
20
 
20
   # These are all roles in one
21
   # These are all roles in one
21
   #roles:
22
   #roles:

Loading…
Cancel
Save