Skip to content

Commit 6841129

Browse files
authored
Merge pull request #16 from jonathanio/feature/openvpn-24-changes
OpenVPN 2.4 & DNSSEC Improvements
2 parents 60984ef + 19e17ec commit 6841129

File tree

4 files changed

+40
-36
lines changed

4 files changed

+40
-36
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ otherwise the configuration provided by this script will only work on domains
4242
that cannot be resolved by the currently configured DNS servers (i.e. they must
4343
fall back after trying the ones set by your LAN's DHCP server).
4444

45-
Finally, update your OpenVPN configuration file and set the `up` and `down-pre`
46-
options:
45+
Finally, update your OpenVPN configuration file and set the `up` and `down`
46+
options to point to the script, and `down-pre` to ensure that the script is run
47+
before the device is closed:
4748

4849
```
4950
script-security 2
5051
setenv PATH /usr/bin
5152
up /etc/openvpn/update-systemd-resolved
52-
down-pre /etc/openvpn/update-systemd-resolved
53+
down /etc/openvpn/update-systemd-resolved
54+
down-pre
5355
```
5456

5557
## Usage
@@ -63,7 +65,7 @@ OpenVPN, either through the server, or the client, configuration:
6365
| `DOMAIN` | `example.com` | The primary domain for this host. If set multiple times, the last provided is used. Will be the primary search domain for bare hostnames. All requests for this domain as well will be routed to the `DNS` servers provided on this link. |
6466
| `DOMAIN-SEARCH` | `example.com` | Secondary domains which will be used to search for bare hostnames (after any `DOMAIN`, if set) and in the order provided. All requests for this domain will be routed to the `DNS` servers provided on this link. |
6567
| `DOMAIN-ROUTE` | `example.com` | All requests for these domains will be routed to the `DNS` servers provided on this link. They will *not* be used to search for bare hostnames, only routed. |
66-
| `DNSSEC` | `yes`<br />`no`</br >`default` | Control of DNSSEC should be enabled (`yes`) or disabled (`no`) for any queries over this link only, or use the system default (`default`). |
68+
| `DNSSEC` | `yes`<br />`no`</br >`allow-downgrade`</br >`default` | Control of DNSSEC should be enabled (`yes`) or disabled (`no`), or `allow-downgrade` to switch off DNSSEC only if the server doesn't support it, for any queries over this link only, or use the system default (`default`). |
6769

6870
*Note*: There are no local or system options to be configured. All configuration
6971
for this script is handled though OpenVPN, including, for example, the name of

run-tests

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,11 @@ function busctl {
6666
;;
6767
SetLinkDNSSEC)
6868
shift 2
69-
if [[ "${TEST_BUSCTL_DNSSEC}" == "" ]]; then
70-
[[ "${ip_ifindex} ${TEST_BUSCTL_DNSSEC}" == "${@}" ]] || \
71-
_fail "SetLinkDNSSEC was called and should not be: '${@}'"
72-
else
73-
[[ "${ip_ifindex} ${TEST_BUSCTL_DNSSEC}" == "${@}" ]] && \
74-
_pass "SetLinkDNSSEC was called correctly" || \
75-
_fail "SetLinkDNSSEC was not given the correct arguments:\n" \
76-
" Expected: '${ip_ifindex} ${TEST_BUSCTL_DNSSEC}'\n" \
77-
" Received: '${@}'"
78-
fi
69+
[[ "${ip_ifindex} ${TEST_BUSCTL_DNSSEC}x" == "${@}x" ]] && \
70+
_pass "SetLinkDNSSEC was called correctly" || \
71+
_fail "SetLinkDNSSEC was not given the correct arguments:\n" \
72+
" Expected: '${ip_ifindex} ${TEST_BUSCTL_DNSSEC}'\n" \
73+
" Received: '${@}'"
7974
;;
8075
*)
8176
_fail "Unknown command called on busctl: ${1}"

tests/20_dnssec_only.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ dev="tun20"
44
TEST_BUSCTL_CALLED=1
55

66
declare -A test_options=(
7-
['default']='""'
8-
['Default']='""'
7+
['default']=''
8+
['Default']=''
99
['true']='yes'
1010
['True']='yes'
1111
['yes']='yes'

update-systemd-resolved

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818

1919
# This script will parse DHCP options set via OpenVPN (dhcp-option) to update
2020
# systemd-resolved directly via DBus, instead of updating /etc/resolv.conf. To
21-
# install, set as the 'up' and 'down-pre' script in your OpenVPN configuration file
22-
# or command-line argument. For example:
21+
# install, set as the 'up' and 'down' script in your OpenVPN configuration file
22+
# or via the command-line arguments, alongside setting the 'down-pre' option to
23+
# run the 'down' script before the device is closed. For example:
2324
# up /etc/openvpn/update-systemd-resolved
24-
# down-pre /etc/openvpn/update-systemd-resolved
25+
# down /etc/openvpn/update-systemd-resolved
26+
# down-pre
2527

2628
# Define what needs to be called via DBus
2729
DBUS_DEST="org.freedesktop.resolve1"
@@ -46,7 +48,7 @@ busctl_call() {
4648
# Preserve busctl's exit status
4749
busctl call "$DBUS_DEST" "$DBUS_NODE" "${DBUS_DEST}.Manager" "$@" || {
4850
local -i status=$?
49-
emerg "\`busctl' exited with status $status"
51+
emerg "'busctl' exited with status $status"
5052
return $status
5153
}
5254
}
@@ -76,7 +78,7 @@ up() {
7678
local if_index="$1"
7779
shift
7880

79-
info "Link \`$link' coming up"
81+
info "Link '$link' coming up"
8082

8183
# Preset values for processing -- will be altered in the various process_*
8284
# functions.
@@ -94,7 +96,7 @@ up() {
9496
if declare -f "$process_setting_function" &>/dev/null; then
9597
"$process_setting_function" "$setting_value" || return $?
9698
else
97-
warning "Not a recognized DHCP setting: \`${setting}'"
99+
warning "Not a recognized DHCP setting: '${setting}'"
98100
fi
99101
done < <(dhcp_settings)
100102

@@ -125,12 +127,12 @@ up() {
125127
if [[ -n "${dns_sec}" ]]; then
126128
if [[ "${dns_sec}" == "default" ]]; then
127129
# We need to provide an empty string to use the default settings
128-
busctl_params=("$if_index" '""')
130+
info "SetLinkDNSSEC($if_index '')"
131+
busctl_call SetLinkDNSSEC 'is' "$if_index" "" || return $?
129132
else
130-
busctl_params=("$if_index" "${dns_sec}")
133+
info "SetLinkDNSSEC($if_index ${dns_sec})"
134+
busctl_call SetLinkDNSSEC 'is' "$if_index" "${dns_sec}" || return $?
131135
fi
132-
info "SetLinkDNSSEC(${busctl_params[*]})"
133-
busctl_call SetLinkDNSSEC 'is' "${busctl_params[@]}" || return $?
134136
fi
135137
}
136138

@@ -140,8 +142,13 @@ down() {
140142
local if_index="$1"
141143
shift
142144

143-
info "Link \`$link' going down"
144-
busctl_call RevertLink i "$if_index"
145+
info "Link '$link' going down"
146+
if [[ "$(whoami 2>/dev/null)" != "root" ]]; then
147+
# Cleanly handle the priviledge dropped case by not calling RevertLink
148+
info "Priviledges dropped in the client: Cannot call RevertLink."
149+
else
150+
busctl_call RevertLink i "$if_index"
151+
fi
145152
}
146153

147154
process_dns() {
@@ -153,7 +160,7 @@ process_dns() {
153160
elif looks_like_ipv4 "$address"; then
154161
process_dns_ipv4 "$address" || return $?
155162
else
156-
err "Not a valid IPv6 or IPv4 address: \`$address'"
163+
err "Not a valid IPv6 or IPv4 address: '$address'"
157164
return 1
158165
fi
159166
}
@@ -194,17 +201,17 @@ parse_ipv6() {
194201
local raw_address="$1"
195202

196203
log_invalid_ipv6() {
197-
local message="\`$raw_address' is not a valid IPv6 address"
204+
local message="'$raw_address' is not a valid IPv6 address"
198205
emerg "${message}: $*"
199206
}
200207

201208
trap -- 'unset -f log_invalid_ipv6' RETURN
202209

203210
if [[ "$raw_address" == *::*::* ]]; then
204-
log_invalid_ipv6 "address cannot contain more than one \`::'"
211+
log_invalid_ipv6 "address cannot contain more than one '::'"
205212
return 1
206213
elif [[ "$raw_address" =~ :0+:: ]] || [[ "$raw_address" =~ ::0+: ]]; then
207-
log_invalid_ipv6 "address contains a 0-group adjacent to \`::' and is not maximally shortened"
214+
log_invalid_ipv6 "address contains a 0-group adjacent to '::' and is not maximally shortened"
208215
return 1
209216
fi
210217

@@ -269,7 +276,7 @@ parse_ipv6() {
269276

270277
if [[ "$raw_address" == *::* ]]; then
271278
if (( ${#tokenized_segments[*]} == length )); then
272-
log_invalid_ipv6 "single \`0' fields should not be compressed"
279+
log_invalid_ipv6 "single '0' fields should not be compressed"
273280
return 1
274281
else
275282
local -i largest_run_i=0 largest_run=0
@@ -366,7 +373,7 @@ process_dnssec() {
366373
allow-downgrade)
367374
setting="allow-downgrade" ;;
368375
*)
369-
local message="\`$option' is not a valid DNSSEC option"
376+
local message="'$option' is not a valid DNSSEC option"
370377
emerg "${message}"
371378
return 1 ;;
372379
esac
@@ -388,11 +395,11 @@ main() {
388395
usage 'No device name specified'
389396
return 1
390397
elif ! declare -f "${script_type}" &>/dev/null; then
391-
usage "Invalid script type: \`${script_type}'"
398+
usage "Invalid script type: '${script_type}'"
392399
return 1
393400
else
394401
if ! read -r link if_index _ < <(get_link_info "$dev"); then
395-
usage "Invalid device name: \`$dev'"
402+
usage "Invalid device name: '$dev'"
396403
return 1
397404
fi
398405

0 commit comments

Comments
 (0)