package/netsnmp: add snmp user and systemd service file
PATCH 1/1 package/netsnmp: add snmp user and systemd service file
* Add a snmp user so snmpd doesn't run as root
* Add a snmp systemd file as only an sysv was previously included
--- package/netsnmp/S59snmpd | 2 +- package/netsnmp/netsnmp.mk | 12 ++++++++++++ package/netsnmp/snmpd.service | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 package/netsnmp/snmpd.service
package/netsnmp/S59snmpd +1 -1
@@ -17,7 +17,7 @@ export PATH=/sbin:/usr/sbin:/bin:/usr/bin # Defaults export MIBDIRS=/usr/share/snmp/mibs SNMPDRUN=yes -SNMPDOPTS='-Lsd -Lf /dev/null -p /var/run/snmpd.pid 127.0.0.1' +SNMPDOPTS='-Lsd -Lf /dev/null -p /var/run/snmpd.pid -u snmp -g snmp 127.0.0.1' TRAPDRUN=no TRAPDOPTS='-Lsd -p /var/run/snmptrapd.pid'
package/netsnmp/netsnmp.mk +12 -0
@@ -41,6 +41,14 @@ NETSNMP_INSTALL_TARGET_OPTS = DESTDIR=$(TARGET_DIR) LIB_LDCONFIG_CMD=true instal NETSNMP_MAKE = $(MAKE1) NETSNMP_CONFIG_SCRIPTS = net-snmp-config +define NETSNMP_USERS + snmp -1 snmp -1 * - - - snmpd user +endef + +ifeq ($(BR2_INIT_SYSTEMD),y) +NETSNMP_CONF_OPTS += --with-systemd +endif + ifeq ($(BR2_ENDIAN),"BIG") NETSNMP_CONF_OPTS += --with-endianness=big else
@@ -104,6 +112,10 @@ define NETSNMP_INSTALL_INIT_SYSV $(INSTALL) -D -m 0755 package/netsnmp/S59snmpd \ $(TARGET_DIR)/etc/init.d/S59snmpd endef +define NETSNMP_INSTALL_INIT_SYSTEMD + $(INSTALL) -D -m 0644 package/netsnmp/snmpd.service \ + $(TARGET_DIR)/usr/lib/systemd/system/snmpd.service +endef endif $(eval $(autotools-package))
package/netsnmp/snmpd.service new file +15 -0
@@ -0,0 +1,15 @@ +[Unit] +Description=SNMP Daemon +After=network.target +ConditionPathExists=/etc/snmp/snmpd.conf + +[Service] +Type=simple +Environment=MIBDIRS=/usr/share/snmp/mibs +Environment=SNMPDOPTS='-Lsd -Lf /dev/null -p /var/run/snmpd.pid -u snmp -g snmp 127.0.0.1' +EnvironmentFile=-/etc/default/snmpd +PassEnvironment=MIBDIRS +ExecStart=/usr/sbin/snmpd -f $SNMPDOPTS + +[Install] +WantedBy=multi-user.target
Signature · 6 lines
2.30.2 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
David, All,
On 2023-04-20 17:12 -0400, David Johnson via buildroot spake thusly:
Quoted 2 lines
* Add a snmp user so snmpd doesn't run as root
* Add a snmp systemd file as only an sysv was previously included
Those are two semantically different changes, and thus should be done in two patches, the first to indeed add a user/group, the second to add systemd support (and see below).
Quoted 2 lines
Signed-off-by David Johnson <[email protected]>---
[--SNIP--]
Quoted 5 lines
package/netsnmp/netsnmp.mk +0
-0
package/netsnmp/netsnmp.mk NETSNMP_INSTALL_TARGET_OPTS = DESTDIR=$(TARGET_DIR) LIB_LDCONFIG_CMD=true instal · line 49
Quoted 9 lines
package/netsnmp/netsnmp.mk +6
-0@@ -41,6 +41,14 @@ NETSNMP_INSTALL_TARGET_OPTS = DESTDIR=$(TARGET_DIR) LIB_LDCONFIG_CMD=true instal NETSNMP_MAKE = $(MAKE1) NETSNMP_CONFIG_SCRIPTS = net-snmp-config +define NETSNMP_USERS + snmp -1 snmp -1 * - - - snmpd user +endef + +ifeq ($(BR2_INIT_SYSTEMD),y) +NETSNMP_CONF_OPTS += --with-systemd
We want to have explicit disabling option too, so:
ifeq ($(BR2_INIT_SYSTEMD),y)
NETSNMP_CONF_OPTS += --with-systemd
else
NETSNMP_CONF_OPTS += --without-systemd
endif[--SNIP--]
Quoted 6 lines
package/netsnmp/snmpd.service new file +0
-0
package/netsnmp/snmpd.service line 9
Quoted 9 lines
package/netsnmp/snmpd.service new file +9
-0@@ -0,0 +1,15 @@ +[Unit] +Description=SNMP Daemon +After=network.target +ConditionPathExists=/etc/snmp/snmpd.conf + +[Service] +Type=simple +Environment=MIBDIRS=/usr/share/snmp/mibs +Environment=SNMPDOPTS='-Lsd -Lf /dev/null -p /var/run/snmpd.pid -u snmp -g snmp 127.0.0.1'
So, I am not a systemd expert, but I would have expected the snmp socket to be handled by systemd with a socket unit, and handed over to snmpd, while the user/group would also be managed by systemd, with the Service.User and Service.Group options, like I have seen it done for gpsd for example: https://gitlab.com/gpsd/gpsd/-/tree/master/systemd
If that's not possible, then your proposed unit seems OK too.
Ah, I now read README.systemd, and they advise against socket activation for snmpd, with some good rationale; just state so in the commit log. For snmptrap, socket activation is properly supported (but it seems we do not install it).
Also explain why we provide our own unit when there is already one provided by upstream.
Regards,
Yann E. MORIN.
Quoted 13 lines
package/netsnmp/snmpd.service new file +6
-0+EnvironmentFile=-/etc/default/snmpd +PassEnvironment=MIBDIRS +ExecStart=/usr/sbin/snmpd -f $SNMPDOPTS + +[Install] +WantedBy=multi-user.targetSignature · 6 lines
2.30.2 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------' _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot