From 992e83d203f4949572f2766d22db448bf7fad1c7 Mon Sep 17 00:00:00 2001
From: Colin Walters <walters@verbum.org>
Date: Thu, 4 Jan 2024 11:08:37 -0500
Subject: [PATCH] machine: Enable console autologin by default

There are no security concerns here; this is a convenience
for people debugging things.  Some podman-machine developers
were manually setting a password over SSH for example,
but this is just better than that.

[NO NEW TESTS NEEDED]

Signed-off-by: Colin Walters <walters@verbum.org>
---
 pkg/machine/ignition/ignition.go | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/pkg/machine/ignition/ignition.go b/pkg/machine/ignition/ignition.go
index 11488d4a3f..0863f6f1d3 100644
--- a/pkg/machine/ignition/ignition.go
+++ b/pkg/machine/ignition/ignition.go
@@ -135,6 +135,14 @@ func (ign *DynamicIgnition) GenerateIgnitionConfig() error {
 		ignStorage.Links = append(ignStorage.Links, tzLink)
 	}
 
+	// Enables automatic login on the console;
+	// there's no security concerns here, and this makes debugging easier.
+	// xref https://docs.fedoraproject.org/en-US/fedora-coreos/tutorial-autologin/
+	var autologinDropin = `[Service]
+ExecStart=
+ExecStart=-/usr/sbin/agetty --autologin root --noclear %I $TERM
+`
+
 	deMoby := parser.NewUnitFile()
 	deMoby.Add("Unit", "Description", "Remove moby-engine")
 	deMoby.Add("Unit", "After", "systemd-machine-id-commit.service")
@@ -220,7 +228,26 @@ func (ign *DynamicIgnition) GenerateIgnitionConfig() error {
 				Enabled: BoolToPtr(false),
 				Name:    "zincati.service",
 			},
-		}}
+			{
+				Name: "serial-getty@.service",
+				Dropins: []Dropin{
+					{
+						Name:     "10-autologin.conf",
+						Contents: &autologinDropin,
+					},
+				},
+			},
+			{
+				Name: "getty@.service",
+				Dropins: []Dropin{
+					{
+						Name:     "10-autologin.conf",
+						Contents: &autologinDropin,
+					},
+				},
+			},
+		},
+	}
 
 	// Only qemu has the qemu firmware environment setting
 	if ign.VMType == define.QemuVirt {