Skip to contentSkip to conversation

package/quagga: Fix directories and permissions

PATCH Superseded Nathaniel Roach 2 participants 5 messages May 11, 2016 – May 12, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/quagga: Fix directories and permissions

Quagga runs as the "quagga" user, but it also needs to modify files in /etc and /var - config files, pid files and vty sockets for vtysh.

Tell the configure script the right folders to use, create the user, fix the permissions, and then let systemd know (if needed).

---
 package/quagga/quagga.mk            | 22 +++++++++++++++++++++-
 package/quagga/quagga_tmpfiles.conf |  2 ++
 2 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 package/quagga/quagga_tmpfiles.conf
package/quagga/quagga.mk +21 -1
index 6b98367..3592aee 100644
@@ -10,7 +10,11 @@ QUAGGA_SITE = http://download.savannah.gnu.org/releases/quagga
 QUAGGA_DEPENDENCIES = host-gawk
 QUAGGA_LICENSE = GPLv2+
 QUAGGA_LICENSE_FILES = COPYING
-QUAGGA_CONF_OPTS = --program-transform-name=''
+QUAGGA_CONF_OPTS = \
+  --program-transform-name='' \
+  --sysconfdir=/etc/quagga \
+  --localstatedir=/var/run/quagga
+
 # 0002-configure-fix-static-linking-with-readline.patch
 QUAGGA_AUTORECONF = YES
 
@@ -33,6 +37,16 @@ QUAGGA_CONF_OPTS += $(if $(BR2_PACKAGE_QUAGGA_ISISD),--enable-isisd,--disable-is
 QUAGGA_CONF_OPTS += $(if $(BR2_PACKAGE_QUAGGA_BGP_ANNOUNCE),--enable-bgp-announce,--disable-bgp-announce)
 QUAGGA_CONF_OPTS += $(if $(BR2_PACKAGE_QUAGGA_TCP_ZERBRA),--enable-tcp-zebra,--disable-tcp-zebra)
 
+define QUAGGA_USERS
+	quagga -1 quagga -1 * - - - Quagga priv drop user
+endef
+
+define QUAGGA_PERMISSIONS
+	/etc/quagga r 600 quagga quagga - - - - -
+	/etc/quagga d 755 quagga quagga - - - - -
+	/var/run/quagga d 755 quagga quagga - - - - -
+endef
+
 ifeq ($(BR2_PACKAGE_QUAGGA_SNMP),y)
 QUAGGA_CONF_ENV += ac_cv_path_NETSNMP_CONFIG=$(STAGING_DIR)/usr/bin/net-snmp-config
 QUAGGA_CONF_OPTS += --enable-snmp=agentx
@@ -50,4 +64,10 @@ ifeq ($(BR2_arc),y)
 QUAGGA_CONF_OPTS += --disable-pie
 endif
 
+define QUAGGA_INSTALL_INIT_SYSTEMD
+	mkdir -p $(TARGET_DIR)/usr/lib/tmpfiles.d
+	$(INSTALL) -D -m 644 package/quagga/quagga_tmpfiles.conf \
+		$(TARGET_DIR)/usr/lib/tmpfiles.d/quagga.conf
+endef
+
 $(eval $(autotools-package))
package/quagga/quagga_tmpfiles.conf new file +2 -0
new file mode 100644
index 0000000..ad82cc6
@@ -0,0 +1,2 @@
+d /var/run/quagga/ 1755 quagga quagga -
+
Signature · 1 line
2.8.1
#1 lore raw

PATCH 1/1 package/quagga: Fix directories and permissions

Hello,

I'm adding in Cc: Baruch, since he has done most of the recent updates to the Quagga package. Baruch, could you review/test this patch, according to your knowledge of Quagga?

I'm also adding some comments below.

Quoted 2 lines

Quagga runs as the "quagga" user, but it also needs to modify files in /etc and /var - config files, pid files and vty sockets for vtysh.

Does it really need to write in /etc ? If that's the case, then it seems a bit wrong, and we have a bigger problem. What happens if /etc is read-only ?

package/quagga/quagga.mk QUAGGA_SITE = http://download.savannah.gnu.org/releases/quagga · line 16

Quoted 13 lines · Nathaniel Roach
package/quagga/quagga.mk +4 -1
index 6b98367..3592aee 100644
@@ -10,7 +10,11 @@ QUAGGA_SITE = http://download.savannah.gnu.org/releases/quagga
 QUAGGA_DEPENDENCIES = host-gawk
 QUAGGA_LICENSE = GPLv2+
 QUAGGA_LICENSE_FILES = COPYING
-QUAGGA_CONF_OPTS = --program-transform-name=''
+QUAGGA_CONF_OPTS = \
+  --program-transform-name='' \
+  --sysconfdir=/etc/quagga \
+  --localstatedir=/var/run/quagga

Indentation should be one tab for those lines. But why isn't sysconfdir=/etc appropriate? Is it because quagga writes to some files in /etc? If that's the case, as said above, I'm believe it's bad.

package/quagga/quagga.mk QUAGGA_CONF_OPTS += $(if $(BR2_PACKAGE_QUAGGA_ISISD),--enable-isisd,--disable-is · line 46

Quoted 3 lines
package/quagga/quagga.mk +3 -0
+define QUAGGA_PERMISSIONS
+	/etc/quagga r 600 quagga quagga - - - - -
+	/etc/quagga d 755 quagga quagga - - - - -

Hum, does this actually work?

package/quagga/quagga.mk ifeq ($(BR2_arc),y) · line 68

Quoted 12 lines
package/quagga/quagga.mk +5 -0
+	/var/run/quagga d 755 quagga quagga - - - - -
+endef
+
 ifeq ($(BR2_PACKAGE_QUAGGA_SNMP),y)
 QUAGGA_CONF_ENV += ac_cv_path_NETSNMP_CONFIG=$(STAGING_DIR)/usr/bin/net-snmp-config
 QUAGGA_CONF_OPTS += --enable-snmp=agentx
@@ -50,4 +64,10 @@ ifeq ($(BR2_arc),y)
 QUAGGA_CONF_OPTS += --disable-pie
 endif
 
+define QUAGGA_INSTALL_INIT_SYSTEMD
+	mkdir -p $(TARGET_DIR)/usr/lib/tmpfiles.d

This mkdir -p is useless, as $(INSTALL) -D creates all sub-directories needed to be able to copy to the destination path.

package/quagga/quagga_tmpfiles.conf line 2

Quoted 13 lines
package/quagga/quagga.mk +4 -0
+	$(INSTALL) -D -m 644 package/quagga/quagga_tmpfiles.conf \
+		$(TARGET_DIR)/usr/lib/tmpfiles.d/quagga.conf
+endef
+
 $(eval $(autotools-package))
package/quagga/quagga_tmpfiles.conf new file +2 -0
new file mode 100644
index 0000000..ad82cc6
@@ -0,0 +1,2 @@
+d /var/run/quagga/ 1755 quagga quagga -
+

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH 1/1 package/quagga: Fix directories and permissions

Hi Thomas,

Quoted 6 lines · Thomas Petazzoni

Hello,

I'm adding in Cc: Baruch, since he has done most of the recent updates to the Quagga package. Baruch, could you review/test this patch, according to your knowledge of Quagga?

Quoted 7 lines

I'm also adding some comments below.

Quoted 2 lines

Quagga runs as the "quagga" user, but it also needs to modify files in /etc and /var - config files, pid files and vty sockets for vtysh.

Does it really need to write in /etc ? If that's the case, then it seems a bit wrong, and we have a bigger problem. What happens if /etc is read-only ?

If you're using vtysh to configure Quagga, yes, it absolutely needs write permissions to the config folder, as it's more than likely you'd want to save your config. (Running commands in vtysh is very similar to Cisco routers, there's a "running-config" and a "startup-config" - commands are saved into running, but are not copied into startup by default)

The daemons themselves don't write to /etc unless you tell it to:

$sudo vtysh
...
charon# copy run start
Building Configuration...
Configuration saved to /etc/quagga/zebra.conf
Configuration saved to /etc/quagga/ospfd.conf
[OK]

It needs write permissions to the folder as it moves the old config and writes a new one, rather than just overwriting.

In the instance that /etc/ is RO, the user simply won't be able to save an updated configuration.

Quoted 20 lines · Nathaniel Roach
Quoted 6 lines
package/quagga/quagga.mk +0 -0
index 6b98367..3592aee 100644

package/quagga/quagga.mk QUAGGA_SITE = http://download.savannah.gnu.org/releases/quagga · line 16

Quoted 8 lines
package/quagga/quagga.mk +4 -1
@@ -10,7 +10,11 @@ QUAGGA_SITE = http://download.savannah.gnu.org/releases/quagga
  QUAGGA_DEPENDENCIES = host-gawk
  QUAGGA_LICENSE = GPLv2+
  QUAGGA_LICENSE_FILES = COPYING
-QUAGGA_CONF_OPTS = --program-transform-name=''
+QUAGGA_CONF_OPTS = \
+  --program-transform-name='' \
+  --sysconfdir=/etc/quagga \
+  --localstatedir=/var/run/quagga

Indentation should be one tab for those lines. But why isn't sysconfdir=/etc appropriate? Is it because quagga writes to some files in /etc? If that's the case, as said above, I'm believe it's bad.

Ah, editor settings strikes again.

Quoted 5 lines

package/quagga/quagga.mk QUAGGA_CONF_OPTS += $(if $(BR2_PACKAGE_QUAGGA_ISISD),--enable-isisd,--disable-is · line 46

Quoted 4 lines
package/quagga/quagga.mk +3 -0
+define QUAGGA_PERMISSIONS
+	/etc/quagga r 600 quagga quagga - - - - -
+	/etc/quagga d 755 quagga quagga - - - - -

Hum, does this actually work?

Yup, unfortunately wildcards don't, and I didn't feel that adding a line for each daemon was appropriate. (There's one for each daemon, and it's only installed if that daemon is selected, hence why I need to effectively do a wildcard chmod here)

Quoted 11 lines
Quoted 11 lines
package/quagga/quagga.mk +3 -0
+	/var/run/quagga d 755 quagga quagga - - - - -
+endef
+
  ifeq ($(BR2_PACKAGE_QUAGGA_SNMP),y)
  QUAGGA_CONF_ENV += ac_cv_path_NETSNMP_CONFIG=$(STAGING_DIR)/usr/bin/net-snmp-config
  QUAGGA_CONF_OPTS += --enable-snmp=agentx
@@ -50,4 +64,10 @@ ifeq ($(BR2_arc),y)
  QUAGGA_CONF_OPTS += --disable-pie
  endif
 
Quoted 4 lines

package/quagga/quagga.mk ifeq ($(BR2_arc),y) · line 68

Quoted 2 lines
package/quagga/quagga.mk +2 -0
+define QUAGGA_INSTALL_INIT_SYSTEMD
+	mkdir -p $(TARGET_DIR)/usr/lib/tmpfiles.d

This mkdir -p is useless, as $(INSTALL) -D creates all sub-directories needed to be able to copy to the destination path.

Huh, thanks! I believe I copied this from somewhere else, but I'll take it out in the next revision.

Quoted 16 lines
Quoted 12 lines
package/quagga/quagga.mk +4 -0
+	$(INSTALL) -D -m 644 package/quagga/quagga_tmpfiles.conf \
+		$(TARGET_DIR)/usr/lib/tmpfiles.d/quagga.conf
+endef
+
  $(eval $(autotools-package))
package/quagga/quagga_tmpfiles.conf new file +0 -0
new file mode 100644
index 0000000..ad82cc6

package/quagga/quagga_tmpfiles.conf line 2

Quoted 2 lines
package/quagga/quagga_tmpfiles.conf new file +2 -0
@@ -0,0 +1,2 @@
+d /var/run/quagga/ 1755 quagga quagga -
+

Thanks!

Quoted 1 line

Thomas

Cheers, Nathaniel

#3 lore raw

PATCH 1/1 package/quagga: Fix directories and permissions

Hello,

Quoted 16 lines · Nathaniel Roach

If you're using vtysh to configure Quagga, yes, it absolutely needs write permissions to the config folder, as it's more than likely you'd want to save your config. (Running commands in vtysh is very similar to Cisco routers, there's a "running-config" and a "startup-config" - commands are saved into running, but are not copied into startup by default)

The daemons themselves don't write to /etc unless you tell it to:

$sudo vtysh
...
charon# copy run start
Building Configuration...
Configuration saved to /etc/quagga/zebra.conf
Configuration saved to /etc/quagga/ospfd.conf
[OK]

Quoted 5 lines

It needs write permissions to the folder as it moves the old config and writes a new one, rather than just overwriting.

In the instance that /etc/ is RO, the user simply won't be able to save an updated configuration.

Right, makes sense. Then, perhaps you want to add a comment on top of QUAGGA_CONF_OPTS to indicate why we override localstatedir and sysconfdir. Just something like:

# Override localstatedir and sysconfdir so that quagga has its own # directories, which is will access with its own user.

or something along those lines (I'm sure a better wording is possible).

Quoted 8 lines
Quoted 4 lines

package/quagga/quagga.mk QUAGGA_CONF_OPTS += $(if $(BR2_PACKAGE_QUAGGA_ISISD),--enable-isisd,--disable-is · line 46

Quoted 3 lines
package/quagga/quagga.mk +3 -0
+define QUAGGA_PERMISSIONS
+	/etc/quagga r 600 quagga quagga - - - - -
+	/etc/quagga d 755 quagga quagga - - - - -  

Hum, does this actually work?

Yup, unfortunately wildcards don't, and I didn't feel that adding a line for each daemon was appropriate. (There's one for each daemon, and it's only installed if that daemon is selected, hence why I need to effectively do a wildcard chmod here)

So you need the first line to make every file in /etc/quagga owned by quagga, 600, and then the second line to make the /etc/quagga directory owned by the quagga user and 755, so that quagga can create more files in this directory, right?

Quoted 6 lines
Quoted 4 lines

package/quagga/quagga.mk ifeq ($(BR2_arc),y) · line 68

Quoted 2 lines
package/quagga/quagga.mk +2 -0
+define QUAGGA_INSTALL_INIT_SYSTEMD
+	mkdir -p $(TARGET_DIR)/usr/lib/tmpfiles.d  

This mkdir -p is useless, as $(INSTALL) -D creates all sub-directories needed to be able to copy to the destination path.

Huh, thanks! I believe I copied this from somewhere else, but I'll take it out in the next revision.

If you've seen it somewhere, try to remember where so that we can fix this place as well :-)

So overall, looks good. Just fix the very minor nits that I mentioned, and it's good to go.

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#4 lore raw

PATCH 1/1 package/quagga: Fix directories and permissions

Quoted 38 lines · Thomas Petazzoni

Hello,

Quoted 16 lines · Nathaniel Roach

If you're using vtysh to configure Quagga, yes, it absolutely needs write permissions to the config folder, as it's more than likely you'd want to save your config. (Running commands in vtysh is very similar to Cisco routers, there's a "running-config" and a "startup-config" - commands are saved into running, but are not copied into startup by default)

The daemons themselves don't write to /etc unless you tell it to:

$sudo vtysh
...
charon# copy run start
Building Configuration...
Configuration saved to /etc/quagga/zebra.conf
Configuration saved to /etc/quagga/ospfd.conf
[OK]

Quoted 5 lines

It needs write permissions to the folder as it moves the old config and writes a new one, rather than just overwriting.

In the instance that /etc/ is RO, the user simply won't be able to save an updated configuration.

Right, makes sense. Then, perhaps you want to add a comment on top of QUAGGA_CONF_OPTS to indicate why we override localstatedir and sysconfdir. Just something like:

# Override localstatedir and sysconfdir so that quagga has its own # directories, which is will access with its own user.

or something along those lines (I'm sure a better wording is possible).

Quoted 4 lines
Quoted 4 lines

package/quagga/quagga.mk QUAGGA_CONF_OPTS += $(if $(BR2_PACKAGE_QUAGGA_ISISD),--enable-isisd,--disable-is · line 46

Quoted 3 lines
package/quagga/quagga.mk +3 -0
+define QUAGGA_PERMISSIONS
+	/etc/quagga r 600 quagga quagga - - - - -
+	/etc/quagga d 755 quagga quagga - - - - -

Hum, does this actually work?

Quoted 8 lines
Quoted 4 lines

Yup, unfortunately wildcards don't, and I didn't feel that adding a line for each daemon was appropriate. (There's one for each daemon, and it's only installed if that daemon is selected, hence why I need to effectively do a wildcard chmod here)

So you need the first line to make every file in /etc/quagga owned by quagga, 600, and then the second line to make the /etc/quagga directory owned by the quagga user and 755, so that quagga can create more files in this directory, right?

That's precisely it. I'll comment this too so it's clearer.

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines

package/quagga/quagga.mk ifeq ($(BR2_arc),y) · line 68

Quoted 3 lines
package/quagga/quagga.mk +2 -0
+define QUAGGA_INSTALL_INIT_SYSTEMD
+	mkdir -p $(TARGET_DIR)/usr/lib/tmpfiles.d

This mkdir -p is useless, as $(INSTALL) -D creates all sub-directories needed to be able to copy to the destination path.

Huh, thanks! I believe I copied this from somewhere else, but I'll take it out in the next revision.

If you've seen it somewhere, try to remember where so that we can fix this place as well :-)

Found it: package/audit/audit.mk:49 I'll send that through in another patch.

Quoted 7 lines

So overall, looks good. Just fix the very minor nits that I mentioned, and it's good to go.

Thanks!

Thomas

Cheers!