Skip to contentSkip to conversation

package/openssh: Depend on libaudit if available

PATCH New Norbert Lange 3 participants 22 messages Jun 5, 2020 – Jun 11, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 package/openssh: Depend on libaudit if available

---
 package/openssh/openssh.mk | 5 +++++
 1 file changed, 5 insertions(+)
package/openssh/openssh.mk +5 -0
index 515eec2c03..55b917e20a 100644
@@ -39,6 +39,11 @@ else
 OPENSSH_CONF_OPTS += --without-ssl-engine
 endif
 
+ifeq ($(BR2_PACKAGE_AUDIT),y)
+OPENSSH_DEPENDENCIES += audit
+OPENSSH_CONF_OPTS += --with-audit=linux
+endif
+
 ifeq ($(BR2_PACKAGE_LINUX_PAM),y)
 define OPENSSH_INSTALL_PAM_CONF
 	$(INSTALL) -D -m 644 $(@D)/contrib/sshd.pam.generic $(TARGET_DIR)/etc/pam.d/sshd
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/4 package/openssh: improve integration for systemd

the openssh daemon is not suited for systemd's simple service type. dependend services should only start when sshd is ready to accept connections.

A patch is added from debian to allow openssh
to communicate this state.

Restarts are prevented if the reason is a faulty
config file (errocode 255).

The "user confinement directory" is changed to '/run/sshd' which is automatically managed by systemd.

---
 package/openssh/00-systemd-readiness.patch | 84 ++++++++++++++++++++++
 package/openssh/openssh.mk                 | 14 +++-
 package/openssh/sshd-sysusers.conf         |  2 +-
 package/openssh/sshd.service               | 13 +++-
 4 files changed, 109 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/00-systemd-readiness.patch
package/openssh/00-systemd-readiness.patch new file +84 -0
new file mode 100644
index 0000000000..be3b6b0074
@@ -0,0 +1,84 @@
+From ab765b2bd55062a704f09da8f8c1c4ad1d6630a7 Mon Sep 17 00:00:00 2001
+From: Michael Biebl <[email protected]>
+Date: Mon, 21 Dec 2015 16:08:47 +0000
+Subject: Add systemd readiness notification support
+
+Bug-Debian: https://bugs.debian.org/778913
+Forwarded: no
+Last-Update: 2017-08-22
+
+Patch-Name: systemd-readiness.patch
+---
+ configure.ac | 24 ++++++++++++++++++++++++
+ sshd.c       |  9 +++++++++
+ 2 files changed, 33 insertions(+)
+
+diff --git a/configure.ac b/configure.ac
+index e894db9fc..c119d6fd1 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -4499,6 +4499,29 @@ AC_ARG_WITH([kerberos5],
+ AC_SUBST([GSSLIBS])
+ AC_SUBST([K5LIBS])
+
++# Check whether user wants systemd support
++SYSTEMD_MSG="no"
++AC_ARG_WITH(systemd,
++	[  --with-systemd          Enable systemd support],
++	[ if test "x$withval" != "xno" ; then
++		AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
++		if test "$PKGCONFIG" != "no"; then
++			AC_MSG_CHECKING([for libsystemd])
++			if $PKGCONFIG --exists libsystemd; then
++				SYSTEMD_CFLAGS=`$PKGCONFIG --cflags libsystemd`
++				SYSTEMD_LIBS=`$PKGCONFIG --libs libsystemd`
++				CPPFLAGS="$CPPFLAGS $SYSTEMD_CFLAGS"
++				SSHDLIBS="$SSHDLIBS $SYSTEMD_LIBS"
++				AC_MSG_RESULT([yes])
++				AC_DEFINE(HAVE_SYSTEMD, 1, [Define if you want systemd support.])
++				SYSTEMD_MSG="yes"
++			else
++				AC_MSG_RESULT([no])
++			fi
++		fi
++	fi ]
++)
++
+ # Looking for programs, paths and files
+
+ PRIVSEP_PATH=/var/empty
+@@ -5305,6 +5328,7 @@ echo "                   libldns support: $LDNS_MSG"
+ echo "  Solaris process contract support: $SPC_MSG"
+ echo "           Solaris project support: $SP_MSG"
+ echo "         Solaris privilege support: $SPP_MSG"
++echo "                   systemd support: $SYSTEMD_MSG"
+ echo "       IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
+ echo "           Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
+ echo "                  BSD Auth support: $BSD_AUTH_MSG"
+diff --git a/sshd.c b/sshd.c
+index 4e8ff0662..5e7679a33 100644
+--- a/sshd.c
++++ b/sshd.c
+@@ -85,6 +85,10 @@
+ #include <prot.h>
+ #endif
+
++#ifdef HAVE_SYSTEMD
++#include <systemd/sd-daemon.h>
++#endif
++
+ #include "xmalloc.h"
+ #include "ssh.h"
+ #include "ssh2.h"
+@@ -1951,6 +1955,11 @@ main(int ac, char **av)
+ 			}
+ 		}
+
++#ifdef HAVE_SYSTEMD
++		/* Signal systemd that we are ready to accept connections */
++		sd_notify(0, "READY=1");
++#endif
++
+ 		/* Accept a connection and return in a forked child */
+ 		server_accept_loop(&sock_in, &sock_out,
+ 		    &newsock, config_s);
package/openssh/openssh.mk +13 -1
index 55b917e20a..d425db1428 100644
@@ -12,6 +12,7 @@ OPENSSH_CONF_ENV = \
 	LD="$(TARGET_CC)" \
 	LDFLAGS="$(TARGET_CFLAGS)" \
 	LIBS=`$(PKG_CONFIG_HOST_BINARY) --libs openssl`
+OPENSSH_AUTORECONF = YES
 OPENSSH_CONF_OPTS = \
 	--sysconfdir=/etc/ssh \
 	--with-default-path=$(BR2_SYSTEM_DEFAULT_PATH) \
@@ -22,9 +23,20 @@ OPENSSH_CONF_OPTS = \
 	--disable-wtmpx \
 	--disable-strip
 
+ifeq ($(BR2_PACKAGE_SYSTEMD),y)
+OPENSSH_DEPENDENCIES = systemd
+
+OPENSSH_CONF_OPTS += \
+	--with-privsep-path=/run/sshd \
+	--with-pid-dir=/run \
+	--with-systemd
+
+else
+
 define OPENSSH_PERMISSIONS
 	/var/empty d 755 root root - - - - -
 endef
+endif
 
 ifeq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),)
 OPENSSH_CONF_OPTS += --without-pie
@@ -72,7 +84,7 @@ define OPENSSH_INSTALL_SYSTEMD_SYSUSERS
 endef
 else
 define OPENSSH_USERS
-	sshd -1 sshd -1 * /var/empty - - SSH drop priv user
+	sshd -1 sshd -1 * $(if $(BR2_PACKAGE_SYSTEMD),/run/sshd,/var/empty) - - SSH drop priv user
 endef
 endif
 
package/openssh/sshd-sysusers.conf +1 -1
index ac77aec065..303d0dbb63 100644
@@ -1 +1 @@
-u sshd - "SSH drop priv user" /var/empty
+u sshd - "SSH drop priv user" /run/sshd
package/openssh/sshd.service +11 -2
index b5e96b3a25..715bd3f7eb 100644
@@ -1,11 +1,20 @@
 [Unit]
 Description=OpenSSH server daemon
-After=syslog.target network.target auditd.service
+Documentation=man:sshd(8) man:sshd_config(5)
+After=network.target auditd.service
 
 [Service]
 ExecStartPre=/usr/bin/ssh-keygen -A
-ExecStart=/usr/sbin/sshd -D -e
+ExecStartPre=/usr/sbin/sshd -t
+ExecStart=/usr/sbin/sshd -D
+ExecReload=/usr/sbin/sshd -t
 ExecReload=/bin/kill -HUP $MAINPID
+KillMode=process
+Restart=on-failure
+RestartPreventExitStatus=255
+Type=notify
+RuntimeDirectory=sshd
+RuntimeDirectoryMode=0755
 
 [Install]
 WantedBy=multi-user.target
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/4 package/openssh: improve integration for systemd

Quoted 13 lines · On Sat, 6 Jun 2020 00:59:02 +0200 Norbert Lange <[email protected]> wrote:

the openssh daemon is not suited for systemd's simple service type. dependend services should only start when sshd is ready to accept connections.

A patch is added from debian to allow openssh to communicate this state.

Restarts are prevented if the reason is a faulty config file (errocode 255).

The "user confinement directory" is changed to '/run/sshd' which is automatically managed by systemd.

Quoted 8 lines
---
 package/openssh/00-systemd-readiness.patch | 84 ++++++++++++++++++++++
 package/openssh/openssh.mk                 | 14 +++-
 package/openssh/sshd-sysusers.conf         |  2 +-
 package/openssh/sshd.service               | 13 +++-
 4 files changed, 109 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/00-systemd-readiness.patch

On this patch, as well as patches 3/4 and 4/4 in this series, I would really appreciate some review from people more knowledgeable than I am in systemd.

Matt ? J?r?my ?

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw

PATCH 2/4 package/openssh: improve integration for systemd

In reply to Norbert Lange

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a ?crit :

Quoted 136 lines

the openssh daemon is not suited for systemd's simple service type. dependend services should only start when sshd is ready to accept connections.

A patch is added from debian to allow openssh to communicate this state.

Restarts are prevented if the reason is a faulty config file (errocode 255).

The "user confinement directory" is changed to '/run/sshd' which is automatically managed by systemd.

---
 package/openssh/00-systemd-readiness.patch | 84 ++++++++++++++++++++++
 package/openssh/openssh.mk                 | 14 +++-
 package/openssh/sshd-sysusers.conf         |  2 +-
 package/openssh/sshd.service               | 13 +++-
 4 files changed, 109 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/00-systemd-readiness.patch
package/openssh/00-systemd-readiness.patch new file +33 -0
new file mode 100644
index 0000000000..be3b6b0074
@@ -0,0 +1,84 @@
+From ab765b2bd55062a704f09da8f8c1c4ad1d6630a7 Mon Sep 17 00:00:00 2001
+From: Michael Biebl <[email protected]>
+Date: Mon, 21 Dec 2015 16:08:47 +0000
+Subject: Add systemd readiness notification support
+
+Bug-Debian: https://bugs.debian.org/778913
+Forwarded: no
+Last-Update: 2017-08-22
+
+Patch-Name: systemd-readiness.patch
+---
+ configure.ac | 24 ++++++++++++++++++++++++
+ sshd.c       |  9 +++++++++
+ 2 files changed, 33 insertions(+)
+
+diff --git a/configure.ac b/configure.ac
+index e894db9fc..c119d6fd1 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -4499,6 +4499,29 @@ AC_ARG_WITH([kerberos5],
+ AC_SUBST([GSSLIBS])
+ AC_SUBST([K5LIBS])
+
++# Check whether user wants systemd support
++SYSTEMD_MSG="no"
++AC_ARG_WITH(systemd,
++      [  --with-systemd          Enable systemd support],
++      [ if test "x$withval" != "xno" ; then
++              AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
++              if test "$PKGCONFIG" != "no"; then
++                      AC_MSG_CHECKING([for libsystemd])
++                      if $PKGCONFIG --exists libsystemd; then
++                              SYSTEMD_CFLAGS=`$PKGCONFIG --cflags

libsystemd`

++                              SYSTEMD_LIBS=`$PKGCONFIG --libs libsystemd`
++                              CPPFLAGS="$CPPFLAGS $SYSTEMD_CFLAGS"
++                              SSHDLIBS="$SSHDLIBS $SYSTEMD_LIBS"
++                              AC_MSG_RESULT([yes])
++                              AC_DEFINE(HAVE_SYSTEMD, 1, [Define if you

want systemd support.])
++ SYSTEMD_MSG="yes"
++ else
++ AC_MSG_RESULT([no])
++ fi
++ fi
++ fi ]
++)
++
+ # Looking for programs, paths and files

package/openssh/00-systemd-readiness.patch new file +31 -0
+
+ PRIVSEP_PATH=/var/empty
+@@ -5305,6 +5328,7 @@ echo "                   libldns support: $LDNS_MSG"
+ echo "  Solaris process contract support: $SPC_MSG"
+ echo "           Solaris project support: $SP_MSG"
+ echo "         Solaris privilege support: $SPP_MSG"
++echo "                   systemd support: $SYSTEMD_MSG"
+ echo "       IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
+ echo "           Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
+ echo "                  BSD Auth support: $BSD_AUTH_MSG"
+diff --git a/sshd.c b/sshd.c
+index 4e8ff0662..5e7679a33 100644
+--- a/sshd.c
++++ b/sshd.c
+@@ -85,6 +85,10 @@
+ #include <prot.h>
+ #endif
+
++#ifdef HAVE_SYSTEMD
++#include <systemd/sd-daemon.h>
++#endif
++
+ #include "xmalloc.h"
+ #include "ssh.h"
+ #include "ssh2.h"
+@@ -1951,6 +1955,11 @@ main(int ac, char **av)
+                       }
+               }
+
++#ifdef HAVE_SYSTEMD
++              /* Signal systemd that we are ready to accept connections

*/
++ sd_notify(0, "READY=1");
++#endif
++

package/openssh/00-systemd-readiness.patch new file +3 -0
+               /* Accept a connection and return in a forked child */
+               server_accept_loop(&sock_in, &sock_out,
+                   &newsock, config_s);
package/openssh/openssh.mk +5 -0
index 55b917e20a..d425db1428 100644
@@ -12,6 +12,7 @@ OPENSSH_CONF_ENV = \
        LD="$(TARGET_CC)" \
        LDFLAGS="$(TARGET_CFLAGS)" \
        LIBS=`$(PKG_CONFIG_HOST_BINARY) --libs openssl`
+OPENSSH_AUTORECONF = YES
 OPENSSH_CONF_OPTS = \
        --sysconfdir=/etc/ssh \
        --with-default-path=$(BR2_SYSTEM_DEFAULT_PATH) \
@@ -22,9 +23,20 @@ OPENSSH_CONF_OPTS = \
        --disable-wtmpx \
        --disable-strip
 
+ifeq ($(BR2_PACKAGE_SYSTEMD),y)
+OPENSSH_DEPENDENCIES = systemd
+
+OPENSSH_CONF_OPTS += \

package/openssh/openssh.mk OPENSSH_CONF_OPTS = \ · line 39

Quoted 10 lines
package/openssh/openssh.mk +6 -0
+       --with-privsep-path=/run/sshd \
+       --with-pid-dir=/run \
+       --with-systemd
+
+else
+
 define OPENSSH_PERMISSIONS
        /var/empty d 755 root root - - - - -
 endef
 

Do we still need this when using systemd, or can it be commented out ?

Quoted 30 lines
package/openssh/openssh.mk +1 -0
+endif
 
 ifeq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),)

OPENSSH_CONF_OPTS += --without-pie

package/openssh/openssh.mk +1 -1
@@ -72,7 +84,7 @@ define OPENSSH_INSTALL_SYSTEMD_SYSUSERS
 endef
 else
 define OPENSSH_USERS
-       sshd -1 sshd -1 * /var/empty - - SSH drop priv user
+       sshd -1 sshd -1 * $(if

$(BR2_PACKAGE_SYSTEMD),/run/sshd,/var/empty) - - SSH drop priv user
endef
endif

package/openssh/sshd-sysusers.conf +1 -1
index ac77aec065..303d0dbb63 100644
@@ -1 +1 @@
-u sshd - "SSH drop priv user" /var/empty
+u sshd - "SSH drop priv user" /run/sshd
package/openssh/sshd.service +0 -1
index b5e96b3a25..715bd3f7eb 100644
@@ -1,11 +1,20 @@
 [Unit]
 Description=OpenSSH server daemon
-After=syslog.target network.target auditd.service

package/openssh/sshd.service line 11

Quoted 10 lines
package/openssh/sshd.service +4 -1
+Documentation=man:sshd(8) man:sshd_config(5)
+After=network.target auditd.service
 
 
 [Service]
 ExecStartPre=/usr/bin/ssh-keygen -A
-ExecStart=/usr/sbin/sshd -D -e
+ExecStartPre=/usr/sbin/sshd -t
+ExecStart=/usr/sbin/sshd -D
 

You droped the -e, so you are logging to syslog However you droped the dependency on syslog.target earlier... (maybe it should be syslog.socket instead of .target, btw)

how exactly do you want to log ? (I think logging to stdout is better, it will be
redirected to the journal.

package/openssh/sshd.service line 18

Quoted 4 lines
package/openssh/sshd.service +2 -0
+ExecReload=/usr/sbin/sshd -t
 ExecReload=/bin/kill -HUP $MAINPID
+KillMode=process
 

Wouldn't mixed be better here ?
I'm not really sure what the use-case for procss is anyway...

Quoted 16 lines
package/openssh/sshd.service +5 -0
+Restart=on-failure
+RestartPreventExitStatus=255
+Type=notify
+RuntimeDirectory=sshd
+RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target
--
2.26.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

Signature · 21 lines
[image: SMILE]  <http://www.smile.eu/>

20 rue des Jardins
92600 Asni?res-sur-Seine
*J?r?my ROSEN*
Architecte technique

[image: email] jeremy.rosen at smile.fr
[image: phone]  +33 6 88 25 87 42
[image: url] http://www.smile.eu

[image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
<https://www.facebook.com/smileopensource> [image: LinkedIn]
<https://www.linkedin.com/company/smile> [image: Github]
<https://github.com/Smile-SA>

[image: D?couvrez l?univers Smile, rendez-vous sur smile.eu]
<https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20200607/19becf37/attachment.html>
#4 lore raw

PATCH 2/4 package/openssh: improve integration for systemd

Am So., 7. Juni 2020 um 12:54 Uhr schrieb J?r?my ROSEN <[email protected]>:

Quoted 133 lines

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a ?crit :

Quoted 129 lines

the openssh daemon is not suited for systemd's simple service type. dependend services should only start when sshd is ready to accept connections.

A patch is added from debian to allow openssh
to communicate this state.

Restarts are prevented if the reason is a faulty
config file (errocode 255).

The "user confinement directory" is changed to '/run/sshd' which is automatically managed by systemd.

---
 package/openssh/00-systemd-readiness.patch | 84 ++++++++++++++++++++++
 package/openssh/openssh.mk                 | 14 +++-
 package/openssh/sshd-sysusers.conf         |  2 +-
 package/openssh/sshd.service               | 13 +++-
 4 files changed, 109 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/00-systemd-readiness.patch
package/openssh/00-systemd-readiness.patch new file +84 -0
new file mode 100644
index 0000000000..be3b6b0074
@@ -0,0 +1,84 @@
+From ab765b2bd55062a704f09da8f8c1c4ad1d6630a7 Mon Sep 17 00:00:00 2001
+From: Michael Biebl <[email protected]>
+Date: Mon, 21 Dec 2015 16:08:47 +0000
+Subject: Add systemd readiness notification support
+
+Bug-Debian: https://bugs.debian.org/778913
+Forwarded: no
+Last-Update: 2017-08-22
+
+Patch-Name: systemd-readiness.patch
+---
+ configure.ac | 24 ++++++++++++++++++++++++
+ sshd.c       |  9 +++++++++
+ 2 files changed, 33 insertions(+)
+
+diff --git a/configure.ac b/configure.ac
+index e894db9fc..c119d6fd1 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -4499,6 +4499,29 @@ AC_ARG_WITH([kerberos5],
+ AC_SUBST([GSSLIBS])
+ AC_SUBST([K5LIBS])
+
++# Check whether user wants systemd support
++SYSTEMD_MSG="no"
++AC_ARG_WITH(systemd,
++      [  --with-systemd          Enable systemd support],
++      [ if test "x$withval" != "xno" ; then
++              AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
++              if test "$PKGCONFIG" != "no"; then
++                      AC_MSG_CHECKING([for libsystemd])
++                      if $PKGCONFIG --exists libsystemd; then
++                              SYSTEMD_CFLAGS=`$PKGCONFIG --cflags libsystemd`
++                              SYSTEMD_LIBS=`$PKGCONFIG --libs libsystemd`
++                              CPPFLAGS="$CPPFLAGS $SYSTEMD_CFLAGS"
++                              SSHDLIBS="$SSHDLIBS $SYSTEMD_LIBS"
++                              AC_MSG_RESULT([yes])
++                              AC_DEFINE(HAVE_SYSTEMD, 1, [Define if you want systemd support.])
++                              SYSTEMD_MSG="yes"
++                      else
++                              AC_MSG_RESULT([no])
++                      fi
++              fi
++      fi ]
++)
++
+ # Looking for programs, paths and files
+
+ PRIVSEP_PATH=/var/empty
+@@ -5305,6 +5328,7 @@ echo "                   libldns support: $LDNS_MSG"
+ echo "  Solaris process contract support: $SPC_MSG"
+ echo "           Solaris project support: $SP_MSG"
+ echo "         Solaris privilege support: $SPP_MSG"
++echo "                   systemd support: $SYSTEMD_MSG"
+ echo "       IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
+ echo "           Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
+ echo "                  BSD Auth support: $BSD_AUTH_MSG"
+diff --git a/sshd.c b/sshd.c
+index 4e8ff0662..5e7679a33 100644
+--- a/sshd.c
++++ b/sshd.c
+@@ -85,6 +85,10 @@
+ #include <prot.h>
+ #endif
+
++#ifdef HAVE_SYSTEMD
++#include <systemd/sd-daemon.h>
++#endif
++
+ #include "xmalloc.h"
+ #include "ssh.h"
+ #include "ssh2.h"
+@@ -1951,6 +1955,11 @@ main(int ac, char **av)
+                       }
+               }
+
++#ifdef HAVE_SYSTEMD
++              /* Signal systemd that we are ready to accept connections */
++              sd_notify(0, "READY=1");
++#endif
++
+               /* Accept a connection and return in a forked child */
+               server_accept_loop(&sock_in, &sock_out,
+                   &newsock, config_s);
package/openssh/openssh.mk +1 -0
index 55b917e20a..d425db1428 100644
@@ -12,6 +12,7 @@ OPENSSH_CONF_ENV = \
        LD="$(TARGET_CC)" \
        LDFLAGS="$(TARGET_CFLAGS)" \
        LIBS=`$(PKG_CONFIG_HOST_BINARY) --libs openssl`
+OPENSSH_AUTORECONF = YES
 OPENSSH_CONF_OPTS = \
        --sysconfdir=/etc/ssh \
        --with-default-path=$(BR2_SYSTEM_DEFAULT_PATH) \
@@ -22,9 +23,20 @@ OPENSSH_CONF_OPTS = \
        --disable-wtmpx \
        --disable-strip
 
Quoted 16 lines

package/openssh/openssh.mk OPENSSH_CONF_OPTS = \ · line 38

Quoted 13 lines
package/openssh/openssh.mk +10 -0
+ifeq ($(BR2_PACKAGE_SYSTEMD),y)
+OPENSSH_DEPENDENCIES = systemd
+
+OPENSSH_CONF_OPTS += \
+       --with-privsep-path=/run/sshd \
+       --with-pid-dir=/run \
+       --with-systemd
+
+else
+
 define OPENSSH_PERMISSIONS
        /var/empty d 755 root root - - - - -
 endef

Do we still need this when using systemd, or can it be commented out ?

Not sure what you mean with "this"?
The OPENSSH_PERMISSIONS block is needed when not using systemd and it is only active then.

Quoted 35 lines
Quoted 35 lines
package/openssh/openssh.mk +2 -1
+endif
 
 ifeq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),)
 OPENSSH_CONF_OPTS += --without-pie
@@ -72,7 +84,7 @@ define OPENSSH_INSTALL_SYSTEMD_SYSUSERS
 endef
 else
 define OPENSSH_USERS
-       sshd -1 sshd -1 * /var/empty - - SSH drop priv user
+       sshd -1 sshd -1 * $(if $(BR2_PACKAGE_SYSTEMD),/run/sshd,/var/empty) - - SSH drop priv user
 endef
 endif
 
package/openssh/sshd-sysusers.conf +1 -1
index ac77aec065..303d0dbb63 100644
@@ -1 +1 @@
-u sshd - "SSH drop priv user" /var/empty
+u sshd - "SSH drop priv user" /run/sshd
package/openssh/sshd.service +2 -1
index b5e96b3a25..715bd3f7eb 100644
@@ -1,11 +1,20 @@
 [Unit]
 Description=OpenSSH server daemon
-After=syslog.target network.target auditd.service
+Documentation=man:sshd(8) man:sshd_config(5)
+After=network.target auditd.service
 
 
Quoted 9 lines

package/openssh/sshd.service line 9

Quoted 5 lines
package/openssh/sshd.service +2 -1
 [Service]
 ExecStartPre=/usr/bin/ssh-keygen -A
-ExecStart=/usr/sbin/sshd -D -e
+ExecStartPre=/usr/sbin/sshd -t
+ExecStart=/usr/sbin/sshd -D

You droped the -e, so you are logging to syslog However you droped the dependency on syslog.target earlier... (maybe it should be syslog.socket instead of .target, btw)

syslog.target is long long gone, and the syslog will be unconditionally available
https://www.freedesktop.org/wiki/Software/systemd/syslog/

Quoted 4 lines

how exactly do you want to log ? (I think logging to stdout is better, it will be redirected to the journal.

stdout is not really useful if syslog is supported.

Quoted 10 lines

package/openssh/sshd.service line 12

Quoted 6 lines
package/openssh/sshd.service +2 -0
+ExecReload=/usr/sbin/sshd -t
 ExecReload=/bin/kill -HUP $MAINPID
+KillMode=process

Wouldn't mixed be better here ?
I'm not really sure what the use-case for procss is anyway...

I taken that from debian, I could not argue against it (there is a long discussion which I linked above).
Can you argue *for* mixed?

Quoted 27 lines
Quoted 14 lines
package/openssh/sshd.service +5 -0
+Restart=on-failure
+RestartPreventExitStatus=255
+Type=notify
+RuntimeDirectory=sshd
+RuntimeDirectoryMode=0755
 
 [Install]

WantedBy=multi-user.target
--
2.26.2

Quoted 4 lines

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

--

20 rue des Jardins
92600 Asni?res-sur-Seine

Quoted 9 lines

J?r?my ROSEN
Architecte technique

jeremy.rosen at smile.fr
+33 6 88 25 87 42
http://www.smile.eu

Regards, Norbert

#5 lore raw

PATCH 2/4 package/openssh: improve integration for systemd

Le dim. 7 juin 2020 ? 21:03, Norbert Lange <[email protected]> a ?crit :

Quoted 159 lines

Am So., 7. Juni 2020 um 12:54 Uhr schrieb J?r?my ROSEN < jeremy.rosen at smile.fr>:

Quoted 4 lines

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a

?crit :

Quoted 23 lines
Quoted 23 lines

the openssh daemon is not suited for systemd's simple service type. dependend services should only start when sshd is ready to accept connections.

A patch is added from debian to allow openssh to communicate this state.

Restarts are prevented if the reason is a faulty config file (errocode 255).

The "user confinement directory" is changed to '/run/sshd' which is automatically managed by systemd.

---
 package/openssh/00-systemd-readiness.patch | 84 ++++++++++++++++++++++
 package/openssh/openssh.mk                 | 14 +++-
 package/openssh/sshd-sysusers.conf         |  2 +-
 package/openssh/sshd.service               | 13 +++-
 4 files changed, 109 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/00-systemd-readiness.patch
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/package/openssh/00-systemd-readiness.patch

Quoted 30 lines
Quoted 30 lines

new file mode 100644
index 0000000000..be3b6b0074

package/openssh/00-systemd-readiness.patch new file +25 -0
@@ -0,0 +1,84 @@
+From ab765b2bd55062a704f09da8f8c1c4ad1d6630a7 Mon Sep 17 00:00:00 2001
+From: Michael Biebl <[email protected]>
+Date: Mon, 21 Dec 2015 16:08:47 +0000
+Subject: Add systemd readiness notification support
+
+Bug-Debian: https://bugs.debian.org/778913
+Forwarded: no
+Last-Update: 2017-08-22
+
+Patch-Name: systemd-readiness.patch
+---
+ configure.ac | 24 ++++++++++++++++++++++++
+ sshd.c       |  9 +++++++++
+ 2 files changed, 33 insertions(+)
+
+diff --git a/configure.ac b/configure.ac
+index e894db9fc..c119d6fd1 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -4499,6 +4499,29 @@ AC_ARG_WITH([kerberos5],
+ AC_SUBST([GSSLIBS])
+ AC_SUBST([K5LIBS])
+
++# Check whether user wants systemd support
++SYSTEMD_MSG="no"
Quoted 8 lines

package/openssh/00-systemd-readiness.patch

Quoted 8 lines
package/openssh/00-systemd-readiness.patch new file +8 -0
++AC_ARG_WITH(systemd,
++      [  --with-systemd          Enable systemd support],
++      [ if test "x$withval" != "xno" ; then
++              AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
++              if test "$PKGCONFIG" != "no"; then
++                      AC_MSG_CHECKING([for libsystemd])
++                      if $PKGCONFIG --exists libsystemd; then
++                              SYSTEMD_CFLAGS=`$PKGCONFIG --cflags

libsystemd`

Quoted 1 line

package/openssh/00-systemd-readiness.patch line 34

Quoted 1 line
package/openssh/00-systemd-readiness.patch new file +1 -0
++                              SYSTEMD_LIBS=`$PKGCONFIG --libs

libsystemd`

Quoted 4 lines

package/openssh/00-systemd-readiness.patch

Quoted 4 lines
package/openssh/00-systemd-readiness.patch new file +4 -0
++                              CPPFLAGS="$CPPFLAGS $SYSTEMD_CFLAGS"
++                              SSHDLIBS="$SSHDLIBS $SYSTEMD_LIBS"
++                              AC_MSG_RESULT([yes])
++                              AC_DEFINE(HAVE_SYSTEMD, 1, [Define if

you want systemd support.])

Quoted 4 lines
Quoted 4 lines
package/openssh/00-systemd-readiness.patch new file +4 -0
++                              SYSTEMD_MSG="yes"
++                      else
++                              AC_MSG_RESULT([no])
++                      fi
Quoted 8 lines

package/openssh/00-systemd-readiness.patch

Quoted 8 lines
package/openssh/00-systemd-readiness.patch new file +8 -0
++              fi
++      fi ]
++)
++
+ # Looking for programs, paths and files
+
+ PRIVSEP_PATH=/var/empty
+@@ -5305,6 +5328,7 @@ echo "                   libldns support:

$LDNS_MSG"

Quoted 20 lines
Quoted 20 lines
package/openssh/00-systemd-readiness.patch new file +20 -0
+ echo "  Solaris process contract support: $SPC_MSG"
+ echo "           Solaris project support: $SP_MSG"
+ echo "         Solaris privilege support: $SPP_MSG"
++echo "                   systemd support: $SYSTEMD_MSG"
+ echo "       IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
+ echo "           Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
+ echo "                  BSD Auth support: $BSD_AUTH_MSG"
+diff --git a/sshd.c b/sshd.c
+index 4e8ff0662..5e7679a33 100644
+--- a/sshd.c
++++ b/sshd.c
+@@ -85,6 +85,10 @@
+ #include <prot.h>
+ #endif
+
++#ifdef HAVE_SYSTEMD
++#include <systemd/sd-daemon.h>
++#endif
++
+ #include "xmalloc.h"
Quoted 8 lines

package/openssh/00-systemd-readiness.patch

Quoted 8 lines
package/openssh/00-systemd-readiness.patch new file +8 -0
+ #include "ssh.h"
+ #include "ssh2.h"
+@@ -1951,6 +1955,11 @@ main(int ac, char **av)
+                       }
+               }
+
++#ifdef HAVE_SYSTEMD
++              /* Signal systemd that we are ready to accept

connections */

Quoted 22 lines
Quoted 22 lines
package/openssh/00-systemd-readiness.patch new file +6 -0
++              sd_notify(0, "READY=1");
++#endif
++
+               /* Accept a connection and return in a forked child */
+               server_accept_loop(&sock_in, &sock_out,
+                   &newsock, config_s);
package/openssh/openssh.mk +1 -0
index 55b917e20a..d425db1428 100644
@@ -12,6 +12,7 @@ OPENSSH_CONF_ENV = \
        LD="$(TARGET_CC)" \
        LDFLAGS="$(TARGET_CFLAGS)" \
        LIBS=`$(PKG_CONFIG_HOST_BINARY) --libs openssl`
+OPENSSH_AUTORECONF = YES
 OPENSSH_CONF_OPTS = \
        --sysconfdir=/etc/ssh \
        --with-default-path=$(BR2_SYSTEM_DEFAULT_PATH) \
@@ -22,9 +23,20 @@ OPENSSH_CONF_OPTS = \
        --disable-wtmpx \
        --disable-strip
 
Quoted 16 lines

package/openssh/openssh.mk OPENSSH_CONF_OPTS = \ · line 38

Quoted 13 lines
package/openssh/openssh.mk +10 -0
+ifeq ($(BR2_PACKAGE_SYSTEMD),y)
+OPENSSH_DEPENDENCIES = systemd
+
+OPENSSH_CONF_OPTS += \
+       --with-privsep-path=/run/sshd \
+       --with-pid-dir=/run \
+       --with-systemd
+
+else
+
 define OPENSSH_PERMISSIONS
        /var/empty d 755 root root - - - - -
 endef

Do we still need this when using systemd, or can it be commented out ?

Quoted 5 lines

Not sure what you mean with "this"?
The OPENSSH_PERMISSIONS block is needed when not using systemd and it is only active then.

my bad, I missed the enclosing ifeq()

Quoted 55 lines
Quoted 5 lines
Quoted 5 lines
package/openssh/openssh.mk +1 -0
+endif
 
Quoted 8 lines

package/openssh/openssh.mk define OPENSSH_INSTALL_SYSTEMD_SYSUSERS · line 87

Quoted 8 lines
package/openssh/openssh.mk +1 -1
 ifeq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),)
 OPENSSH_CONF_OPTS += --without-pie
@@ -72,7 +84,7 @@ define OPENSSH_INSTALL_SYSTEMD_SYSUSERS
 endef
 else
 define OPENSSH_USERS
-       sshd -1 sshd -1 * /var/empty - - SSH drop priv user
+       sshd -1 sshd -1 * $(if

$(BR2_PACKAGE_SYSTEMD),/run/sshd,/var/empty) - - SSH drop priv user

Quoted 4 lines

Review

Quoted 4 lines
package/openssh/openssh.mk +0 -0
 endef
 endif
 
(quoted diff) +0 -0

b/package/openssh/sshd-sysusers.conf

Quoted 18 lines
Quoted 18 lines

index ac77aec065..303d0dbb63 100644

package/openssh/sshd-sysusers.conf +1 -1
@@ -1 +1 @@
-u sshd - "SSH drop priv user" /var/empty
+u sshd - "SSH drop priv user" /run/sshd
package/openssh/sshd.service +2 -1
index b5e96b3a25..715bd3f7eb 100644
@@ -1,11 +1,20 @@
 [Unit]
 Description=OpenSSH server daemon
-After=syslog.target network.target auditd.service
+Documentation=man:sshd(8) man:sshd_config(5)
+After=network.target auditd.service
 
 
Quoted 9 lines

package/openssh/sshd.service line 9

Quoted 5 lines
package/openssh/sshd.service +2 -1
 [Service]
 ExecStartPre=/usr/bin/ssh-keygen -A
-ExecStart=/usr/sbin/sshd -D -e
+ExecStartPre=/usr/sbin/sshd -t
+ExecStart=/usr/sbin/sshd -D

You droped the -e, so you are logging to syslog However you droped the dependency on syslog.target earlier... (maybe it should be syslog.socket instead of .target, btw)

syslog.target is long long gone, and the syslog will be unconditionally available
https://www.freedesktop.org/wiki/Software/systemd/syslog/

Quoted 2 lines
Quoted 8 lines
Quoted 1 line

how exactly do you want to log ? (I think logging to stdout is better,

it will be

Quoted 1 line

redirected to the journal.

stdout is not really useful if syslog is supported.

i'd go the other way round

syslog is not really necessary if stdout is available, but it's a matter of taste :P so let's go your way.

Quoted 12 lines
Quoted 10 lines

package/openssh/sshd.service line 12

Quoted 6 lines
package/openssh/sshd.service +2 -0
+ExecReload=/usr/sbin/sshd -t
 ExecReload=/bin/kill -HUP $MAINPID
+KillMode=process

Wouldn't mixed be better here ?
I'm not really sure what the use-case for procss is anyway...

Quoted 5 lines

I taken that from debian, I could not argue against it (there is a long discussion which I linked above).
Can you argue *for* mixed?

I didn't see any link
* process : SIGTERM and SIGKILL is sent only to MainPID
* mixed : SIGTERM is sent to MainPID, SIGKILL is sent to every process in the service cgroup.

This means that if all works well, they do the same thing

in case the MainPID fails to properly terminate its children, process would leave children alive
but mixed woul kill everybody

Since we are trying to terminate the service, it makes sense to me to make sur all child process
are killed.

but I don't see your link so I may be missing something

Quoted 39 lines
Quoted 27 lines
Quoted 14 lines
package/openssh/sshd.service +5 -0
+Restart=on-failure
+RestartPreventExitStatus=255
+Type=notify
+RuntimeDirectory=sshd
+RuntimeDirectoryMode=0755
 
 [Install]

WantedBy=multi-user.target
--
2.26.2

Quoted 4 lines

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

--

20 rue des Jardins
92600 Asni?res-sur-Seine

Quoted 9 lines

J?r?my ROSEN
Architecte technique

jeremy.rosen at smile.fr
+33 6 88 25 87 42
http://www.smile.eu

Regards, Norbert

Signature · 21 lines
[image: SMILE]  <http://www.smile.eu/>

20 rue des Jardins
92600 Asni?res-sur-Seine
*J?r?my ROSEN*
Architecte technique

[image: email] jeremy.rosen at smile.fr
[image: phone]  +33 6 88 25 87 42
[image: url] http://www.smile.eu

[image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
<https://www.facebook.com/smileopensource> [image: LinkedIn]
<https://www.linkedin.com/company/smile> [image: Github]
<https://github.com/Smile-SA>

[image: D?couvrez l?univers Smile, rendez-vous sur smile.eu]
<https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20200607/1ef4b42e/attachment.html>
#6 lore raw

PATCH 2/4 package/openssh: improve integration for systemd

Am So., 7. Juni 2020 um 21:16 Uhr schrieb J?r?my ROSEN <[email protected]>:

Quoted 221 lines

Le dim. 7 juin 2020 ? 21:03, Norbert Lange <[email protected]> a ?crit :

Quoted 152 lines

Am So., 7. Juni 2020 um 12:54 Uhr schrieb J?r?my ROSEN <[email protected]>:

Quoted 133 lines

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a ?crit :

Quoted 129 lines

the openssh daemon is not suited for systemd's simple service type. dependend services should only start when sshd is ready to accept connections.

A patch is added from debian to allow openssh
to communicate this state.

Restarts are prevented if the reason is a faulty
config file (errocode 255).

The "user confinement directory" is changed to '/run/sshd' which is automatically managed by systemd.

---
 package/openssh/00-systemd-readiness.patch | 84 ++++++++++++++++++++++
 package/openssh/openssh.mk                 | 14 +++-
 package/openssh/sshd-sysusers.conf         |  2 +-
 package/openssh/sshd.service               | 13 +++-
 4 files changed, 109 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/00-systemd-readiness.patch
package/openssh/00-systemd-readiness.patch new file +84 -0
new file mode 100644
index 0000000000..be3b6b0074
@@ -0,0 +1,84 @@
+From ab765b2bd55062a704f09da8f8c1c4ad1d6630a7 Mon Sep 17 00:00:00 2001
+From: Michael Biebl <[email protected]>
+Date: Mon, 21 Dec 2015 16:08:47 +0000
+Subject: Add systemd readiness notification support
+
+Bug-Debian: https://bugs.debian.org/778913
+Forwarded: no
+Last-Update: 2017-08-22
+
+Patch-Name: systemd-readiness.patch
+---
+ configure.ac | 24 ++++++++++++++++++++++++
+ sshd.c       |  9 +++++++++
+ 2 files changed, 33 insertions(+)
+
+diff --git a/configure.ac b/configure.ac
+index e894db9fc..c119d6fd1 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -4499,6 +4499,29 @@ AC_ARG_WITH([kerberos5],
+ AC_SUBST([GSSLIBS])
+ AC_SUBST([K5LIBS])
+
++# Check whether user wants systemd support
++SYSTEMD_MSG="no"
++AC_ARG_WITH(systemd,
++      [  --with-systemd          Enable systemd support],
++      [ if test "x$withval" != "xno" ; then
++              AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
++              if test "$PKGCONFIG" != "no"; then
++                      AC_MSG_CHECKING([for libsystemd])
++                      if $PKGCONFIG --exists libsystemd; then
++                              SYSTEMD_CFLAGS=`$PKGCONFIG --cflags libsystemd`
++                              SYSTEMD_LIBS=`$PKGCONFIG --libs libsystemd`
++                              CPPFLAGS="$CPPFLAGS $SYSTEMD_CFLAGS"
++                              SSHDLIBS="$SSHDLIBS $SYSTEMD_LIBS"
++                              AC_MSG_RESULT([yes])
++                              AC_DEFINE(HAVE_SYSTEMD, 1, [Define if you want systemd support.])
++                              SYSTEMD_MSG="yes"
++                      else
++                              AC_MSG_RESULT([no])
++                      fi
++              fi
++      fi ]
++)
++
+ # Looking for programs, paths and files
+
+ PRIVSEP_PATH=/var/empty
+@@ -5305,6 +5328,7 @@ echo "                   libldns support: $LDNS_MSG"
+ echo "  Solaris process contract support: $SPC_MSG"
+ echo "           Solaris project support: $SP_MSG"
+ echo "         Solaris privilege support: $SPP_MSG"
++echo "                   systemd support: $SYSTEMD_MSG"
+ echo "       IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
+ echo "           Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
+ echo "                  BSD Auth support: $BSD_AUTH_MSG"
+diff --git a/sshd.c b/sshd.c
+index 4e8ff0662..5e7679a33 100644
+--- a/sshd.c
++++ b/sshd.c
+@@ -85,6 +85,10 @@
+ #include <prot.h>
+ #endif
+
++#ifdef HAVE_SYSTEMD
++#include <systemd/sd-daemon.h>
++#endif
++
+ #include "xmalloc.h"
+ #include "ssh.h"
+ #include "ssh2.h"
+@@ -1951,6 +1955,11 @@ main(int ac, char **av)
+                       }
+               }
+
++#ifdef HAVE_SYSTEMD
++              /* Signal systemd that we are ready to accept connections */
++              sd_notify(0, "READY=1");
++#endif
++
+               /* Accept a connection and return in a forked child */
+               server_accept_loop(&sock_in, &sock_out,
+                   &newsock, config_s);
package/openssh/openssh.mk +1 -0
index 55b917e20a..d425db1428 100644
@@ -12,6 +12,7 @@ OPENSSH_CONF_ENV = \
        LD="$(TARGET_CC)" \
        LDFLAGS="$(TARGET_CFLAGS)" \
        LIBS=`$(PKG_CONFIG_HOST_BINARY) --libs openssl`
+OPENSSH_AUTORECONF = YES
 OPENSSH_CONF_OPTS = \
        --sysconfdir=/etc/ssh \
        --with-default-path=$(BR2_SYSTEM_DEFAULT_PATH) \
@@ -22,9 +23,20 @@ OPENSSH_CONF_OPTS = \
        --disable-wtmpx \
        --disable-strip
 
Quoted 16 lines

package/openssh/openssh.mk OPENSSH_CONF_OPTS = \ · line 38

Quoted 13 lines
package/openssh/openssh.mk +10 -0
+ifeq ($(BR2_PACKAGE_SYSTEMD),y)
+OPENSSH_DEPENDENCIES = systemd
+
+OPENSSH_CONF_OPTS += \
+       --with-privsep-path=/run/sshd \
+       --with-pid-dir=/run \
+       --with-systemd
+
+else
+
 define OPENSSH_PERMISSIONS
        /var/empty d 755 root root - - - - -
 endef

Do we still need this when using systemd, or can it be commented out ?

Quoted 4 lines

Not sure what you mean with "this"?
The OPENSSH_PERMISSIONS block is needed when not using systemd and it is only active then.

my bad, I missed the enclosing ifeq()

Quoted 58 lines
Quoted 36 lines
Quoted 36 lines
package/openssh/openssh.mk +2 -1
+endif
 
 ifeq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),)
 OPENSSH_CONF_OPTS += --without-pie
@@ -72,7 +84,7 @@ define OPENSSH_INSTALL_SYSTEMD_SYSUSERS
 endef
 else
 define OPENSSH_USERS
-       sshd -1 sshd -1 * /var/empty - - SSH drop priv user
+       sshd -1 sshd -1 * $(if $(BR2_PACKAGE_SYSTEMD),/run/sshd,/var/empty) - - SSH drop priv user
 endef
 endif
 
package/openssh/sshd-sysusers.conf +1 -1
index ac77aec065..303d0dbb63 100644
@@ -1 +1 @@
-u sshd - "SSH drop priv user" /var/empty
+u sshd - "SSH drop priv user" /run/sshd
package/openssh/sshd.service +2 -1
index b5e96b3a25..715bd3f7eb 100644
@@ -1,11 +1,20 @@
 [Unit]
 Description=OpenSSH server daemon
-After=syslog.target network.target auditd.service
+Documentation=man:sshd(8) man:sshd_config(5)
+After=network.target auditd.service
 
 
Quoted 9 lines

package/openssh/sshd.service line 9

Quoted 5 lines
package/openssh/sshd.service +2 -1
 [Service]
 ExecStartPre=/usr/bin/ssh-keygen -A
-ExecStart=/usr/sbin/sshd -D -e
+ExecStartPre=/usr/sbin/sshd -t
+ExecStart=/usr/sbin/sshd -D

You droped the -e, so you are logging to syslog However you droped the dependency on syslog.target earlier... (maybe it should be syslog.socket instead of .target, btw)

syslog.target is long long gone, and the syslog will be unconditionally available
https://www.freedesktop.org/wiki/Software/systemd/syslog/

Quoted 4 lines

how exactly do you want to log ? (I think logging to stdout is better, it will be redirected to the journal.

Quoted 6 lines
Quoted 2 lines

stdout is not really useful if syslog is supported.

i'd go the other way round

syslog is not really necessary if stdout is available, but it's a matter of taste :P so let's go your way.

Its more the point, that Openssh already implemented syslog, and thats a clear functional superset of listening to stdout.

Quoted 26 lines
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 7 lines

package/openssh/sshd.service line 12

Quoted 3 lines
package/openssh/sshd.service +2 -0
+ExecReload=/usr/sbin/sshd -t
 ExecReload=/bin/kill -HUP $MAINPID
+KillMode=process

Wouldn't mixed be better here ?
I'm not really sure what the use-case for procss is anyway...

Quoted 4 lines

I taken that from debian, I could not argue against it (there is a long discussion which I linked above).
Can you argue *for* mixed?

I didn't see any link
* process : SIGTERM and SIGKILL is sent only to MainPID
* mixed : SIGTERM is sent to MainPID, SIGKILL is sent to every process in the service cgroup.

This means that if all works well, they do the same thing

Quoted 7 lines

in case the MainPID fails to properly terminate its children, process would leave children alive but mixed woul kill everybody

Since we are trying to terminate the service, it makes sense to me to make sur all child process are killed.

but I don't see your link so I may be missing something

The link is in the added patch: https://bugs.debian.org/778913

As said, I could not argue either way, but I got some respect for the debian guys ;)

Norbert

#7 lore raw

PATCH 2/4 package/openssh: improve integration for systemd

Le dim. 7 juin 2020 ? 21:24, Norbert Lange <[email protected]> a ?crit :

Quoted 282 lines

Am So., 7. Juni 2020 um 21:16 Uhr schrieb J?r?my ROSEN < jeremy.rosen at smile.fr>:

Quoted 4 lines

Le dim. 7 juin 2020 ? 21:03, Norbert Lange <[email protected]> a

?crit :

Quoted 2 lines
Quoted 2 lines

Am So., 7. Juni 2020 um 12:54 Uhr schrieb J?r?my ROSEN <

jeremy.rosen at smile.fr>:

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a

?crit :

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

the openssh daemon is not suited for systemd's simple service type. dependend services should only start when sshd is ready to accept connections.

A patch is added from debian to allow openssh to communicate this state.

Restarts are prevented if the reason is a faulty config file (errocode 255).

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The "user confinement directory" is changed to '/run/sshd' which is automatically managed by systemd.

---
 package/openssh/00-systemd-readiness.patch | 84

++++++++++++++++++++++

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Review

Quoted 7 lines
 package/openssh/openssh.mk                 | 14 +++-
 package/openssh/sshd-sysusers.conf         |  2 +-
 package/openssh/sshd.service               | 13 +++-
 4 files changed, 109 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/00-systemd-readiness.patch
(quoted diff) +0 -0

b/package/openssh/00-systemd-readiness.patch

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

package/openssh/00-systemd-readiness.patch line 1

Quoted 6 lines

new file mode 100644
index 0000000000..be3b6b0074

package/openssh/00-systemd-readiness.patch new file +1 -0
@@ -0,0 +1,84 @@
+From ab765b2bd55062a704f09da8f8c1c4ad1d6630a7 Mon Sep 17 00:00:00

2001

Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
package/openssh/00-systemd-readiness.patch new file +24 -0
+From: Michael Biebl <[email protected]>
+Date: Mon, 21 Dec 2015 16:08:47 +0000
+Subject: Add systemd readiness notification support
+
+Bug-Debian: https://bugs.debian.org/778913
+Forwarded: no
+Last-Update: 2017-08-22
+
+Patch-Name: systemd-readiness.patch
+---
+ configure.ac | 24 ++++++++++++++++++++++++
+ sshd.c       |  9 +++++++++
+ 2 files changed, 33 insertions(+)
+
+diff --git a/configure.ac b/configure.ac
+index e894db9fc..c119d6fd1 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -4499,6 +4499,29 @@ AC_ARG_WITH([kerberos5],
+ AC_SUBST([GSSLIBS])
+ AC_SUBST([K5LIBS])
+
++# Check whether user wants systemd support
++SYSTEMD_MSG="no"
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

package/openssh/00-systemd-readiness.patch

Quoted 8 lines
package/openssh/00-systemd-readiness.patch new file +8 -0
++AC_ARG_WITH(systemd,
++      [  --with-systemd          Enable systemd support],
++      [ if test "x$withval" != "xno" ; then
++              AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
++              if test "$PKGCONFIG" != "no"; then
++                      AC_MSG_CHECKING([for libsystemd])
++                      if $PKGCONFIG --exists libsystemd; then
++                              SYSTEMD_CFLAGS=`$PKGCONFIG --cflags

libsystemd`

Quoted 1 line
Quoted 1 line
Quoted 1 line

package/openssh/00-systemd-readiness.patch line 34

Quoted 1 line
package/openssh/00-systemd-readiness.patch new file +1 -0
++                              SYSTEMD_LIBS=`$PKGCONFIG --libs

libsystemd`

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

package/openssh/00-systemd-readiness.patch

Quoted 4 lines
package/openssh/00-systemd-readiness.patch new file +4 -0
++                              CPPFLAGS="$CPPFLAGS $SYSTEMD_CFLAGS"
++                              SSHDLIBS="$SSHDLIBS $SYSTEMD_LIBS"
++                              AC_MSG_RESULT([yes])
++                              AC_DEFINE(HAVE_SYSTEMD, 1, [Define

if you want systemd support.])

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
package/openssh/00-systemd-readiness.patch new file +4 -0
++                              SYSTEMD_MSG="yes"
++                      else
++                              AC_MSG_RESULT([no])
++                      fi
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

package/openssh/00-systemd-readiness.patch

Quoted 8 lines
package/openssh/00-systemd-readiness.patch new file +8 -0
++              fi
++      fi ]
++)
++
+ # Looking for programs, paths and files
+
+ PRIVSEP_PATH=/var/empty
+@@ -5305,6 +5328,7 @@ echo "                   libldns support:

$LDNS_MSG"

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
package/openssh/00-systemd-readiness.patch new file +20 -0
+ echo "  Solaris process contract support: $SPC_MSG"
+ echo "           Solaris project support: $SP_MSG"
+ echo "         Solaris privilege support: $SPP_MSG"
++echo "                   systemd support: $SYSTEMD_MSG"
+ echo "       IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
+ echo "           Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
+ echo "                  BSD Auth support: $BSD_AUTH_MSG"
+diff --git a/sshd.c b/sshd.c
+index 4e8ff0662..5e7679a33 100644
+--- a/sshd.c
++++ b/sshd.c
+@@ -85,6 +85,10 @@
+ #include <prot.h>
+ #endif
+
++#ifdef HAVE_SYSTEMD
++#include <systemd/sd-daemon.h>
++#endif
++
+ #include "xmalloc.h"
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

package/openssh/00-systemd-readiness.patch

Quoted 8 lines
package/openssh/00-systemd-readiness.patch new file +8 -0
+ #include "ssh.h"
+ #include "ssh2.h"
+@@ -1951,6 +1955,11 @@ main(int ac, char **av)
+                       }
+               }
+
++#ifdef HAVE_SYSTEMD
++              /* Signal systemd that we are ready to accept

connections */

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

package/openssh/00-systemd-readiness.patch

Quoted 4 lines
package/openssh/00-systemd-readiness.patch new file +4 -0
++              sd_notify(0, "READY=1");
++#endif
++
+               /* Accept a connection and return in a forked child

*/

Quoted 48 lines
Quoted 35 lines
Quoted 18 lines
Quoted 18 lines
package/openssh/00-systemd-readiness.patch new file +2 -0
+               server_accept_loop(&sock_in, &sock_out,
+                   &newsock, config_s);
package/openssh/openssh.mk +1 -0
index 55b917e20a..d425db1428 100644
@@ -12,6 +12,7 @@ OPENSSH_CONF_ENV = \
        LD="$(TARGET_CC)" \
        LDFLAGS="$(TARGET_CFLAGS)" \
        LIBS=`$(PKG_CONFIG_HOST_BINARY) --libs openssl`
+OPENSSH_AUTORECONF = YES
 OPENSSH_CONF_OPTS = \
        --sysconfdir=/etc/ssh \
        --with-default-path=$(BR2_SYSTEM_DEFAULT_PATH) \
@@ -22,9 +23,20 @@ OPENSSH_CONF_OPTS = \
        --disable-wtmpx \
        --disable-strip
 
Quoted 16 lines

package/openssh/openssh.mk OPENSSH_CONF_OPTS = \ · line 38

Quoted 13 lines
package/openssh/openssh.mk +10 -0
+ifeq ($(BR2_PACKAGE_SYSTEMD),y)
+OPENSSH_DEPENDENCIES = systemd
+
+OPENSSH_CONF_OPTS += \
+       --with-privsep-path=/run/sshd \
+       --with-pid-dir=/run \
+       --with-systemd
+
+else
+
 define OPENSSH_PERMISSIONS
        /var/empty d 755 root root - - - - -
 endef

Do we still need this when using systemd, or can it be commented out ?

Quoted 4 lines

Not sure what you mean with "this"?
The OPENSSH_PERMISSIONS block is needed when not using systemd and it is only active then.

my bad, I missed the enclosing ifeq()

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
package/openssh/openssh.mk +1 -0
+endif
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

package/openssh/openssh.mk define OPENSSH_INSTALL_SYSTEMD_SYSUSERS · line 87

Quoted 8 lines
package/openssh/openssh.mk +1 -1
 ifeq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),)
 OPENSSH_CONF_OPTS += --without-pie
@@ -72,7 +84,7 @@ define OPENSSH_INSTALL_SYSTEMD_SYSUSERS
 endef
 else
 define OPENSSH_USERS
-       sshd -1 sshd -1 * /var/empty - - SSH drop priv user
+       sshd -1 sshd -1 * $(if

$(BR2_PACKAGE_SYSTEMD),/run/sshd,/var/empty) - - SSH drop priv user

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Review

Quoted 4 lines
package/openssh/openssh.mk +0 -0
 endef
 endif
 
(quoted diff) +0 -0

b/package/openssh/sshd-sysusers.conf

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Review

Quoted 7 lines

index ac77aec065..303d0dbb63 100644

package/openssh/sshd-sysusers.conf +1 -1
@@ -1 +1 @@
-u sshd - "SSH drop priv user" /var/empty
+u sshd - "SSH drop priv user" /run/sshd
(quoted diff) +0 -0

b/package/openssh/sshd.service

Quoted 22 lines
Quoted 22 lines
Quoted 20 lines
Quoted 6 lines

index b5e96b3a25..715bd3f7eb 100644

package/openssh/sshd.service +0 -0
@@ -1,11 +1,20 @@
 [Unit]
 Description=OpenSSH server daemon

package/openssh/sshd.service line 10

Quoted 10 lines
package/openssh/sshd.service +4 -2
-After=syslog.target network.target auditd.service
+Documentation=man:sshd(8) man:sshd_config(5)
+After=network.target auditd.service
 
 
 [Service]
 ExecStartPre=/usr/bin/ssh-keygen -A
-ExecStart=/usr/sbin/sshd -D -e
+ExecStartPre=/usr/sbin/sshd -t
+ExecStart=/usr/sbin/sshd -D

You droped the -e, so you are logging to syslog However you droped the dependency on syslog.target earlier... (maybe it should be syslog.socket instead of .target, btw)

Quoted 8 lines
Quoted 8 lines

syslog.target is long long gone, and the syslog will be unconditionally available
https://www.freedesktop.org/wiki/Software/systemd/syslog/

Quoted 3 lines

how exactly do you want to log ? (I think logging to stdout is

better, it will be

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

redirected to the journal.

stdout is not really useful if syslog is supported.

i'd go the other way round

syslog is not really necessary if stdout is available, but it's a matter of taste :P so let's go your way.

Its more the point, that Openssh already implemented syslog, and thats a clear functional superset of listening to stdout.

Quoted 20 lines
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 7 lines

package/openssh/sshd.service line 12

Quoted 3 lines
package/openssh/sshd.service +2 -0
+ExecReload=/usr/sbin/sshd -t
 ExecReload=/bin/kill -HUP $MAINPID
+KillMode=process

Wouldn't mixed be better here ?
I'm not really sure what the use-case for procss is anyway...

Quoted 4 lines

I taken that from debian, I could not argue against it (there is a long discussion which I linked above).
Can you argue *for* mixed?

Quoted 3 lines

I didn't see any link
* process : SIGTERM and SIGKILL is sent only to MainPID
* mixed : SIGTERM is sent to MainPID, SIGKILL is sent to every process

in the service cgroup.

Quoted 4 lines

This means that if all works well, they do the same thing

in case the MainPID fails to properly terminate its children, process

would leave children alive

Quoted 3 lines

but mixed woul kill everybody

Since we are trying to terminate the service, it makes sense to me to

make sur all child process

Quoted 10 lines
Quoted 3 lines

are killed.

but I don't see your link so I may be missing something

The link is in the added patch: https://bugs.debian.org/778913

As said, I could not argue either way, but I got some respect for the debian guys ;)

The thread does not actually discuss process vs mixed...

so doesn't really help here.
OTOH, the debian version has been vetted by mbiel which is a systemc core-maintainer.

so i would go with mixed if I were to write the service from scratch, but since I don't have an
explanation for the choice of process, I'm not entirely sure...

A possibility is that ssh creates a process per connection. in that case
* process would not kill all ongoing connections
* mixed would

maybe it was chosen to protect existing connection. that would make some sense.

Quoted 2 lines

Norbert

Signature · 21 lines
[image: SMILE]  <http://www.smile.eu/>

20 rue des Jardins
92600 Asni?res-sur-Seine
*J?r?my ROSEN*
Architecte technique

[image: email] jeremy.rosen at smile.fr
[image: phone]  +33 6 88 25 87 42
[image: url] http://www.smile.eu

[image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
<https://www.facebook.com/smileopensource> [image: LinkedIn]
<https://www.linkedin.com/company/smile> [image: Github]
<https://github.com/Smile-SA>

[image: D?couvrez l?univers Smile, rendez-vous sur smile.eu]
<https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20200607/119b2c8e/attachment.html>
#8 lore raw

PATCH 2/4 package/openssh: improve integration for systemd

Am So., 7. Juni 2020 um 21:42 Uhr schrieb J?r?my ROSEN <[email protected]>:

Quoted 282 lines

Le dim. 7 juin 2020 ? 21:24, Norbert Lange <[email protected]> a ?crit :

Quoted 265 lines

Am So., 7. Juni 2020 um 21:16 Uhr schrieb J?r?my ROSEN <[email protected]>:

Quoted 221 lines

Le dim. 7 juin 2020 ? 21:03, Norbert Lange <[email protected]> a ?crit :

Quoted 152 lines

Am So., 7. Juni 2020 um 12:54 Uhr schrieb J?r?my ROSEN <[email protected]>:

Quoted 133 lines

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a ?crit :

Quoted 129 lines

the openssh daemon is not suited for systemd's simple service type. dependend services should only start when sshd is ready to accept connections.

A patch is added from debian to allow openssh
to communicate this state.

Restarts are prevented if the reason is a faulty
config file (errocode 255).

The "user confinement directory" is changed to '/run/sshd' which is automatically managed by systemd.

---
 package/openssh/00-systemd-readiness.patch | 84 ++++++++++++++++++++++
 package/openssh/openssh.mk                 | 14 +++-
 package/openssh/sshd-sysusers.conf         |  2 +-
 package/openssh/sshd.service               | 13 +++-
 4 files changed, 109 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/00-systemd-readiness.patch
package/openssh/00-systemd-readiness.patch new file +84 -0
new file mode 100644
index 0000000000..be3b6b0074
@@ -0,0 +1,84 @@
+From ab765b2bd55062a704f09da8f8c1c4ad1d6630a7 Mon Sep 17 00:00:00 2001
+From: Michael Biebl <[email protected]>
+Date: Mon, 21 Dec 2015 16:08:47 +0000
+Subject: Add systemd readiness notification support
+
+Bug-Debian: https://bugs.debian.org/778913
+Forwarded: no
+Last-Update: 2017-08-22
+
+Patch-Name: systemd-readiness.patch
+---
+ configure.ac | 24 ++++++++++++++++++++++++
+ sshd.c       |  9 +++++++++
+ 2 files changed, 33 insertions(+)
+
+diff --git a/configure.ac b/configure.ac
+index e894db9fc..c119d6fd1 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -4499,6 +4499,29 @@ AC_ARG_WITH([kerberos5],
+ AC_SUBST([GSSLIBS])
+ AC_SUBST([K5LIBS])
+
++# Check whether user wants systemd support
++SYSTEMD_MSG="no"
++AC_ARG_WITH(systemd,
++      [  --with-systemd          Enable systemd support],
++      [ if test "x$withval" != "xno" ; then
++              AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
++              if test "$PKGCONFIG" != "no"; then
++                      AC_MSG_CHECKING([for libsystemd])
++                      if $PKGCONFIG --exists libsystemd; then
++                              SYSTEMD_CFLAGS=`$PKGCONFIG --cflags libsystemd`
++                              SYSTEMD_LIBS=`$PKGCONFIG --libs libsystemd`
++                              CPPFLAGS="$CPPFLAGS $SYSTEMD_CFLAGS"
++                              SSHDLIBS="$SSHDLIBS $SYSTEMD_LIBS"
++                              AC_MSG_RESULT([yes])
++                              AC_DEFINE(HAVE_SYSTEMD, 1, [Define if you want systemd support.])
++                              SYSTEMD_MSG="yes"
++                      else
++                              AC_MSG_RESULT([no])
++                      fi
++              fi
++      fi ]
++)
++
+ # Looking for programs, paths and files
+
+ PRIVSEP_PATH=/var/empty
+@@ -5305,6 +5328,7 @@ echo "                   libldns support: $LDNS_MSG"
+ echo "  Solaris process contract support: $SPC_MSG"
+ echo "           Solaris project support: $SP_MSG"
+ echo "         Solaris privilege support: $SPP_MSG"
++echo "                   systemd support: $SYSTEMD_MSG"
+ echo "       IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
+ echo "           Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
+ echo "                  BSD Auth support: $BSD_AUTH_MSG"
+diff --git a/sshd.c b/sshd.c
+index 4e8ff0662..5e7679a33 100644
+--- a/sshd.c
++++ b/sshd.c
+@@ -85,6 +85,10 @@
+ #include <prot.h>
+ #endif
+
++#ifdef HAVE_SYSTEMD
++#include <systemd/sd-daemon.h>
++#endif
++
+ #include "xmalloc.h"
+ #include "ssh.h"
+ #include "ssh2.h"
+@@ -1951,6 +1955,11 @@ main(int ac, char **av)
+                       }
+               }
+
++#ifdef HAVE_SYSTEMD
++              /* Signal systemd that we are ready to accept connections */
++              sd_notify(0, "READY=1");
++#endif
++
+               /* Accept a connection and return in a forked child */
+               server_accept_loop(&sock_in, &sock_out,
+                   &newsock, config_s);
package/openssh/openssh.mk +1 -0
index 55b917e20a..d425db1428 100644
@@ -12,6 +12,7 @@ OPENSSH_CONF_ENV = \
        LD="$(TARGET_CC)" \
        LDFLAGS="$(TARGET_CFLAGS)" \
        LIBS=`$(PKG_CONFIG_HOST_BINARY) --libs openssl`
+OPENSSH_AUTORECONF = YES
 OPENSSH_CONF_OPTS = \
        --sysconfdir=/etc/ssh \
        --with-default-path=$(BR2_SYSTEM_DEFAULT_PATH) \
@@ -22,9 +23,20 @@ OPENSSH_CONF_OPTS = \
        --disable-wtmpx \
        --disable-strip
 
Quoted 16 lines

package/openssh/openssh.mk OPENSSH_CONF_OPTS = \ · line 38

Quoted 13 lines
package/openssh/openssh.mk +10 -0
+ifeq ($(BR2_PACKAGE_SYSTEMD),y)
+OPENSSH_DEPENDENCIES = systemd
+
+OPENSSH_CONF_OPTS += \
+       --with-privsep-path=/run/sshd \
+       --with-pid-dir=/run \
+       --with-systemd
+
+else
+
 define OPENSSH_PERMISSIONS
        /var/empty d 755 root root - - - - -
 endef

Do we still need this when using systemd, or can it be commented out ?

Quoted 4 lines

Not sure what you mean with "this"?
The OPENSSH_PERMISSIONS block is needed when not using systemd and it is only active then.

my bad, I missed the enclosing ifeq()

Quoted 58 lines
Quoted 36 lines
Quoted 36 lines
package/openssh/openssh.mk +2 -1
+endif
 
 ifeq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),)
 OPENSSH_CONF_OPTS += --without-pie
@@ -72,7 +84,7 @@ define OPENSSH_INSTALL_SYSTEMD_SYSUSERS
 endef
 else
 define OPENSSH_USERS
-       sshd -1 sshd -1 * /var/empty - - SSH drop priv user
+       sshd -1 sshd -1 * $(if $(BR2_PACKAGE_SYSTEMD),/run/sshd,/var/empty) - - SSH drop priv user
 endef
 endif
 
package/openssh/sshd-sysusers.conf +1 -1
index ac77aec065..303d0dbb63 100644
@@ -1 +1 @@
-u sshd - "SSH drop priv user" /var/empty
+u sshd - "SSH drop priv user" /run/sshd
package/openssh/sshd.service +2 -1
index b5e96b3a25..715bd3f7eb 100644
@@ -1,11 +1,20 @@
 [Unit]
 Description=OpenSSH server daemon
-After=syslog.target network.target auditd.service
+Documentation=man:sshd(8) man:sshd_config(5)
+After=network.target auditd.service
 
 
Quoted 9 lines

package/openssh/sshd.service line 9

Quoted 5 lines
package/openssh/sshd.service +2 -1
 [Service]
 ExecStartPre=/usr/bin/ssh-keygen -A
-ExecStart=/usr/sbin/sshd -D -e
+ExecStartPre=/usr/sbin/sshd -t
+ExecStart=/usr/sbin/sshd -D

You droped the -e, so you are logging to syslog However you droped the dependency on syslog.target earlier... (maybe it should be syslog.socket instead of .target, btw)

syslog.target is long long gone, and the syslog will be unconditionally available
https://www.freedesktop.org/wiki/Software/systemd/syslog/

Quoted 4 lines

how exactly do you want to log ? (I think logging to stdout is better, it will be redirected to the journal.

Quoted 6 lines
Quoted 2 lines

stdout is not really useful if syslog is supported.

i'd go the other way round

syslog is not really necessary if stdout is available, but it's a matter of taste :P so let's go your way.

Its more the point, that Openssh already implemented syslog, and thats a clear functional superset of listening to stdout.

Quoted 32 lines
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 7 lines

package/openssh/sshd.service line 12

Quoted 3 lines
package/openssh/sshd.service +2 -0
+ExecReload=/usr/sbin/sshd -t
 ExecReload=/bin/kill -HUP $MAINPID
+KillMode=process

Wouldn't mixed be better here ?
I'm not really sure what the use-case for procss is anyway...

Quoted 4 lines

I taken that from debian, I could not argue against it (there is a long discussion which I linked above).
Can you argue *for* mixed?

I didn't see any link
* process : SIGTERM and SIGKILL is sent only to MainPID
* mixed : SIGTERM is sent to MainPID, SIGKILL is sent to every process in the service cgroup.

This means that if all works well, they do the same thing

in case the MainPID fails to properly terminate its children, process would leave children alive but mixed woul kill everybody

Since we are trying to terminate the service, it makes sense to me to make sur all child process are killed.

Quoted 7 lines
Quoted 1 line

but I don't see your link so I may be missing something

The link is in the added patch: https://bugs.debian.org/778913

As said, I could not argue either way, but I got some respect for the debian guys ;)

The thread does not actually discuss process vs mixed...

so doesn't really help here.
OTOH, the debian version has been vetted by mbiel which is a systemc core-maintainer.

Quoted 8 lines

so i would go with mixed if I were to write the service from scratch, but since I don't have an explanation for the choice of process, I'm not entirely sure...

A possibility is that ssh creates a process per connection. in that case
* process would not kill all ongoing connections
* mixed would

maybe it was chosen to protect existing connection. that would make some sense.

Well, debian and arch seem to agree on using "process", I guess it means to just prevent
new connections and not kill existing ones?

Can I get a "reviewed-by" for this patch, so this and #3 can be merged?

Norbert

#9 lore raw

PATCH 2/4 package/openssh: improve integration for systemd

sure

Reviewed-by J?r?my Rosen <[email protected]>

Sorry for noticing that everything was adressed

Le jeu. 11 juin 2020 ? 02:04, Norbert Lange <[email protected]> a ?crit :

Quoted 328 lines

Am So., 7. Juni 2020 um 21:42 Uhr schrieb J?r?my ROSEN < jeremy.rosen at smile.fr>:

Quoted 4 lines

Le dim. 7 juin 2020 ? 21:24, Norbert Lange <[email protected]> a

?crit :

Quoted 2 lines
Quoted 2 lines

Am So., 7. Juni 2020 um 21:16 Uhr schrieb J?r?my ROSEN <

jeremy.rosen at smile.fr>:

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Le dim. 7 juin 2020 ? 21:03, Norbert Lange <[email protected]> a

?crit :

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Am So., 7. Juni 2020 um 12:54 Uhr schrieb J?r?my ROSEN <

jeremy.rosen at smile.fr>:

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]>

a ?crit :

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

the openssh daemon is not suited for systemd's simple service type. dependend services should only start when sshd is ready to accept connections.

A patch is added from debian to allow openssh to communicate this state.

Restarts are prevented if the reason is a faulty config file (errocode 255).

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The "user confinement directory" is changed to '/run/sshd' which is automatically managed by systemd.

---
 package/openssh/00-systemd-readiness.patch | 84

++++++++++++++++++++++

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Review

Quoted 7 lines
 package/openssh/openssh.mk                 | 14 +++-
 package/openssh/sshd-sysusers.conf         |  2 +-
 package/openssh/sshd.service               | 13 +++-
 4 files changed, 109 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/00-systemd-readiness.patch
(quoted diff) +0 -0

b/package/openssh/00-systemd-readiness.patch

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

package/openssh/00-systemd-readiness.patch line 1

Quoted 6 lines

new file mode 100644
index 0000000000..be3b6b0074

package/openssh/00-systemd-readiness.patch new file +1 -0
@@ -0,0 +1,84 @@
+From ab765b2bd55062a704f09da8f8c1c4ad1d6630a7 Mon Sep 17

00:00:00 2001

Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
package/openssh/00-systemd-readiness.patch new file +24 -0
+From: Michael Biebl <[email protected]>
+Date: Mon, 21 Dec 2015 16:08:47 +0000
+Subject: Add systemd readiness notification support
+
+Bug-Debian: https://bugs.debian.org/778913
+Forwarded: no
+Last-Update: 2017-08-22
+
+Patch-Name: systemd-readiness.patch
+---
+ configure.ac | 24 ++++++++++++++++++++++++
+ sshd.c       |  9 +++++++++
+ 2 files changed, 33 insertions(+)
+
+diff --git a/configure.ac b/configure.ac
+index e894db9fc..c119d6fd1 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -4499,6 +4499,29 @@ AC_ARG_WITH([kerberos5],
+ AC_SUBST([GSSLIBS])
+ AC_SUBST([K5LIBS])
+
++# Check whether user wants systemd support
++SYSTEMD_MSG="no"
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

package/openssh/00-systemd-readiness.patch line 33

Quoted 8 lines
package/openssh/00-systemd-readiness.patch new file +8 -0
++AC_ARG_WITH(systemd,
++      [  --with-systemd          Enable systemd support],
++      [ if test "x$withval" != "xno" ; then
++              AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
++              if test "$PKGCONFIG" != "no"; then
++                      AC_MSG_CHECKING([for libsystemd])
++                      if $PKGCONFIG --exists libsystemd; then
++                              SYSTEMD_CFLAGS=`$PKGCONFIG

--cflags libsystemd`

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

package/openssh/00-systemd-readiness.patch line 34

Quoted 1 line
package/openssh/00-systemd-readiness.patch new file +1 -0
++                              SYSTEMD_LIBS=`$PKGCONFIG --libs

libsystemd`

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

package/openssh/00-systemd-readiness.patch line 35

Quoted 1 line
package/openssh/00-systemd-readiness.patch new file +1 -0
++                              CPPFLAGS="$CPPFLAGS

$SYSTEMD_CFLAGS"

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

package/openssh/00-systemd-readiness.patch line 38

Quoted 3 lines
package/openssh/00-systemd-readiness.patch new file +3 -0
++                              SSHDLIBS="$SSHDLIBS $SYSTEMD_LIBS"
++                              AC_MSG_RESULT([yes])
++                              AC_DEFINE(HAVE_SYSTEMD, 1,

[Define if you want systemd support.])

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
package/openssh/00-systemd-readiness.patch new file +4 -0
++                              SYSTEMD_MSG="yes"
++                      else
++                              AC_MSG_RESULT([no])
++                      fi
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

package/openssh/00-systemd-readiness.patch line 50

Quoted 8 lines
package/openssh/00-systemd-readiness.patch new file +8 -0
++              fi
++      fi ]
++)
++
+ # Looking for programs, paths and files
+
+ PRIVSEP_PATH=/var/empty
+@@ -5305,6 +5328,7 @@ echo "                   libldns support:

$LDNS_MSG"

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
package/openssh/00-systemd-readiness.patch new file +20 -0
+ echo "  Solaris process contract support: $SPC_MSG"
+ echo "           Solaris project support: $SP_MSG"
+ echo "         Solaris privilege support: $SPP_MSG"
++echo "                   systemd support: $SYSTEMD_MSG"
+ echo "       IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
+ echo "           Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
+ echo "                  BSD Auth support: $BSD_AUTH_MSG"
+diff --git a/sshd.c b/sshd.c
+index 4e8ff0662..5e7679a33 100644
+--- a/sshd.c
++++ b/sshd.c
+@@ -85,6 +85,10 @@
+ #include <prot.h>
+ #endif
+
++#ifdef HAVE_SYSTEMD
++#include <systemd/sd-daemon.h>
++#endif
++
+ #include "xmalloc.h"
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

package/openssh/00-systemd-readiness.patch line 78

Quoted 8 lines
package/openssh/00-systemd-readiness.patch new file +8 -0
+ #include "ssh.h"
+ #include "ssh2.h"
+@@ -1951,6 +1955,11 @@ main(int ac, char **av)
+                       }
+               }
+
++#ifdef HAVE_SYSTEMD
++              /* Signal systemd that we are ready to accept

connections */

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

package/openssh/00-systemd-readiness.patch line 82

Quoted 4 lines
package/openssh/00-systemd-readiness.patch new file +4 -0
++              sd_notify(0, "READY=1");
++#endif
++
+               /* Accept a connection and return in a forked

child */

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

package/openssh/

Quoted 3 lines
package/openssh/00-systemd-readiness.patch new file +2 -0
+               server_accept_loop(&sock_in, &sock_out,
+                   &newsock, config_s);
package/openssh/ renamed from package/openssh/openssh.mk +0 -0

openssh.mk

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

index 55b917e20a..d425db1428 100644

package/openssh/openssh.mk +1 -0
@@ -12,6 +12,7 @@ OPENSSH_CONF_ENV = \
        LD="$(TARGET_CC)" \
        LDFLAGS="$(TARGET_CFLAGS)" \
        LIBS=`$(PKG_CONFIG_HOST_BINARY) --libs openssl`
+OPENSSH_AUTORECONF = YES
 OPENSSH_CONF_OPTS = \
        --sysconfdir=/etc/ssh \
        --with-default-path=$(BR2_SYSTEM_DEFAULT_PATH) \
@@ -22,9 +23,20 @@ OPENSSH_CONF_OPTS = \
        --disable-wtmpx \
        --disable-strip
 
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
package/openssh/openssh.mk +8 -0
+ifeq ($(BR2_PACKAGE_SYSTEMD),y)
+OPENSSH_DEPENDENCIES = systemd
+
+OPENSSH_CONF_OPTS += \
+       --with-privsep-path=/run/sshd \
+       --with-pid-dir=/run \
+       --with-systemd
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

package/openssh/openssh.mk OPENSSH_CONF_OPTS = \ · line 38

Quoted 5 lines
package/openssh/openssh.mk +2 -0
+else
+
 define OPENSSH_PERMISSIONS
        /var/empty d 755 root root - - - - -
 endef

Do we still need this when using systemd, or can it be commented

out ?

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 5 lines

Not sure what you mean with "this"?
The OPENSSH_PERMISSIONS block is needed when not using systemd and it is only active then.

my bad, I missed the enclosing ifeq()

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
package/openssh/openssh.mk +1 -0
+endif
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

package/openssh/openssh.mk define OPENSSH_INSTALL_SYSTEMD_SYSUSERS · line 87

Quoted 8 lines
package/openssh/openssh.mk +1 -1
 ifeq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),)
 OPENSSH_CONF_OPTS += --without-pie
@@ -72,7 +84,7 @@ define OPENSSH_INSTALL_SYSTEMD_SYSUSERS
 endef
 else
 define OPENSSH_USERS
-       sshd -1 sshd -1 * /var/empty - - SSH drop priv user
+       sshd -1 sshd -1 * $(if

$(BR2_PACKAGE_SYSTEMD),/run/sshd,/var/empty) - - SSH drop priv user

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Review

Quoted 4 lines
package/openssh/openssh.mk +0 -0
 endef
 endif
 
(quoted diff) +0 -0

b/package/openssh/sshd-sysusers.conf

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Review

Quoted 7 lines

index ac77aec065..303d0dbb63 100644

package/openssh/sshd-sysusers.conf +1 -1
@@ -1 +1 @@
-u sshd - "SSH drop priv user" /var/empty
+u sshd - "SSH drop priv user" /run/sshd
(quoted diff) +0 -0

b/package/openssh/sshd.service

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 20 lines
Quoted 6 lines

index b5e96b3a25..715bd3f7eb 100644

package/openssh/sshd.service +0 -0
@@ -1,11 +1,20 @@
 [Unit]
 Description=OpenSSH server daemon

package/openssh/sshd.service line 10

Quoted 10 lines
package/openssh/sshd.service +4 -2
-After=syslog.target network.target auditd.service
+Documentation=man:sshd(8) man:sshd_config(5)
+After=network.target auditd.service
 
 
 [Service]
 ExecStartPre=/usr/bin/ssh-keygen -A
-ExecStart=/usr/sbin/sshd -D -e
+ExecStartPre=/usr/sbin/sshd -t
+ExecStart=/usr/sbin/sshd -D

You droped the -e, so you are logging to syslog However you droped the dependency on syslog.target earlier... (maybe it should be syslog.socket instead of .target, btw)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

syslog.target is long long gone, and the syslog will be unconditionally available
https://www.freedesktop.org/wiki/Software/systemd/syslog/

Quoted 3 lines

how exactly do you want to log ? (I think logging to stdout is

better, it will be

Quoted 33 lines
Quoted 33 lines
Quoted 9 lines
Quoted 5 lines
Quoted 1 line

redirected to the journal.

stdout is not really useful if syslog is supported.

i'd go the other way round

syslog is not really necessary if stdout is available, but it's a matter of taste :P so let's go your way.

Its more the point, that Openssh already implemented syslog, and thats a clear functional superset of listening to stdout.

Quoted 20 lines
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Quoted 7 lines

package/openssh/sshd.service

Quoted 3 lines
package/openssh/sshd.service +2 -0
+ExecReload=/usr/sbin/sshd -t
 ExecReload=/bin/kill -HUP $MAINPID
+KillMode=process

Wouldn't mixed be better here ?
I'm not really sure what the use-case for procss is anyway...

I taken that from debian, I could not argue against it (there is a long discussion which I linked above).
Can you argue *for* mixed?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I didn't see any link
* process : SIGTERM and SIGKILL is sent only to MainPID
* mixed : SIGTERM is sent to MainPID, SIGKILL is sent to every

process in the service cgroup.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

This means that if all works well, they do the same thing

in case the MainPID fails to properly terminate its children, process

would leave children alive

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

but mixed woul kill everybody

Since we are trying to terminate the service, it makes sense to me to

make sur all child process

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

are killed.

but I don't see your link so I may be missing something

The link is in the added patch: https://bugs.debian.org/778913

Quoted 8 lines
Quoted 3 lines

As said, I could not argue either way, but I got some respect for the debian guys ;)

The thread does not actually discuss process vs mixed...

so doesn't really help here.
OTOH, the debian version has been vetted by mbiel which is a systemc

core-maintainer.

Quoted 2 lines

so i would go with mixed if I were to write the service from scratch,

but since I don't have an

Quoted 7 lines

explanation for the choice of process, I'm not entirely sure...

A possibility is that ssh creates a process per connection. in that case
* process would not kill all ongoing connections
* mixed would

maybe it was chosen to protect existing connection. that would make some

sense.

Well, debian and arch seem to agree on using "process", I guess it means to just prevent
new connections and not kill existing ones?

Can I get a "reviewed-by" for this patch, so this and #3 can be merged?

Norbert

Signature · 21 lines
[image: SMILE]  <http://www.smile.eu/>

20 rue des Jardins
92600 Asni?res-sur-Seine
*J?r?my ROSEN*
Architecte technique

[image: email] jeremy.rosen at smile.fr
[image: phone]  +33 6 88 25 87 42
[image: url] http://www.smile.eu

[image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
<https://www.facebook.com/smileopensource> [image: LinkedIn]
<https://www.linkedin.com/company/smile> [image: Github]
<https://github.com/Smile-SA>

[image: D?couvrez l?univers Smile, rendez-vous sur smile.eu]
<https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20200611/4fb1bac3/attachment.html>
#10 lore raw

PATCH 3/4 package/openssh: seperate sd service for host key generation

In reply to Norbert Lange

split out generationg of host keys into an optional service that can easily be removed or deactivated.

---
 package/openssh/openssh.mk               |  5 +++--
 package/openssh/sshd-host-keygen.service | 20 ++++++++++++++++++++
 package/openssh/sshd.service             |  1 -
 3 files changed, 23 insertions(+), 3 deletions(-)
 create mode 100644 package/openssh/sshd-host-keygen.service
package/openssh/openssh.mk +3 -2
index d425db1428..6b3ee1f5f4 100644
@@ -114,8 +114,9 @@ endef
 OPENSSH_POST_INSTALL_TARGET_HOOKS += OPENSSH_INSTALL_SERVER_PROGRAMS
 
 define OPENSSH_INSTALL_INIT_SYSTEMD
-	$(INSTALL) -D -m 644 package/openssh/sshd.service \
-		$(TARGET_DIR)/usr/lib/systemd/system/sshd.service
+	mkdir $(TARGET_DIR)/usr/lib/systemd/system
+	$(INSTALL) -m 644 package/openssh/sshd*.service \
+		$(TARGET_DIR)/usr/lib/systemd/system/
 	$(OPENSSH_INSTALL_SYSTEMD_SYSUSERS)
 endef
 
package/openssh/sshd-host-keygen.service new file +20 -0
new file mode 100644
index 0000000000..058e671c44
@@ -0,0 +1,20 @@
+[Unit]
+Description=SSH Key Generation
+Before=sshd.service
+
+ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key
+ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key.pub
+ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key
+ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key.pub
+ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key
+ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key.pub
+ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key
+ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key.pub
+
+[Service]
+ExecStart=/usr/bin/ssh-keygen -A
+Type=oneshot
+RemainAfterExit=yes
+
+[Install]
+WantedBy=sshd.service
package/openssh/sshd.service +0 -1
index 715bd3f7eb..797e249d8d 100644
@@ -4,7 +4,6 @@ Documentation=man:sshd(8) man:sshd_config(5)
 After=network.target auditd.service
 
 [Service]
-ExecStartPre=/usr/bin/ssh-keygen -A
 ExecStartPre=/usr/sbin/sshd -t
 ExecStart=/usr/sbin/sshd -D
 ExecReload=/usr/sbin/sshd -t
Signature · 1 line
2.26.2
#11 lore raw

PATCH 3/4 package/openssh: seperate sd service for host key generation

Why the RemainAfterExit ?
This is a "real oneshot", it doesn't need a state to stay behind. Moreover it would only stay behind when actually generating the key. in all followup boot the unit would not be started at all

Appart from that, Looks good to me...

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a ?crit :

Quoted 74 lines

split out generationg of host keys into an optional service that can easily be removed or deactivated.

---
 package/openssh/openssh.mk               |  5 +++--
 package/openssh/sshd-host-keygen.service | 20 ++++++++++++++++++++
 package/openssh/sshd.service             |  1 -
 3 files changed, 23 insertions(+), 3 deletions(-)
 create mode 100644 package/openssh/sshd-host-keygen.service
package/openssh/openssh.mk +3 -2
index d425db1428..6b3ee1f5f4 100644
@@ -114,8 +114,9 @@ endef
 OPENSSH_POST_INSTALL_TARGET_HOOKS += OPENSSH_INSTALL_SERVER_PROGRAMS
 
 define OPENSSH_INSTALL_INIT_SYSTEMD
-       $(INSTALL) -D -m 644 package/openssh/sshd.service \
-               $(TARGET_DIR)/usr/lib/systemd/system/sshd.service
+       mkdir $(TARGET_DIR)/usr/lib/systemd/system
+       $(INSTALL) -m 644 package/openssh/sshd*.service \
+               $(TARGET_DIR)/usr/lib/systemd/system/
        $(OPENSSH_INSTALL_SYSTEMD_SYSUSERS)
 endef
 
package/openssh/sshd-host-keygen.service new file +20 -0
new file mode 100644
index 0000000000..058e671c44
@@ -0,0 +1,20 @@
+[Unit]
+Description=SSH Key Generation
+Before=sshd.service
+
+ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key
+ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key.pub
+ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key
+ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key.pub
+ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key
+ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key.pub
+ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key
+ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key.pub
+
+[Service]
+ExecStart=/usr/bin/ssh-keygen -A
+Type=oneshot
+RemainAfterExit=yes
+
+[Install]
+WantedBy=sshd.service
package/openssh/sshd.service +0 -2
index 715bd3f7eb..797e249d8d 100644
@@ -4,7 +4,6 @@ Documentation=man:sshd(8) man:sshd_config(5)
 After=network.target auditd.service
 
 [Service]
-ExecStartPre=/usr/bin/ssh-keygen -A
 ExecStartPre=/usr/sbin/sshd -t
 ExecStart=/usr/sbin/sshd -D
 ExecReload=/usr/sbin/sshd -t
--

2.26.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

Signature · 21 lines
[image: SMILE]  <http://www.smile.eu/>

20 rue des Jardins
92600 Asni?res-sur-Seine
*J?r?my ROSEN*
Architecte technique

[image: email] jeremy.rosen at smile.fr
[image: phone]  +33 6 88 25 87 42
[image: url] http://www.smile.eu

[image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
<https://www.facebook.com/smileopensource> [image: LinkedIn]
<https://www.linkedin.com/company/smile> [image: Github]
<https://github.com/Smile-SA>

[image: D?couvrez l?univers Smile, rendez-vous sur smile.eu]
<https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20200607/cc602538/attachment.html>
#12 lore raw

PATCH 3/4 package/openssh: seperate sd service for host key generation

Am So., 7. Juni 2020 um 12:44 Uhr schrieb J?r?my ROSEN <[email protected]>:

Quoted 4 lines

Why the RemainAfterExit ?
This is a "real oneshot", it doesn't need a state to stay behind.
Moreover it would only stay behind when actually generating the key. in all followup boot the unit would not be started at all

Yeah... there is some truth to that, but those one-shots have tricky sideeffects systemd 245 changed something that completely undermines my understanding of how they should work,
and make that flag practically a necessity. See:
https://github.com/systemd/systemd/issues/15091

I dont think I am able to correctly describe all pro's and cons but I added this flag after:

- later services did not care for failures
- starting/stopping *any* service will recheck the condition and
fill the syslog (* depends on other stuff aswell, but that's what happens for me)

In short: add RemainAfterExit for every one-shot, or there will be dragons. Doesn't seem upstream is bothered by this.

Quoted 95 lines

Appart from that, Looks good to me...

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a ?crit :

Quoted 69 lines

split out generationg of host keys into an optional service that can easily be removed or deactivated.

---
 package/openssh/openssh.mk               |  5 +++--
 package/openssh/sshd-host-keygen.service | 20 ++++++++++++++++++++
 package/openssh/sshd.service             |  1 -
 3 files changed, 23 insertions(+), 3 deletions(-)
 create mode 100644 package/openssh/sshd-host-keygen.service
package/openssh/openssh.mk +3 -2
index d425db1428..6b3ee1f5f4 100644
@@ -114,8 +114,9 @@ endef
 OPENSSH_POST_INSTALL_TARGET_HOOKS += OPENSSH_INSTALL_SERVER_PROGRAMS
 
 define OPENSSH_INSTALL_INIT_SYSTEMD
-       $(INSTALL) -D -m 644 package/openssh/sshd.service \
-               $(TARGET_DIR)/usr/lib/systemd/system/sshd.service
+       mkdir $(TARGET_DIR)/usr/lib/systemd/system
+       $(INSTALL) -m 644 package/openssh/sshd*.service \
+               $(TARGET_DIR)/usr/lib/systemd/system/
        $(OPENSSH_INSTALL_SYSTEMD_SYSUSERS)
 endef
 
package/openssh/sshd-host-keygen.service new file +20 -0
new file mode 100644
index 0000000000..058e671c44
@@ -0,0 +1,20 @@
+[Unit]
+Description=SSH Key Generation
+Before=sshd.service
+
+ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key
+ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key.pub
+ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key
+ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key.pub
+ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key
+ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key.pub
+ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key
+ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key.pub
+
+[Service]
+ExecStart=/usr/bin/ssh-keygen -A
+Type=oneshot
+RemainAfterExit=yes
+
+[Install]
+WantedBy=sshd.service
package/openssh/sshd.service +0 -2
index 715bd3f7eb..797e249d8d 100644
@@ -4,7 +4,6 @@ Documentation=man:sshd(8) man:sshd_config(5)
 After=network.target auditd.service
 
 [Service]
-ExecStartPre=/usr/bin/ssh-keygen -A
 ExecStartPre=/usr/sbin/sshd -t
 ExecStart=/usr/sbin/sshd -D
 ExecReload=/usr/sbin/sshd -t
--

2.26.2

Quoted 4 lines

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

--

20 rue des Jardins
92600 Asni?res-sur-Seine

J?r?my ROSEN
Architecte technique

jeremy.rosen at smile.fr
+33 6 88 25 87 42
http://www.smile.eu

#13 lore raw

PATCH 3/4 package/openssh: seperate sd service for host key generation

Le dim. 7 juin 2020 ? 20:56, Norbert Lange <[email protected]> a ?crit :

Quoted 22 lines

Am So., 7. Juni 2020 um 12:44 Uhr schrieb J?r?my ROSEN < jeremy.rosen at smile.fr>:

Quoted 4 lines

Why the RemainAfterExit ?
This is a "real oneshot", it doesn't need a state to stay behind. Moreover it would only stay behind when actually generating the key. in

all followup boot the unit would not be started at all

Yeah... there is some truth to that, but those one-shots have tricky sideeffects systemd 245 changed something that completely undermines my understanding of how they should work,
and make that flag practically a necessity. See:
https://github.com/systemd/systemd/issues/15091

I dont think I am able to correctly describe all pro's and cons but I added this flag after:

(quoted diff) +0 -2
-   later services did not care for failures
-   starting/stopping *any* service will recheck the condition and

fill the syslog (* depends on other stuff aswell, but that's what happens for me)

Quoted 4 lines

In short: add RemainAfterExit for every one-shot, or there will be dragons. Doesn't seem upstream is bothered by this.

ok, I see your point... you are protected by your various Condition= from

this bug, but that would fill the logs with condition checks messages.

Could you please add a comment pointing to that bug report ?

Appart from that

Quoted 98 lines
Quoted 4 lines

Appart from that, Looks good to me...

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a

?crit :

Quoted 28 lines
Quoted 28 lines

split out generationg of host keys into an optional service that can easily be removed or deactivated.

---
 package/openssh/openssh.mk               |  5 +++--
 package/openssh/sshd-host-keygen.service | 20 ++++++++++++++++++++
 package/openssh/sshd.service             |  1 -
 3 files changed, 23 insertions(+), 3 deletions(-)
 create mode 100644 package/openssh/sshd-host-keygen.service
package/openssh/openssh.mk +3 -2
index d425db1428..6b3ee1f5f4 100644
@@ -114,8 +114,9 @@ endef
 OPENSSH_POST_INSTALL_TARGET_HOOKS += OPENSSH_INSTALL_SERVER_PROGRAMS
 
 define OPENSSH_INSTALL_INIT_SYSTEMD
-       $(INSTALL) -D -m 644 package/openssh/sshd.service \
-               $(TARGET_DIR)/usr/lib/systemd/system/sshd.service
+       mkdir $(TARGET_DIR)/usr/lib/systemd/system
+       $(INSTALL) -m 644 package/openssh/sshd*.service \
+               $(TARGET_DIR)/usr/lib/systemd/system/
        $(OPENSSH_INSTALL_SYSTEMD_SYSUSERS)
 endef
 
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/package/openssh/sshd-host-keygen.service

Quoted 62 lines
Quoted 40 lines

new file mode 100644
index 0000000000..058e671c44

package/openssh/sshd-host-keygen.service new file +20 -0
@@ -0,0 +1,20 @@
+[Unit]
+Description=SSH Key Generation
+Before=sshd.service
+
+ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key
+ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key.pub
+ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key
+ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key.pub
+ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key
+ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key.pub
+ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key
+ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key.pub
+
+[Service]
+ExecStart=/usr/bin/ssh-keygen -A
+Type=oneshot
+RemainAfterExit=yes
+
+[Install]
+WantedBy=sshd.service
package/openssh/sshd.service +0 -2
index 715bd3f7eb..797e249d8d 100644
@@ -4,7 +4,6 @@ Documentation=man:sshd(8) man:sshd_config(5)
 After=network.target auditd.service
 
 [Service]
-ExecStartPre=/usr/bin/ssh-keygen -A
 ExecStartPre=/usr/sbin/sshd -t
 ExecStart=/usr/sbin/sshd -D
 ExecReload=/usr/sbin/sshd -t
--

2.26.2

Quoted 4 lines

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

--

20 rue des Jardins
92600 Asni?res-sur-Seine

J?r?my ROSEN
Architecte technique

jeremy.rosen at smile.fr
+33 6 88 25 87 42
http://www.smile.eu

Signature · 21 lines
[image: SMILE]  <http://www.smile.eu/>

20 rue des Jardins
92600 Asni?res-sur-Seine
*J?r?my ROSEN*
Architecte technique

[image: email] jeremy.rosen at smile.fr
[image: phone]  +33 6 88 25 87 42
[image: url] http://www.smile.eu

[image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
<https://www.facebook.com/smileopensource> [image: LinkedIn]
<https://www.linkedin.com/company/smile> [image: Github]
<https://github.com/Smile-SA>

[image: D?couvrez l?univers Smile, rendez-vous sur smile.eu]
<https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20200607/68875fbe/attachment.html>
#14 lore raw

PATCH 4/4 package/openssh: add sd socket-activated ssh daemon services

In reply to Norbert Lange
---
 package/openssh/openssh.mk               |  6 +++---
 package/openssh/sshd-host-keygen.service |  2 +-
 package/openssh/sshd.socket              | 11 +++++++++++
 package/openssh/sshd at .service            | 10 ++++++++++
 4 files changed, 25 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/sshd.socket
 create mode 100644 package/openssh/sshd at .service
package/openssh/openssh.mk +3 -3
index 6b3ee1f5f4..1f2638e9c9 100644
@@ -114,9 +114,9 @@ endef
 OPENSSH_POST_INSTALL_TARGET_HOOKS += OPENSSH_INSTALL_SERVER_PROGRAMS
 
 define OPENSSH_INSTALL_INIT_SYSTEMD
-	mkdir $(TARGET_DIR)/usr/lib/systemd/system
-	$(INSTALL) -m 644 package/openssh/sshd*.service \
-		$(TARGET_DIR)/usr/lib/systemd/system/
+	mkdir -p $(TARGET_DIR)/usr/lib/systemd/system
+	$(INSTALL) -m 644 package/openssh/sshd*.service package/openssh/sshd.socket \
+		$(TARGET_DIR)/usr/lib/systemd/system/.
 	$(OPENSSH_INSTALL_SYSTEMD_SYSUSERS)
 endef
 
package/openssh/sshd-host-keygen.service +1 -1
index 058e671c44..ffde622b01 100644
@@ -17,4 +17,4 @@ Type=oneshot
 RemainAfterExit=yes
 
 [Install]
-WantedBy=sshd.service
+WantedBy=sshd.service sshd.socket
package/openssh/sshd.socket new file +11 -0
new file mode 100644
index 0000000000..bbae9ed7aa
@@ -0,0 +1,11 @@
+[Unit]
+Description=OpenBSD Secure Shell server socket
+Before=sshd.service
+Conflicts=sshd.service
+
+[Socket]
+ListenStream=22
+Accept=yes
+
+[Install]
+WantedBy=sockets.target
package/openssh/sshd at .service new file +10 -0
new file mode 100644
index 0000000000..b3a590d9a3
@@ -0,0 +1,10 @@
+[Unit]
+Description=OpenBSD Secure Shell server per-connection daemon
+Documentation=man:sshd(8) man:sshd_config(5)
+After=auditd.service
+
+[Service]
+ExecStart=-/usr/sbin/sshd -i
+StandardInput=socket
+RuntimeDirectory=sshd
+RuntimeDirectoryMode=0755
Signature · 1 line
2.26.2
#15 lore raw

PATCH 4/4 package/openssh: add sd socket-activated ssh daemon services

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a ?crit :

Quoted 46 lines
---
 package/openssh/openssh.mk               |  6 +++---
 package/openssh/sshd-host-keygen.service |  2 +-
 package/openssh/sshd.socket              | 11 +++++++++++
 package/openssh/sshd at .service            | 10 ++++++++++
 4 files changed, 25 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/sshd.socket
 create mode 100644 package/openssh/sshd at .service
package/openssh/openssh.mk +3 -3
index 6b3ee1f5f4..1f2638e9c9 100644
@@ -114,9 +114,9 @@ endef
 OPENSSH_POST_INSTALL_TARGET_HOOKS += OPENSSH_INSTALL_SERVER_PROGRAMS
 
 define OPENSSH_INSTALL_INIT_SYSTEMD
-       mkdir $(TARGET_DIR)/usr/lib/systemd/system
-       $(INSTALL) -m 644 package/openssh/sshd*.service \
-               $(TARGET_DIR)/usr/lib/systemd/system/
+       mkdir -p $(TARGET_DIR)/usr/lib/systemd/system
+       $(INSTALL) -m 644 package/openssh/sshd*.service
 package/openssh/sshd.socket \
+               $(TARGET_DIR)/usr/lib/systemd/system/.
        $(OPENSSH_INSTALL_SYSTEMD_SYSUSERS)
 endef
package/openssh/sshd-host-keygen.service +1 -1
index 058e671c44..ffde622b01 100644
@@ -17,4 +17,4 @@ Type=oneshot
 RemainAfterExit=yes
 
 [Install]
-WantedBy=sshd.service
+WantedBy=sshd.service sshd.socket
package/openssh/sshd.socket new file +0 -0
new file mode 100644
index 0000000000..bbae9ed7aa

package/openssh/sshd.socket line 4

Quoted 4 lines
package/openssh/sshd.socket new file +4 -0
@@ -0,0 +1,11 @@
+[Unit]
+Description=OpenBSD Secure Shell server socket
+Before=sshd.service
+Conflicts=sshd.service

No, that would stop the socket when the service is started, and you don't want that.
If you do that, only one connection would be accepted before the socket is stoped
and since you have accept=yes no further connections would be accepted

Quoted 14 lines
package/openssh/sshd.socket new file +7 -0
+
+[Socket]
+ListenStream=22
+Accept=yes
+
+[Install]
+WantedBy=sockets.target
package/openssh/sshd at .service new file +0 -0
new file mode 100644
index 0000000000..b3a590d9a3

package/openssh/sshd at .service line 10

Quoted 10 lines
package/openssh/sshd at .service new file +10 -0
@@ -0,0 +1,10 @@
+[Unit]
+Description=OpenBSD Secure Shell server per-connection daemon
+Documentation=man:sshd(8) man:sshd_config(5)
+After=auditd.service
+
+[Service]
+ExecStart=-/usr/sbin/sshd -i
+StandardInput=socket
+RuntimeDirectory=sshd
+RuntimeDirectoryMode=0755

I am a bit confused, you have both an ssh.service and a ssh.socket+ssh@ .service
Wouldn't those two fight over port 22 ?

Quoted 8 lines

--
2.26.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

Signature · 21 lines
[image: SMILE]  <http://www.smile.eu/>

20 rue des Jardins
92600 Asni?res-sur-Seine
*J?r?my ROSEN*
Architecte technique

[image: email] jeremy.rosen at smile.fr
[image: phone]  +33 6 88 25 87 42
[image: url] http://www.smile.eu

[image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
<https://www.facebook.com/smileopensource> [image: LinkedIn]
<https://www.linkedin.com/company/smile> [image: Github]
<https://github.com/Smile-SA>

[image: D?couvrez l?univers Smile, rendez-vous sur smile.eu]
<https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20200607/7c81434a/attachment.html>
#16 lore raw

PATCH 4/4 package/openssh: add sd socket-activated ssh daemon services

Am So., 7. Juni 2020 um 13:07 Uhr schrieb J?r?my ROSEN <[email protected]>:

Quoted 48 lines

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a ?crit :

Quoted 44 lines
---
 package/openssh/openssh.mk               |  6 +++---
 package/openssh/sshd-host-keygen.service |  2 +-
 package/openssh/sshd.socket              | 11 +++++++++++
 package/openssh/sshd at .service            | 10 ++++++++++
 4 files changed, 25 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/sshd.socket
 create mode 100644 package/openssh/sshd at .service
package/openssh/openssh.mk +3 -3
index 6b3ee1f5f4..1f2638e9c9 100644
@@ -114,9 +114,9 @@ endef
 OPENSSH_POST_INSTALL_TARGET_HOOKS += OPENSSH_INSTALL_SERVER_PROGRAMS
 
 define OPENSSH_INSTALL_INIT_SYSTEMD
-       mkdir $(TARGET_DIR)/usr/lib/systemd/system
-       $(INSTALL) -m 644 package/openssh/sshd*.service \
-               $(TARGET_DIR)/usr/lib/systemd/system/
+       mkdir -p $(TARGET_DIR)/usr/lib/systemd/system
+       $(INSTALL) -m 644 package/openssh/sshd*.service package/openssh/sshd.socket \
+               $(TARGET_DIR)/usr/lib/systemd/system/.
        $(OPENSSH_INSTALL_SYSTEMD_SYSUSERS)
 endef
 
package/openssh/sshd-host-keygen.service +1 -1
index 058e671c44..ffde622b01 100644
@@ -17,4 +17,4 @@ Type=oneshot
 RemainAfterExit=yes
 
 [Install]
-WantedBy=sshd.service
+WantedBy=sshd.service sshd.socket
package/openssh/sshd.socket new file +0 -0
new file mode 100644
index 0000000000..bbae9ed7aa
@@ -0,0 +1,11 @@
Quoted 8 lines

package/openssh/sshd.socket line 4

Quoted 4 lines
package/openssh/sshd.socket new file +4 -0
+[Unit]
+Description=OpenBSD Secure Shell server socket
+Before=sshd.service
+Conflicts=sshd.service

No, that would stop the socket when the service is started, and you don't want that. If you do that, only one connection would be accepted before the socket is stoped and since you have accept=yes no further connections would be accepted

there is the singular sshd service
and the sshd.socket which spawns sshd@ instance services. Those are mutually exclusive (because of the "Conflicts"), the "Before" line just ensures that the sshd.socket wins out by default.

Quoted 21 lines
Quoted 21 lines
package/openssh/sshd.socket new file +7 -0
+
+[Socket]
+ListenStream=22
+Accept=yes
+
+[Install]
+WantedBy=sockets.target
package/openssh/sshd at .service new file +6 -0
new file mode 100644
index 0000000000..b3a590d9a3
@@ -0,0 +1,10 @@
+[Unit]
+Description=OpenBSD Secure Shell server per-connection daemon
+Documentation=man:sshd(8) man:sshd_config(5)
+After=auditd.service
+
+[Service]
Quoted 8 lines

package/openssh/sshd at .service line 10

Quoted 4 lines
package/openssh/sshd at .service new file +4 -0
+ExecStart=-/usr/sbin/sshd -i
+StandardInput=socket
+RuntimeDirectory=sshd
+RuntimeDirectoryMode=0755

I am a bit confused, you have both an ssh.service and a ssh.socket+ssh at .service Wouldn't those two fight over port 22 ?

No, on a fresh installation, the socket will be started, the sshd service will not because of the "Conflicts".
if you manually enable/start the sshd.service then the socket will be shutdown first.

Quoted 20 lines
Quoted 11 lines

--
2.26.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

--

20 rue des Jardins
92600 Asni?res-sur-Seine

Quoted 6 lines

J?r?my ROSEN
Architecte technique

jeremy.rosen at smile.fr
+33 6 88 25 87 42
http://www.smile.eu

Norbert

#17 lore raw

PATCH 4/4 package/openssh: add sd socket-activated ssh daemon services

Le dim. 7 juin 2020 ? 21:11, Norbert Lange <[email protected]> a ?crit :

Quoted 60 lines

Am So., 7. Juni 2020 um 13:07 Uhr schrieb J?r?my ROSEN < jeremy.rosen at smile.fr>:

Quoted 4 lines

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a

?crit :

Quoted 18 lines
Quoted 18 lines
---
 package/openssh/openssh.mk               |  6 +++---
 package/openssh/sshd-host-keygen.service |  2 +-
 package/openssh/sshd.socket              | 11 +++++++++++
 package/openssh/sshd at .service            | 10 ++++++++++
 4 files changed, 25 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/sshd.socket
 create mode 100644 package/openssh/sshd at .service
package/openssh/openssh.mk +0 -0
index 6b3ee1f5f4..1f2638e9c9 100644
@@ -114,9 +114,9 @@ endef
 OPENSSH_POST_INSTALL_TARGET_HOOKS += OPENSSH_INSTALL_SERVER_PROGRAMS
 
Quoted 6 lines

package/openssh/openssh.mk endef

Quoted 6 lines
package/openssh/openssh.mk +2 -3
 define OPENSSH_INSTALL_INIT_SYSTEMD
-       mkdir $(TARGET_DIR)/usr/lib/systemd/system
-       $(INSTALL) -m 644 package/openssh/sshd*.service \
-               $(TARGET_DIR)/usr/lib/systemd/system/
+       mkdir -p $(TARGET_DIR)/usr/lib/systemd/system
+       $(INSTALL) -m 644 package/openssh/sshd*.service

package/openssh/sshd.socket \

Quoted 5 lines

Review

Quoted 5 lines
package/openssh/openssh.mk +1 -0
+               $(TARGET_DIR)/usr/lib/systemd/system/.
        $(OPENSSH_INSTALL_SYSTEMD_SYSUSERS)
 endef
 
(quoted diff) +0 -0

b/package/openssh/sshd-host-keygen.service

Quoted 6 lines
Quoted 6 lines

index 058e671c44..ffde622b01 100644

package/openssh/sshd-host-keygen.service +0 -0
@@ -17,4 +17,4 @@ Type=oneshot
 RemainAfterExit=yes
 
Quoted 15 lines

package/openssh/sshd.socket line 4

Quoted 13 lines
package/openssh/sshd-host-keygen.service +1 -1
 [Install]
-WantedBy=sshd.service
+WantedBy=sshd.service sshd.socket
package/openssh/sshd.socket new file +4 -0
new file mode 100644
index 0000000000..bbae9ed7aa
@@ -0,0 +1,11 @@
+[Unit]
+Description=OpenBSD Secure Shell server socket
+Before=sshd.service
+Conflicts=sshd.service

No, that would stop the socket when the service is started, and you

don't want that.

Quoted 10 lines
Quoted 1 line

If you do that, only one connection would be accepted before the socket

is stoped

Quoted 1 line

and since you have accept=yes no further connections would be accepted

there is the singular sshd service
and the sshd.socket which spawns sshd@ instance services. Those are mutually exclusive (because of the "Conflicts"), the "Before" line just ensures that the sshd.socket wins out by default.

aah right, I messed up sshd.service and sshd at .service in my head. my bad.

I personally think we shouldn't install both methods. either choose a distro-wide decision or provide a config option

Anyway, I see what you are doing now, and that should work, AFAICT.

I still think that it's cool that openssh supports all those startup methods,
but I'm not convinced we need to support all of them in BR.

Thoughts ?

Regards
Jeremy

Quoted 66 lines
Quoted 10 lines

package/openssh/sshd@

Quoted 10 lines
package/openssh/sshd.socket new file +7 -0
+
+[Socket]
+ListenStream=22
+Accept=yes
+
+[Install]
+WantedBy=sockets.target
package/openssh/sshd@ renamed from package/openssh/sshd at .service +0 -0

.service

Quoted 10 lines
Quoted 10 lines

new file mode 100644
index 0000000000..b3a590d9a3

package/openssh/sshd at .service new file +5 -0
@@ -0,0 +1,10 @@
+[Unit]
+Description=OpenBSD Secure Shell server per-connection daemon
+Documentation=man:sshd(8) man:sshd_config(5)
+After=auditd.service
+
Quoted 8 lines

package/openssh/sshd at .service line 10

Quoted 5 lines
package/openssh/sshd at .service new file +5 -0
+[Service]
+ExecStart=-/usr/sbin/sshd -i
+StandardInput=socket
+RuntimeDirectory=sshd
+RuntimeDirectoryMode=0755

I am a bit confused, you have both an ssh.service and a ssh.socket+ssh@

.service

Quoted 1 line

Wouldn't those two fight over port 22 ?

No, on a fresh installation, the socket will be started, the sshd service will not because of the "Conflicts".
if you manually enable/start the sshd.service then the socket will be shutdown first.

Quoted 20 lines
Quoted 11 lines

--
2.26.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

--

20 rue des Jardins
92600 Asni?res-sur-Seine

Quoted 6 lines

J?r?my ROSEN
Architecte technique

jeremy.rosen at smile.fr
+33 6 88 25 87 42
http://www.smile.eu

Norbert

Signature · 21 lines
[image: SMILE]  <http://www.smile.eu/>

20 rue des Jardins
92600 Asni?res-sur-Seine
*J?r?my ROSEN*
Architecte technique

[image: email] jeremy.rosen at smile.fr
[image: phone]  +33 6 88 25 87 42
[image: url] http://www.smile.eu

[image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
<https://www.facebook.com/smileopensource> [image: LinkedIn]
<https://www.linkedin.com/company/smile> [image: Github]
<https://github.com/Smile-SA>

[image: D?couvrez l?univers Smile, rendez-vous sur smile.eu]
<https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20200607/a3eff4e2/attachment.html>
#18 lore raw

PATCH 4/4 package/openssh: add sd socket-activated ssh daemon services

Am So., 7. Juni 2020 um 21:32 Uhr schrieb J?r?my ROSEN <[email protected]>:

Quoted 72 lines

Le dim. 7 juin 2020 ? 21:11, Norbert Lange <[email protected]> a ?crit :

Quoted 59 lines

Am So., 7. Juni 2020 um 13:07 Uhr schrieb J?r?my ROSEN <[email protected]>:

Quoted 48 lines

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a ?crit :

Quoted 44 lines
---
 package/openssh/openssh.mk               |  6 +++---
 package/openssh/sshd-host-keygen.service |  2 +-
 package/openssh/sshd.socket              | 11 +++++++++++
 package/openssh/sshd at .service            | 10 ++++++++++
 4 files changed, 25 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/sshd.socket
 create mode 100644 package/openssh/sshd at .service
package/openssh/openssh.mk +3 -3
index 6b3ee1f5f4..1f2638e9c9 100644
@@ -114,9 +114,9 @@ endef
 OPENSSH_POST_INSTALL_TARGET_HOOKS += OPENSSH_INSTALL_SERVER_PROGRAMS
 
 define OPENSSH_INSTALL_INIT_SYSTEMD
-       mkdir $(TARGET_DIR)/usr/lib/systemd/system
-       $(INSTALL) -m 644 package/openssh/sshd*.service \
-               $(TARGET_DIR)/usr/lib/systemd/system/
+       mkdir -p $(TARGET_DIR)/usr/lib/systemd/system
+       $(INSTALL) -m 644 package/openssh/sshd*.service package/openssh/sshd.socket \
+               $(TARGET_DIR)/usr/lib/systemd/system/.
        $(OPENSSH_INSTALL_SYSTEMD_SYSUSERS)
 endef
 
package/openssh/sshd-host-keygen.service +1 -1
index 058e671c44..ffde622b01 100644
@@ -17,4 +17,4 @@ Type=oneshot
 RemainAfterExit=yes
 
 [Install]
-WantedBy=sshd.service
+WantedBy=sshd.service sshd.socket
package/openssh/sshd.socket new file +0 -0
new file mode 100644
index 0000000000..bbae9ed7aa
@@ -0,0 +1,11 @@
Quoted 8 lines

package/openssh/sshd.socket line 4

Quoted 4 lines
package/openssh/sshd.socket new file +4 -0
+[Unit]
+Description=OpenBSD Secure Shell server socket
+Before=sshd.service
+Conflicts=sshd.service

No, that would stop the socket when the service is started, and you don't want that. If you do that, only one connection would be accepted before the socket is stoped and since you have accept=yes no further connections would be accepted

Quoted 5 lines

there is the singular sshd service
and the sshd.socket which spawns sshd@ instance services. Those are mutually exclusive (because of the "Conflicts"), the "Before" line just ensures that the sshd.socket wins out by default.

aah right, I messed up sshd.service and sshd at .service in my head. my bad.

Quoted 7 lines

I personally think we shouldn't install both methods. either choose a distro-wide decision or provide a config option

Anyway, I see what you are doing now, and that should work, AFAICT.

I still think that it's cool that openssh supports all those startup methods, but I'm not convinced we need to support all of them in BR.

sshd is better for throughput/efficiency if you have alot connections,

the socket option saves memory if you rarely have connections (and is actually a simpler service file).

I would support both, but let users pick.

Norbert

#19 lore raw

PATCH 4/4 package/openssh: add sd socket-activated ssh daemon services

Am So., 7. Juni 2020 um 21:45 Uhr schrieb Norbert Lange <[email protected]>:

Quoted 82 lines

Am So., 7. Juni 2020 um 21:32 Uhr schrieb J?r?my ROSEN <[email protected]>:

Quoted 72 lines

Le dim. 7 juin 2020 ? 21:11, Norbert Lange <[email protected]> a ?crit :

Quoted 59 lines

Am So., 7. Juni 2020 um 13:07 Uhr schrieb J?r?my ROSEN <[email protected]>:

Quoted 48 lines

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a ?crit :

Quoted 44 lines
---
 package/openssh/openssh.mk               |  6 +++---
 package/openssh/sshd-host-keygen.service |  2 +-
 package/openssh/sshd.socket              | 11 +++++++++++
 package/openssh/sshd at .service            | 10 ++++++++++
 4 files changed, 25 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/sshd.socket
 create mode 100644 package/openssh/sshd at .service
package/openssh/openssh.mk +3 -3
index 6b3ee1f5f4..1f2638e9c9 100644
@@ -114,9 +114,9 @@ endef
 OPENSSH_POST_INSTALL_TARGET_HOOKS += OPENSSH_INSTALL_SERVER_PROGRAMS
 
 define OPENSSH_INSTALL_INIT_SYSTEMD
-       mkdir $(TARGET_DIR)/usr/lib/systemd/system
-       $(INSTALL) -m 644 package/openssh/sshd*.service \
-               $(TARGET_DIR)/usr/lib/systemd/system/
+       mkdir -p $(TARGET_DIR)/usr/lib/systemd/system
+       $(INSTALL) -m 644 package/openssh/sshd*.service package/openssh/sshd.socket \
+               $(TARGET_DIR)/usr/lib/systemd/system/.
        $(OPENSSH_INSTALL_SYSTEMD_SYSUSERS)
 endef
 
package/openssh/sshd-host-keygen.service +1 -1
index 058e671c44..ffde622b01 100644
@@ -17,4 +17,4 @@ Type=oneshot
 RemainAfterExit=yes
 
 [Install]
-WantedBy=sshd.service
+WantedBy=sshd.service sshd.socket
package/openssh/sshd.socket new file +0 -0
new file mode 100644
index 0000000000..bbae9ed7aa
@@ -0,0 +1,11 @@
Quoted 8 lines

package/openssh/sshd.socket line 4

Quoted 4 lines
package/openssh/sshd.socket new file +4 -0
+[Unit]
+Description=OpenBSD Secure Shell server socket
+Before=sshd.service
+Conflicts=sshd.service

No, that would stop the socket when the service is started, and you don't want that. If you do that, only one connection would be accepted before the socket is stoped and since you have accept=yes no further connections would be accepted

Quoted 5 lines

there is the singular sshd service
and the sshd.socket which spawns sshd@ instance services. Those are mutually exclusive (because of the "Conflicts"), the "Before" line just ensures that the sshd.socket wins out by default.

aah right, I messed up sshd.service and sshd at .service in my head. my bad.

Quoted 7 lines

I personally think we shouldn't install both methods. either choose a distro-wide decision or provide a config option

Anyway, I see what you are doing now, and that should work, AFAICT.

I still think that it's cool that openssh supports all those startup methods, but I'm not convinced we need to support all of them in BR.

Quoted 8 lines

sshd is better for throughput/efficiency if you have alot connections,

the socket option saves memory if you rarely have connections (and is actually a simpler service file).

I would support both, but let users pick.

Norbert

How about this option:

config BR2_PACKAGE_OPENSSH_SERVER_SOCKET
bool "server socket"
depends on BR2_INIT_SYSTEMD
help
Systemd socket activation server.

makefile gonna get allota ifdefs, right now it's a bit naive anyway, as you could pick server and not key_utils and then the services (sys and systemd) would fail when trying to verify/generate the host keys.

Norbert

#20 lore raw

PATCH 4/4 package/openssh: add sd socket-activated ssh daemon services

Sounds good... the help text might need a little work, but I like the idea itself...

Le dim. 7 juin 2020 ? 23:30, Norbert Lange <[email protected]> a ?crit :

Quoted 120 lines

Am So., 7. Juni 2020 um 21:45 Uhr schrieb Norbert Lange < nolange79 at gmail.com>:

Quoted 2 lines

Am So., 7. Juni 2020 um 21:32 Uhr schrieb J?r?my ROSEN <

jeremy.rosen at smile.fr>:

Quoted 4 lines
Quoted 4 lines

Le dim. 7 juin 2020 ? 21:11, Norbert Lange <[email protected]> a

?crit :

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Am So., 7. Juni 2020 um 13:07 Uhr schrieb J?r?my ROSEN <

jeremy.rosen at smile.fr>:

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Le sam. 6 juin 2020 ? 00:59, Norbert Lange <[email protected]> a

?crit :

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
---
 package/openssh/openssh.mk               |  6 +++---
 package/openssh/sshd-host-keygen.service |  2 +-
 package/openssh/sshd.socket              | 11 +++++++++++
 package/openssh/sshd at .service            | 10 ++++++++++
 4 files changed, 25 insertions(+), 4 deletions(-)
 create mode 100644 package/openssh/sshd.socket
 create mode 100644 package/openssh/sshd at .service
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

package/openssh/

Quoted 1 line
package/openssh/ renamed from package/openssh/openssh.mk +0 -0

openssh.mk

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

package/openssh/openssh.mk endef · line 114

Quoted 5 lines

index 6b3ee1f5f4..1f2638e9c9 100644

package/openssh/openssh.mk +0 -0
@@ -114,9 +114,9 @@ endef
 OPENSSH_POST_INSTALL_TARGET_HOOKS +=

OPENSSH_INSTALL_SERVER_PROGRAMS

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

package/openssh/openssh.mk endef

Quoted 7 lines
package/openssh/openssh.mk +2 -3
 define OPENSSH_INSTALL_INIT_SYSTEMD
-       mkdir $(TARGET_DIR)/usr/lib/systemd/system
-       $(INSTALL) -m 644 package/openssh/sshd*.service \
-               $(TARGET_DIR)/usr/lib/systemd/system/
+       mkdir -p $(TARGET_DIR)/usr/lib/systemd/system
+       $(INSTALL) -m 644 package/openssh/sshd*.service

package/openssh/sshd.socket \

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 5 lines
package/openssh/openssh.mk +1 -0
+               $(TARGET_DIR)/usr/lib/systemd/system/.
        $(OPENSSH_INSTALL_SYSTEMD_SYSUSERS)
 endef
 
(quoted diff) +0 -0

b/package/openssh/sshd-host-keygen.service

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Review

Quoted 10 lines

index 058e671c44..ffde622b01 100644

package/openssh/sshd-host-keygen.service +1 -1
@@ -17,4 +17,4 @@ Type=oneshot
 RemainAfterExit=yes
 
 [Install]
-WantedBy=sshd.service
+WantedBy=sshd.service sshd.socket
(quoted diff) +0 -0

b/package/openssh/sshd.socket

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

package/openssh/sshd.socket line 4

Quoted 9 lines

new file mode 100644
index 0000000000..bbae9ed7aa

package/openssh/sshd.socket new file +4 -0
@@ -0,0 +1,11 @@
+[Unit]
+Description=OpenBSD Secure Shell server socket
+Before=sshd.service
+Conflicts=sshd.service

No, that would stop the socket when the service is started, and you

don't want that.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

If you do that, only one connection would be accepted before the

socket is stoped

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

and since you have accept=yes no further connections would be

accepted

Quoted 10 lines
Quoted 10 lines
Quoted 6 lines

there is the singular sshd service
and the sshd.socket which spawns sshd@ instance services. Those are mutually exclusive (because of the "Conflicts"), the "Before" line just ensures that the sshd.socket wins out by default.

aah right, I messed up sshd.service and sshd at .service in my head. my bad.

Quoted 6 lines
Quoted 6 lines

I personally think we shouldn't install both methods. either choose a distro-wide decision or provide a config option

Anyway, I see what you are doing now, and that should work, AFAICT.

I still think that it's cool that openssh supports all those startup

methods,

Quoted 10 lines
Quoted 1 line

but I'm not convinced we need to support all of them in BR.

sshd is better for throughput/efficiency if you have alot connections,

the socket option saves memory if you rarely have connections (and is actually a simpler service file).

I would support both, but let users pick.

Norbert

How about this option:

config BR2_PACKAGE_OPENSSH_SERVER_SOCKET
bool "server socket"
depends on BR2_INIT_SYSTEMD
help
Systemd socket activation server.

makefile gonna get allota ifdefs, right now it's a bit naive anyway, as you could pick server and not key_utils and then the services (sys and systemd) would fail when trying to verify/generate the host keys.

Norbert

Signature · 21 lines
[image: SMILE]  <http://www.smile.eu/>

20 rue des Jardins
92600 Asni?res-sur-Seine
*J?r?my ROSEN*
Architecte technique

[image: email] jeremy.rosen at smile.fr
[image: phone]  +33 6 88 25 87 42
[image: url] http://www.smile.eu

[image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
<https://www.facebook.com/smileopensource> [image: LinkedIn]
<https://www.linkedin.com/company/smile> [image: Github]
<https://github.com/Smile-SA>

[image: D?couvrez l?univers Smile, rendez-vous sur smile.eu]
<https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20200607/b76f928e/attachment.html>
#21 lore raw

PATCH 1/4 package/openssh: Depend on libaudit if available

In reply to Norbert Lange
Quoted 10 lines · On Sat, 6 Jun 2020 00:59:01 +0200 Norbert Lange <[email protected]> wrote:
---
 package/openssh/openssh.mk | 5 +++++
 1 file changed, 5 insertions(+)
package/openssh/openssh.mk +0 -0
index 515eec2c03..55b917e20a 100644

package/openssh/openssh.mk else · line 45

Quoted 7 lines
package/openssh/openssh.mk +4 -0
@@ -39,6 +39,11 @@ else
 OPENSSH_CONF_OPTS += --without-ssl-engine
 endif
 
+ifeq ($(BR2_PACKAGE_AUDIT),y)
+OPENSSH_DEPENDENCIES += audit
+OPENSSH_CONF_OPTS += --with-audit=linux
+endif

We like to have an "else" clause that explicitly disables the feature, so I've added that, reworked the commit title, and applied. Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com