Skip to content

Commit 31edb06

Browse files
committed
fix: Fixes to the routing, dynamic interface name, fixed disappearing public key
1 parent 07fd1a8 commit 31edb06

File tree

9 files changed

+55
-10
lines changed

9 files changed

+55
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Purpose of this setup is to expose private subnets behind `Gateway node` to the
77
- Access to private subnets behind gateway
88
- Automatic client configuration generation
99
- Optional support for TOR (allows to hide administrator identity of a hidden service)
10+
- Systemd support

tasks/client.single.yaml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## Retrieve gateway public key ###
2+
3+
- name: Retrieve gateway key
4+
shell: "/usr/local/bin/key-extractor /etc/tinc/{{ network_name }}/hosts/{{ gateway_name }}"
5+
register: gateway_key_stdout
6+
7+
- name: Set gateway key as fact
8+
set_fact:
9+
gateway_key: "{{ gateway_key_stdout.stdout }}"
10+
11+
### Prepare directories ###
12+
113
- name: Create client temporary directory path
214
set_fact:
315
client_temp_path: "{{ local_clients_configs_path }}/{{ client.name }}/etc/tinc/{{ network_name }}"
@@ -12,17 +24,22 @@
1224
- "{{ client_temp_path }}/"
1325
- "{{ client_temp_path }}/hosts"
1426

27+
### Create client configuration ###
28+
1529
- name: Create tinc.conf
1630
template:
1731
src: client/etc/tinc/my-network/tinc.conf
1832
dest: "{{ client_temp_path }}/tinc.conf"
1933
mode: "u+rw,g+r,o"
2034

21-
- name: Create tinc-up script
35+
- name: Create tinc scripts
2236
template:
23-
src: client/etc/tinc/my-network/tinc-up
24-
dest: "{{ client_temp_path }}/tinc-up"
37+
src: "client/etc/tinc/my-network/{{ item }}"
38+
dest: "{{ client_temp_path }}/{{ item }}"
2539
mode: "u+rwx,g+rx,o"
40+
with_items:
41+
- tinc-up
42+
- tinc-down
2643

2744
- name: Create a gateway host file
2845
template:
@@ -47,7 +64,13 @@
4764
set_fact:
4865
client_key: "{{ client_key_stdout.stdout }}"
4966

50-
# Copy key to the gateway node
67+
### Generate the client config ###
68+
- name: Create client (self) host file
69+
template:
70+
src: client/etc/tinc/my-network/hosts/client
71+
dest: "{{ client_temp_path }}/hosts/{{ client.name }}"
72+
73+
### Copy key to the gateway node ###
5174
- name: Create client host file on gateway node
5275
template:
5376
src: server/etc/tinc/my-network/hosts/client-template

tasks/clients.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
loop: "{{ clients }}"
33
loop_control:
44
loop_var: client
5-
include: client.single.yaml
5+
include_tasks: client.single.yaml

tasks/server.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@
1818
dest: "/etc/tinc/{{ network_name }}/tinc-up"
1919
mode: "u+rwx,g+rx,o"
2020

21+
- set_fact:
22+
gateway_key: ""
23+
24+
- name: Check if gateway host file already exists - to extract public key from it
25+
register: public_key_exists
26+
stat:
27+
path: "/etc/tinc/{{ network_name }}/hosts/{{ gateway_name }}"
28+
29+
- name: Extract existing public key to not delete it
30+
when: public_key_exists.stat.exists
31+
block:
32+
- name: Extract key
33+
shell: "/usr/local/bin/key-extractor /etc/tinc/{{ network_name }}/hosts/{{ gateway_name }}"
34+
register: gateway_key_stdout
35+
- set_fact:
36+
gateway_key: "{{ gateway_key_stdout.stdout }}"
37+
2138
- name: Create a gateway host file
2239
template:
2340
src: server/etc/tinc/my-network/hosts/gateway
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# VPN address
1+
# VPN address. Must be on both sides, without this line the nodes wont be able to ping each other
22
Subnet = {{ client.ip }}/32
33

4+
# My public key, should be propagated to other VPN peers, including gateway
45
{{ client_key }}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22
{% for subnet in subnets_to_expose %}
3-
ip -4 route del {{ subnet }} dev {{ dev_interface | default("tun0") }} || true
3+
ip -4 route del {{ subnet }} dev $INTERFACE || true
44
{% endfor %}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
2-
ifconfig $INTERFACE hw ether {{ client.hw_ether }}
2+
ifconfig $INTERFACE hw ether {{ client.hw_ether }} || true
33
ifconfig $INTERFACE {{ client.ip }} netmask {{ netmask | default("255.255.255.0") }} -arp
44

55
{% for subnet in subnets_to_expose %}
6-
ip -4 route add {{ subnet }} dev {{ dev_interface | default("tun0") }}
6+
ip -4 route add {{ subnet }} dev $INTERFACE
77
{% endfor %}

templates/server/etc/tinc/my-network/hosts/gateway

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ Subnet = {{ gateway_ip }}/32
55
{% for subnet in subnets_to_expose %}
66
Subnet = {{ subnet }}
77
{% endfor %}
8+
9+
# Public key of the gateway
10+
{{ gateway_key }}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
2-
ifconfig $INTERFACE hw ether {{ gateway_hw_ether }}
2+
ifconfig $INTERFACE hw ether {{ gateway_hw_ether }} || true
33
ifconfig $INTERFACE {{ gateway_ip }} netmask {{ gateway_mask }} -arp

0 commit comments

Comments
 (0)