Skip to content

Commit 4b3dfc9

Browse files
committed
Switch to authorized keys for image login
1 parent 9613080 commit 4b3dfc9

16 files changed

Lines changed: 29 additions & 82 deletions

File tree

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ SHELL := /usr/bin/env bash
55
WRAPPER := scripts/env_wrapper.sh
66

77
FILE ?= build/latest.efi
8+
SERIAL_CONSOLE ?= false
89

910
##@ Help
1011

@@ -43,8 +44,9 @@ build: setup ## Build the specified module
4344
$(WRAPPER) mkosi --force --image-id $(IMAGE) --include=images/$(IMAGE).conf
4445

4546
# Build module with devtools profile
47+
build-dev: SERIAL_CONSOLE_PROFILE := $(if $(filter true,$(SERIAL_CONSOLE)),serial-console,)
4648
build-dev: setup ## Build module with development tools
47-
$(WRAPPER) mkosi --force --image-id $(IMAGE)-dev --profile=devtools --include=images/$(IMAGE).conf
49+
$(WRAPPER) mkosi --force --image-id $(IMAGE)-dev --profile=devtools,$(SERIAL_CONSOLE_PROFILE) --include=images/$(IMAGE).conf
4850

4951
##@ Utilities
5052

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,17 @@ make build IMAGE=l2-builder
4747
# Build with development tools
4848
make build-dev IMAGE=flashbox-l1
4949

50+
# Build dev image with serial console + password auth enabled
51+
make build-dev IMAGE=flashbox-l1 SERIAL_CONSOLE=true
52+
5053
# View all available targets
5154
make help
5255
```
5356

57+
#### Serial console
58+
59+
Pass `SERIAL_CONSOLE=true` to enable the serial console service and password authentication. This also sets a fixed root password (`dqSPjo4p`) for SSH login, so only use this for local development/debugging.
60+
5461
### Measuring TDX Boot Process
5562

5663
**Export TDX measurements** for the built image:

images/l2-op-rbuilder-bproxy.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@ Include=shared/mkosi.conf
99
Include=modules/l2/_common/mkosi.conf
1010
Include=modules/l2/_gcp/mkosi.conf
1111
Include=modules/l2/_devtools_users/mkosi.conf
12-
Include=modules/l2/_devtools_no_console/mkosi.conf
13-
Include=modules/l2/_devtools_no_root_login/mkosi.conf
1412
Include=modules/l2/op-rbuilder-bproxy/mkosi.conf

images/l2-op-rbuilder.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@ Include=shared/mkosi.conf
99
Include=modules/l2/_common/mkosi.conf
1010
Include=modules/l2/_gcp/mkosi.conf
1111
Include=modules/l2/_devtools_users/mkosi.conf
12-
Include=modules/l2/_devtools_no_console/mkosi.conf
13-
Include=modules/l2/_devtools_no_root_login/mkosi.conf
1412
Include=modules/l2/op-rbuilder/mkosi.conf

images/l2-simulator.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@ Include=shared/mkosi.conf
99
Include=modules/l2/_common/mkosi.conf
1010
Include=modules/l2/_gcp/mkosi.conf
1111
Include=modules/l2/_devtools_users/mkosi.conf
12-
Include=modules/l2/_devtools_no_console/mkosi.conf
13-
Include=modules/l2/_devtools_no_root_login/mkosi.conf
1412
Include=modules/l2/simulator/mkosi.conf

mkosi.profiles/devtools/mkosi.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[Content]
2-
ExtraTrees=mkosi.extra
3-
custom
2+
ExtraTrees=custom
43
PostInstallationScripts=custom.postinst.d/*.sh
54

65
Packages=adjtimex

mkosi.profiles/devtools/mkosi.postinst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22

33
set -euxo pipefail
44

5-
# Enable console service
6-
mkosi-chroot systemctl unmask serial-console.service
7-
mkosi-chroot systemctl add-wants minimal.target serial-console.service
8-
9-
# Deterministically set root password
10-
PASSWORD="dqSPjo4p"
11-
HASH=$(mkosi-chroot openssl passwd -6 -salt salt "$PASSWORD")
12-
mkosi-chroot passwd -u root
13-
mkosi-chroot usermod -p "$HASH" root
14-
155
# Remove git files in custom/ folder
166
mkosi-chroot rm /.gitignore /.gitkeep || true
177

@@ -20,7 +10,6 @@ if [ -f "$BUILDROOT/etc/default/dropbear" ]; then
2010
sed -i '/^DROPBEAR_EXTRA_ARGS=/s/-[swg] \?//g' "$BUILDROOT/etc/default/dropbear"
2111
else
2212
echo "PermitRootLogin yes" >> "$BUILDROOT/etc/ssh/sshd_config"
23-
echo "PasswordAuthentication yes" >> "$BUILDROOT/etc/ssh/sshd_config"
2413
mkosi-chroot systemctl unmask ssh.service ssh.socket systemd-user-sessions.service
2514
mkosi-chroot systemctl add-wants minimal.target ssh.service systemd-user-sessions.service
2615
fi
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Content]
2+
ExtraTrees=serial-console.service:/usr/lib/systemd/system/serial-console.service
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -euxo pipefail
4+
5+
# Enable console service
6+
mkosi-chroot systemctl unmask serial-console.service
7+
mkosi-chroot systemctl add-wants minimal.target serial-console.service
8+
9+
# Deterministically set root password
10+
PASSWORD="dqSPjo4p"
11+
HASH=$(mkosi-chroot openssl passwd -6 -salt salt "$PASSWORD")
12+
mkosi-chroot passwd -u root
13+
mkosi-chroot usermod -p "$HASH" root
14+
15+
# Allow login by password
16+
echo "PasswordAuthentication yes" >> "$BUILDROOT/etc/ssh/sshd_config"

mkosi.profiles/devtools/mkosi.extra/usr/lib/systemd/system/serial-console.service renamed to mkosi.profiles/serial-console/serial-console.service

File renamed without changes.

0 commit comments

Comments
 (0)