ssh-generator: introduce ssh-access.target
This new passive target is supposed to be pulled in by SSH implementations and should be reached when remote SSH access is possible. The idea is that this target can be used as indicator for other components to determine if and when SSH access is possible. One specific usecase for this is the new sd_notify() logic in PID 1 that sends its own supervisor notifications whenever target units are reached. This can be used to precisely schedule SSH connections from host to VM/container, or just to identify systems where SSH is even available.
This commit is contained in:
@@ -128,7 +128,8 @@ static int write_socket_unit(
|
||||
const char *dest,
|
||||
const char *unit,
|
||||
const char *listen_stream,
|
||||
const char *comment) {
|
||||
const char *comment,
|
||||
bool with_ssh_access_target_dependency) {
|
||||
|
||||
int r;
|
||||
|
||||
@@ -149,13 +150,21 @@ static int write_socket_unit(
|
||||
fprintf(f,
|
||||
"[Unit]\n"
|
||||
"Description=OpenSSH Server Socket (systemd-ssh-generator, %s)\n"
|
||||
"Documentation=man:systemd-ssh-generator(8)\n"
|
||||
"Documentation=man:systemd-ssh-generator(8)\n",
|
||||
comment);
|
||||
|
||||
/* When this is a remotely accessible socket let's mark this with a milestone: ssh-access.target */
|
||||
if (with_ssh_access_target_dependency)
|
||||
fputs("Wants=ssh-access.target\n"
|
||||
"Before=ssh-access.target\n",
|
||||
f);
|
||||
|
||||
fprintf(f,
|
||||
"\n[Socket]\n"
|
||||
"ListenStream=%s\n"
|
||||
"Accept=yes\n"
|
||||
"PollLimitIntervalSec=30s\n"
|
||||
"PollLimitBurst=50\n",
|
||||
comment,
|
||||
listen_stream);
|
||||
|
||||
r = fflush_and_check(f);
|
||||
@@ -230,7 +239,8 @@ static int add_vsock_socket(
|
||||
dest,
|
||||
"sshd-vsock.socket",
|
||||
"vsock::22",
|
||||
"AF_VSOCK");
|
||||
"AF_VSOCK",
|
||||
/* with_ssh_access_target_dependency= */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -264,7 +274,8 @@ static int add_local_unix_socket(
|
||||
dest,
|
||||
"sshd-unix-local.socket",
|
||||
"/run/ssh-unix-local/socket",
|
||||
"AF_UNIX Local");
|
||||
"AF_UNIX Local",
|
||||
/* with_ssh_access_target_dependency= */ false);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -320,7 +331,8 @@ static int add_export_unix_socket(
|
||||
dest,
|
||||
"sshd-unix-export.socket",
|
||||
"/run/host/unix-export/ssh",
|
||||
"AF_UNIX Export");
|
||||
"AF_UNIX Export",
|
||||
/* with_ssh_access_target_dependency= */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -370,7 +382,8 @@ static int add_extra_sockets(
|
||||
dest,
|
||||
socket ?: "sshd-extra.socket",
|
||||
*i,
|
||||
*i);
|
||||
*i,
|
||||
/* with_ssh_access_target_dependency= */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user