Skip to content

Commit a3b62f2

Browse files
authored
Merge pull request #4744 from sarthurdev/kea-vrf
kea: T7854: Use helper for Kea VRF systemd units
2 parents 5248f1c + cdf9fe4 commit a3b62f2

File tree

6 files changed

+32
-35
lines changed

6 files changed

+32
-35
lines changed

src/etc/sudoers.d/vyos

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ Cmnd_Alias DIAGNOSTICS = /bin/ip vrf exec * /bin/ping *, \
4747
/usr/libexec/vyos/op_mode/*
4848
Cmnd_Alias KEA_IP6_ROUTES = /sbin/ip -6 route replace *,\
4949
/sbin/ip -6 route del *
50-
Cmnd_Alias KEA_DHCP = /bin/ip vrf exec * /usr/sbin/kea-dhcp*,\
51-
/usr/bin/chown * /var/run/kea/*,\
52-
/usr/bin/chown * /run/kea/*
5350
%operator ALL=NOPASSWD: DATE, IPTABLES, ETHTOOL, IPFLUSH, HWINFO, \
5451
PPPOE_CMDS, PCAPTURE, /usr/sbin/wanpipemon, \
5552
DMIDECODE, DISK, CONNTRACK, IP6TABLES, \
@@ -65,4 +62,3 @@ Cmnd_Alias KEA_DHCP = /bin/ip vrf exec * /usr/sbin/kea-dhcp*,\
6562
%sudo ALL=NOPASSWD: /usr/bin/mokutil
6663

6764
_kea ALL=NOPASSWD: KEA_IP6_ROUTES
68-
_kea ALL=NOPASSWD:SETENV: KEA_DHCP

src/etc/systemd/system/[email protected]

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,10 @@ Wants=network-online.target
55
After=vyos-router.service
66

77
[Service]
8-
User=_kea
8+
User=root
99
AmbientCapabilities=CAP_NET_BIND_SERVICE
1010
Environment="KEA_LOCKFILE_DIR=/run/lock/kea"
11-
ConfigurationDirectory=kea
12-
RuntimeDirectory=kea lock/kea
13-
RuntimeDirectoryPreserve=yes
14-
LogsDirectory=kea
15-
LogsDirectoryMode=0750
16-
StateDirectory=kea
17-
ExecStart=sudo /bin/ip vrf exec %i /usr/sbin/kea-dhcp-ddns -c /var/run/kea/kea-%i-dhcp-ddns.conf
18-
ExecStartPost=/bin/sh -c 'sleep 10 && sudo /usr/bin/chown _kea:_kea /var/run/kea/kea-%i-dhcp-ddns* && sudo /usr/bin/chown _kea:_kea /run/kea/logger_lockfile'
11+
ExecStart=/usr/libexec/vyos/system/kea-vrf-helper %i /usr/sbin/kea-dhcp-ddns -c /var/run/kea/kea-%i-dhcp-ddns.conf
1912
Restart=on-failure
2013

2114
[Install]

src/etc/systemd/system/[email protected]

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,12 @@ Wants=network-online.target
55
After=vyos-router.service
66

77
[Service]
8-
User=_kea
8+
User=root
99
AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_RAW
1010
Environment="KEA_DHCP_DATA_DIR=/config/dhcp"
1111
Environment="KEA_HOOK_SCRIPTS_PATH=/usr/libexec/vyos/system"
1212
Environment="KEA_LOCKFILE_DIR=/run/lock/kea"
13-
ConfigurationDirectory=kea
14-
ConfigurationDirectoryMode=0750
15-
RuntimeDirectory=kea lock/kea
16-
RuntimeDirectoryPreserve=yes
17-
RuntimeDirectoryMode=0750
18-
LogsDirectory=kea
19-
LogsDirectoryMode=0750
20-
StateDirectory=kea
21-
ExecStart=sudo -E /bin/ip vrf exec %i /usr/sbin/kea-dhcp4 -c /var/run/kea/kea-%i-dhcp4.conf
22-
ExecStartPost=/bin/sh -c 'sleep 10 && sudo /usr/bin/chown _kea:_kea /var/run/kea/dhcp4-%i-ctrl* && sudo /usr/bin/chown _kea:_kea /var/run/kea/kea-%i-dhcp4* && sudo /usr/bin/chown _kea:_kea /run/kea/logger_lockfile'
13+
ExecStart=/usr/libexec/vyos/system/kea-vrf-helper %i /usr/sbin/kea-dhcp4 -c /var/run/kea/kea-%i-dhcp4.conf
2314
Restart=on-failure
2415

2516
[Install]

src/etc/systemd/system/[email protected]

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,12 @@ Wants=network-online.target
55
After=vyos-router.service
66

77
[Service]
8-
User=_kea
8+
User=root
99
AmbientCapabilities=CAP_NET_BIND_SERVICE
1010
Environment="KEA_DHCP_DATA_DIR=/config/dhcp"
1111
Environment="KEA_HOOK_SCRIPTS_PATH=/usr/libexec/vyos/system"
1212
Environment="KEA_LOCKFILE_DIR=/run/lock/kea"
13-
ConfigurationDirectory=kea
14-
ConfigurationDirectoryMode=0750
15-
RuntimeDirectory=kea lock/kea
16-
RuntimeDirectoryPreserve=yes
17-
RuntimeDirectoryMode=0750
18-
LogsDirectory=kea
19-
LogsDirectoryMode=0750
20-
StateDirectory=kea
21-
ExecStart=sudo -E /bin/ip vrf exec %i /usr/sbin/kea-dhcp6 -c /var/run/kea/kea-%i-dhcp6.conf
22-
ExecStartPost=/bin/sh -c 'sleep 10 && sudo /usr/bin/chown _kea:_kea /var/run/kea/dhcp6-%i-ctrl* && sudo /usr/bin/chown _kea:_kea /var/run/kea/kea-%i-dhcp6* && sudo /usr/bin/chown _kea:_kea /run/kea/logger_lockfile'
13+
ExecStart=/usr/libexec/vyos/system/kea-vrf-helper %i /usr/sbin/kea-dhcp6 -c /var/run/kea/kea-%i-dhcp6.conf
2314
Restart=on-failure
2415

2516
[Install]

src/init/vyos-router

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,18 @@ start ()
504504
nfct helper add tns inet6 tcp
505505
nft --file /usr/share/vyos/vyos-firewall-init.conf || log_failure_msg "could not initiate firewall rules"
506506

507+
# Create needed kea directories
508+
mkdir -p /var/run/kea /run/lock/kea
509+
chmod 750 /var/run/kea /run/lock/kea
510+
chown _kea:_kea /var/run/kea /run/lock/kea
511+
if [ -d /opt/vyatta/etc/config ]; then
512+
if [ ! -d /opt/vyatta/etc/config/dhcp ]; then
513+
mkdir /opt/vyatta/etc/config/dhcp
514+
chmod 750 /opt/vyatta/etc/config/dhcp
515+
chown _kea:vyattacfg /opt/vyatta/etc/config/dhcp
516+
fi
517+
fi
518+
507519
# Ensure rsyslog is the default syslog daemon
508520
SYSTEMD_SYSLOG="/etc/systemd/system/syslog.service"
509521
SYSTEMD_RSYSLOG="/lib/systemd/system/rsyslog.service"

src/system/kea-vrf-helper

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
VRF=$1
4+
shift
5+
6+
export KEA_DHCP_DATA_DIR=/config/dhcp
7+
export KEA_HOOK_SCRIPTS_PATH=/usr/libexec/vyos/system
8+
export KEA_LOCKFILE_DIR=/run/lock/kea
9+
10+
ip vrf exec $VRF \
11+
setpriv --reuid=_kea --regid=_kea --init-groups \
12+
--inh-caps +net_bind_service,+net_raw \
13+
--ambient-caps +net_bind_service,+net_raw \
14+
$@

0 commit comments

Comments
 (0)