Skip to content

Commit a878f46

Browse files
wireguard: derive allowed ips from given id
Instead of having to manually write down entire ip addresses, just use an id to identify a peer.
1 parent fc231fe commit a878f46

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

locations/scharni.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,11 @@ wireguard_access:
122122
peers:
123123
- description: "Test"
124124
public_key: "5dkLlAtOqcoT7ocNYnLvyJ5pIippsxBXgFJvtVoI0yI=" # gitleaks:allow
125-
allowed_ips:
126-
- "10.248.105.130/32"
127-
- "2001:bf7:830:842a::2/128"
125+
id: 2
128126
persistent_keepalive: 25
129127
- description: "Friend"
130128
public_key: "iBUwLV7EU5odRoiK1GxQGNP1QruBbPp8Lk50yJ/iMno=" # gitleaks:allow
131-
allowed_ips:
132-
- "10.248.105.131/32"
133-
- "2001:bf7:830:842a::3/128"
129+
id: 3
134130
persistent_keepalive: 25
135131

136132
location_scharni__channel_assignments_11a_standard__to_merge:

roles/cfg_openwrt/templates/common/config/network.j2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,16 @@ config wireguard_wg_access
137137
{% if 'preshared_key' in peer %}
138138
option preshared_key '{{ peer['preshared_key'] }}'
139139
{% endif %}
140+
{% if 'id' in peer %}
141+
list allowed_ips '{{ wg_ipv6_subnet | ansible.utils.ipaddr(peer['id']) | ansible.utils.ipaddr('address') }}/128'
142+
{% if wg_has_ipv4 %}
143+
list allowed_ips '{{ wireguard_access['prefix'] | ansible.utils.ipaddr(peer['id']) | ansible.utils.ipaddr('address') }}/32'
144+
{% endif %}
145+
{% else %}
140146
{% for allowed_ip in peer['allowed_ips'] %}
141147
list allowed_ips '{{ allowed_ip }}'
142148
{% endfor %}
149+
{% endif %}
143150
{% if 'persistent_keepalive' in peer %}
144151
option persistent_keepalive '{{ peer['persistent_keepalive'] }}'
145152
{% endif %}

0 commit comments

Comments
 (0)