Skip to content

Commit

Permalink
issuegen: split out if_snippets_gen, add path unit
Browse files Browse the repository at this point in the history
Split out `if_snippets_gen` from the `issuegen` script. This makes
the udev rule `90-console-login-helper-messages-if_snippets_gen.rules`
responsible only for writing snippets with information about network
interfaces to the runtime issue snippets directory
(`/run/console-login-helper-messages/issue.d`) read by `issuegen`
to generate the final `/run/console-login-helper-messages/40_console-login-helper-messages.issue`
file read by the serial terminal (agetty). This is beneficial as
it helps avoid situations where multiple invocations of `issuegen`
are executed concurrently (leading to bugs like coreos#35). This is also
a first step towards making the shown information more configurable
(coreos#15). Also preparation for coreos#7, which will involve making the
`issuegen` script more configurable by accepting a `--legacy` flag
(coreos#7 (comment)),
by reducing the number places in the code that the `issuegen`
function is called (so less downstream patching to pass in a
`--legacy` flag required).

Add `console-login-helper-messages.path`, so that `issuegen` is run
whenever snippets are written to `/run/console-login-helper-messages/issue.d`.
This should be the main way of triggering a run of `issuegen` (first
trigger the path, which starts the service, which will run
`issuegen`). The only other time the `issuegen` service is invoked
is on boot (if the unit is enabled). Note, enablement of the path
unit is required upon installation.
  • Loading branch information
Robert Fairley committed Apr 20, 2020
1 parent 1d55d81 commit 54d38db
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Monitor console-login-helper-messages runtime issue snippets directory for changes

[Path]
PathChanged=/run/console-login-helper-messages/issue.d
Unit=console-login-helper-messages-issuegen.service

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
[Unit]
Description=Generate /run/issue.d/console-login-helper-messages.issue
Description=Generate console-login-helper-messages issue snippet
Before=systemd-user-sessions.service
Wants=network-online.target
After=network-online.target sshd-keygen.target

# The issue file generated by `issuegen` shown at the serial console should be
# kept up to date, no matter the number of successive start requests within a
# given time interval. However, it is unlikely that the configured defaults on
# a system for start request rate limiting of this unit (through
# StartLimitIntervalSec= and StartLimitBurst=) would be exceeded. For example,
# typical scenarios causing this service to be started would be through the
# udev rule `90-console-login-helper-messages-if_snippets_gen`, which are
# likely to involve low numbers of start requests (one for every time a network
# device is connected or disconnected). This unit therefore does not set any
# rate-limiting parameters. However, if this unit is often failing with
# `start-limit-hit`, try disabling rate limiting for this unit by uncommenting
# the following:
#StartLimitIntervalSec=0

[Service]
Type=oneshot
RemainAfterExit=yes
# This service expects to be started repeatedly after exiting (whenever a new
# runtime issue snippet is dropped into the directory watched by
# `console-login-helper-messages-issuegen.path`). `RemainAfterExit` is thus
# explicitly set to `no`, so that the service can re-execute (otherwise,
# `start` on this service after it has exited once before does not have any
# effect).
RemainAfterExit=no
ExecStart=/usr/libexec/console-login-helper-messages/issuegen

[Install]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ACTION=="add", SUBSYSTEM=="net", ENV{INTERFACE}=="e*", RUN+="/usr/libexec/console-login-helper-messages/if_snippets_gen add $env{INTERFACE}"
ACTION=="remove", SUBSYSTEM=="net", ENV{INTERFACE}=="e*", RUN+="/usr/libexec/console-login-helper-messages/if_snippets_gen remove $env{INTERFACE}"

This file was deleted.

17 changes: 17 additions & 0 deletions usr/libexec/console-login-helper-messages/if_snippets_gen
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Generate snippets for network devices, invoked by a udev rule.

set -e

. "$(dirname ${0})/issue_defs"

# Add/remove data from udev rules.
case "$1" in
add)
echo "${2}: \\4{${2}} \\6{${2}}" > "${RUN_SNIPPETS}/22_${2}"
;;
remove)
rm -f "${RUN_SNIPPETS}/22_${2}"
;;
esac
12 changes: 12 additions & 0 deletions usr/libexec/console-login-helper-messages/issue_defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

PKG_NAME=console-login-helper-messages
ISSUE_SNIPPETS_PATH=${PKG_NAME}/issue.d
ETC_SNIPPETS="/etc/${ISSUE_SNIPPETS_PATH}"
RUN_SNIPPETS="/run/${ISSUE_SNIPPETS_PATH}"
USR_LIB_SNIPPETS="/usr/lib/${ISSUE_SNIPPETS_PATH}"


# Make sure the `${RUN_SNIPPETS}` directory is created upfront,
# as it may be written to by callers of this script.
mkdir -p "${RUN_SNIPPETS}"
25 changes: 3 additions & 22 deletions usr/libexec/console-login-helper-messages/issuegen
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Get updated system information, including SSH keys and network devices,
# and generate an issue to display before login.
# Get updated system information, including SSH keys, and generate an
# issue to display before login.

# Copyright (c) 2019 Fedora CoreOS Authors. All rights reserved.
# Copyright (c) 2013 The CoreOS Authors. All rights reserved.
Expand All @@ -13,15 +13,7 @@

set -e

PKG_NAME=console-login-helper-messages
ISSUE_SNIPPETS_PATH=${PKG_NAME}/issue.d
ETC_SNIPPETS="/etc/${ISSUE_SNIPPETS_PATH}"
RUN_SNIPPETS="/run/${ISSUE_SNIPPETS_PATH}"
USR_LIB_SNIPPETS="/usr/lib/${ISSUE_SNIPPETS_PATH}"

# Parts of this script write to the `${RUN_SNIPPETS}` directory,
# make sure it is created upfront.
mkdir -p "${RUN_SNIPPETS}"
. "$(dirname ${0})/issue_defs"


# Provide key fingerprints via issue.
Expand All @@ -33,17 +25,6 @@ for KEY_FILE in $(find "${SSH_DIR}" -name 'ssh_host_*_key') ; do
done | awk '{print "SSH host key: " $2 " " $4}' > "${RUN_SNIPPETS}/21_ssh_host_keys.issue"


# Add/remove data from udev rules.
case "$1" in
add)
echo "${2}: \\4{${2}} \\6{${2}}" > "${RUN_SNIPPETS}/22_${2}.issue"
;;
remove)
rm -f "${RUN_SNIPPETS}/22_${2}.issue"
;;
esac


# Generate a final issue message from compiling the snippets.
# Pick 40 as a prefix as other files can order around it easily.
generated="/run/${PKG_NAME}/40_${PKG_NAME}.issue"
Expand Down

0 comments on commit 54d38db

Please sign in to comment.