From 1f887c7868f666aa0f351d0decf0e2d70fcd008f Mon Sep 17 00:00:00 2001 From: 3u13r Date: Tue, 17 Sep 2024 14:07:28 +0200 Subject: [PATCH] image: re-enable autologin for debug and console images (#3355) * image: remove autologin via mkosi In mkosi v24 --autologin no longer works for ttyS consoles. Since the CSPs use those exclusively for their serial consoles, we need to replace this with another solution (see next commit) * image: add getty systemd unit for debug images This replaces the mkosi --autologin solution with a getty systemd unit for ttyS0. Note that both console and debug images hace their consoles enabled. --- bazel/mkosi/mkosi_image.bzl | 3 --- .../20-constellation-base.preset | 1 + .../autologin.conf | 12 +++++++++ image/system/BUILD.bazel | 7 +----- image/system/variants.bzl | 25 ++----------------- 5 files changed, 16 insertions(+), 32 deletions(-) create mode 100644 image/sysroot-tree/usr/lib/systemd/system/serial-getty@ttyS0.service.d/autologin.conf diff --git a/bazel/mkosi/mkosi_image.bzl b/bazel/mkosi/mkosi_image.bzl index 6af63dff1..fb11a81c2 100644 --- a/bazel/mkosi/mkosi_image.bzl +++ b/bazel/mkosi/mkosi_image.bzl @@ -70,8 +70,6 @@ def _mkosi_image_impl(ctx): args.add("--kernel-command-line", ctx.attr.kernel_command_line) for key, value in ctx.attr.kernel_command_line_dict.items(): args.add("--kernel-command-line", "{}={}".format(key, value)) - if ctx.attr.autologin: - args.add("--autologin", "yes") info = ctx.toolchains["@constellation//bazel/mkosi:toolchain_type"].mkosi if not info.valid: @@ -110,7 +108,6 @@ mkosi_image = rule( implementation = _mkosi_image_impl, attrs = { "architecture": attr.string(), - "autologin": attr.bool(), "base_trees": attr.label_list(allow_files = True), "distribution": attr.string(), "env": attr.string_dict(), diff --git a/image/sysroot-tree/usr/lib/systemd/system-preset/20-constellation-base.preset b/image/sysroot-tree/usr/lib/systemd/system-preset/20-constellation-base.preset index b213385af..f74d34ec8 100644 --- a/image/sysroot-tree/usr/lib/systemd/system-preset/20-constellation-base.preset +++ b/image/sysroot-tree/usr/lib/systemd/system-preset/20-constellation-base.preset @@ -2,6 +2,7 @@ enable systemd-timesyncd.service enable systemd-networkd.service enable systemd-networkd-wait-online.service enable configure-constel-csp.service +enable serial-getty@tty0.service enable dbus.service enable dbus-broker.service enable dbus-daemon.service diff --git a/image/sysroot-tree/usr/lib/systemd/system/serial-getty@ttyS0.service.d/autologin.conf b/image/sysroot-tree/usr/lib/systemd/system/serial-getty@ttyS0.service.d/autologin.conf new file mode 100644 index 000000000..77db15a0a --- /dev/null +++ b/image/sysroot-tree/usr/lib/systemd/system/serial-getty@ttyS0.service.d/autologin.conf @@ -0,0 +1,12 @@ +[Unit] +Description=autologin +ConditionPathExists=/proc/cmdline +ConditionKernelCommandLine=|constellation.console +ConditionKernelCommandLine=|constellation.debug + +[Service] +ExecStart= +ExecStart=-/sbin/agetty -o '-p -f -- \\u' --keep-baud --autologin root 115200,57600,38400,9600 - $TERM + +[Install] +WantedBy=multi-user.target diff --git a/image/system/BUILD.bazel b/image/system/BUILD.bazel index 3765667b8..3a51c92a4 100644 --- a/image/system/BUILD.bazel +++ b/image/system/BUILD.bazel @@ -1,6 +1,6 @@ load("//bazel/mkosi:mkosi_image.bzl", "mkosi_image") load("//bazel/osimage:upload_os_images.bzl", "upload_os_images") -load(":variants.bzl", "CSPS", "STREAMS", "VARIANTS", "autologin", "base_image", "constellation_packages", "images_for_csp", "images_for_csp_and_stream", "images_for_stream", "kernel_command_line", "kernel_command_line_dict") +load(":variants.bzl", "CSPS", "STREAMS", "VARIANTS", "base_image", "constellation_packages", "images_for_csp", "images_for_csp_and_stream", "images_for_stream", "kernel_command_line", "kernel_command_line_dict") [ mkosi_image( @@ -10,11 +10,6 @@ load(":variants.bzl", "CSPS", "STREAMS", "VARIANTS", "autologin", "base_image", ] + glob([ "mkosi.repart/**", ]), - autologin = autologin( - variant["csp"], - variant["attestation_variant"], - stream, - ), base_trees = [ base_image( variant["csp"], diff --git a/image/system/variants.bzl b/image/system/variants.bzl index 3cca05c95..cfc8c5392 100644 --- a/image/system/variants.bzl +++ b/image/system/variants.bzl @@ -86,7 +86,7 @@ csp_settings = { }, }, "qemu": { - "autologin": True, + "kernel_command_line": "constellation.console", # All qemu images have console enabled independent of stream "kernel_command_line_dict": { "console": "ttyS0", "constel.csp": "qemu", @@ -136,10 +136,9 @@ attestation_variant_settings = { stream_settings = { "console": { - "autologin": True, + "kernel_command_line": "constellation.console", }, "debug": { - "autologin": True, "kernel_command_line": "constellation.debug", }, "nightly": {}, @@ -181,26 +180,6 @@ def constellation_packages(stream): "//bootstrapper/cmd/bootstrapper:bootstrapper-package", ] + base_packages -def autologin(csp, attestation_variant, stream): - """Generates a boolean indicating whether autologin should be enabled for the given csp, attestation_variant and stream. - - Args: - csp: The cloud service provider to use. - attestation_variant: The attestation variant to use. - stream: The stream to use. - - Returns: - A boolean indicating whether autologin should be enabled. - """ - out = None - for settings in from_settings(csp, attestation_variant, stream): - if not "autologin" in settings: - continue - if out != None and out != settings["autologin"]: - fail("Inconsistent autologin settings") - out = settings["autologin"] - return out - def kernel_command_line(csp, attestation_variant, stream): cmdline = base_cmdline for settings in from_settings(csp, attestation_variant, stream, default = {}):