ci: implement "console" stream for OS images (#969)

* image: add AUTOLOGIN environment variable to conditionally enable serial console login
* ci: implement "console" stream for OS images
* debugd: remove serial console login access code
This commit is contained in:
Malte Poll 2023-01-16 12:20:01 +01:00 committed by GitHub
parent 90b88e1cf9
commit 938f114086
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 54 deletions

View File

@ -11,15 +11,14 @@ on:
required: false required: false
default: false default: false
stream: stream:
description: "Image stream / type. (Use 'stable' for releases, 'nightly' for regular non-release images and 'debug' for debug builds)" description: "Image stream / type. (Use 'stable' for releases, 'nightly' for regular non-release images, 'console' for images with serial console access and 'debug' for debug builds)"
type: choice type: choice
required: true required: true
options: options:
- "stable" - "stable"
- "nightly" - "nightly"
- "console"
- "debug" - "debug"
# TODO: implement console access enabled image
# - "console"
ref: ref:
type: string type: string
description: "Git ref to checkout" description: "Git ref to checkout"
@ -149,6 +148,8 @@ jobs:
run: | run: |
if [[ "${{ inputs.stream }}" == "debug" ]]; then if [[ "${{ inputs.stream }}" == "debug" ]]; then
echo "imageType=debug" >> "$GITHUB_OUTPUT" echo "imageType=debug" >> "$GITHUB_OUTPUT"
elif [[ "${{ inputs.stream }}" == "console" ]]; then
echo "imageType=console" >> "$GITHUB_OUTPUT"
else else
echo "imageType=default" >> "$GITHUB_OUTPUT" echo "imageType=default" >> "$GITHUB_OUTPUT"
fi fi
@ -266,13 +267,14 @@ jobs:
shell: bash shell: bash
run: | run: |
echo "::group::Build" echo "::group::Build"
sudo make IMAGE_VERSION="${IMAGE_VERSION}" "${CSP}" sudo make IMAGE_VERSION="${IMAGE_VERSION}" AUTOLOGIN="${AUTOLOGIN}" "${CSP}"
echo "::endgroup::" echo "::endgroup::"
working-directory: ${{ github.workspace }}/image working-directory: ${{ github.workspace }}/image
env: env:
BOOTSTRAPPER_BINARY: ${{ github.workspace }}/build/bootstrapper BOOTSTRAPPER_BINARY: ${{ github.workspace }}/build/bootstrapper
DISK_MAPPER_BINARY: ${{ github.workspace }}/build/disk-mapper DISK_MAPPER_BINARY: ${{ github.workspace }}/build/disk-mapper
UPGRADE_AGENT_BINARY: ${{ github.workspace }}/build/upgrade-agent UPGRADE_AGENT_BINARY: ${{ github.workspace }}/build/upgrade-agent
AUTOLOGIN: ${{ (inputs.stream == 'console' || inputs.stream == 'debug' ) && 'true' || 'false' }}
IMAGE_VERSION: ${{ needs.build-settings.outputs.imageVersion }} IMAGE_VERSION: ${{ needs.build-settings.outputs.imageVersion }}
CSP: ${{ matrix.csp }} CSP: ${{ matrix.csp }}

View File

@ -51,10 +51,6 @@ func main() {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
if err := deploy.EnableAutoLogin(ctx, fs, serviceManager); err != nil {
log.Errorf("root login: %w")
}
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
csp := os.Getenv("CONSTEL_CSP") csp := os.Getenv("CONSTEL_CSP")

View File

@ -31,8 +31,4 @@ ExecStart=/run/state/bin/bootstrapper
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
` `
GettyAutologinOverrideFilename = "/run/systemd/system/serial-getty@ttyS0.service.d/autologin.conf"
GettyAutologinOverrideUnitContents = `[Service]
ExecStart=
ExecStart=-/sbin/agetty -o '-p -f -- \\u' --autologin root --keep-baud 115200,57600,38400,9600 - $TERM`
) )

View File

@ -1,41 +0,0 @@
/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/
package deploy
import (
"context"
"fmt"
"os"
"path"
"github.com/edgelesssys/constellation/v2/debugd/internal/debugd"
"github.com/spf13/afero"
)
// EnableAutoLogin installs a systemd unit override that allows passwordless root login
// on the serial console.
func EnableAutoLogin(ctx context.Context, fs afero.Fs, serviceManager serviceManager) error {
if err := fs.MkdirAll(path.Dir(debugd.GettyAutologinOverrideFilename), os.ModePerm); err != nil {
return fmt.Errorf("creating getty autologin override directory: %w", err)
}
if err := afero.WriteFile(fs, debugd.GettyAutologinOverrideFilename,
[]byte(debugd.GettyAutologinOverrideUnitContents), os.ModePerm); err != nil {
return fmt.Errorf("writing getty autologin override unit: %w", err)
}
if err := serviceManager.SystemdAction(ctx, ServiceManagerRequest{
Action: Reload,
}); err != nil {
return fmt.Errorf("reloading systemd units: %w", err)
}
if err := serviceManager.SystemdAction(ctx, ServiceManagerRequest{
Action: Restart,
Unit: "serial-getty@ttyS0.service",
}); err != nil {
return fmt.Errorf("restarting getty: %w", err)
}
return nil
}

View File

@ -7,6 +7,9 @@ UPGRADE_AGENT_BINARY ?= $(BASE_PATH)/../build/upgrade-agent
PKI ?= $(BASE_PATH)/pki PKI ?= $(BASE_PATH)/pki
MKOSI_EXTRA ?= $(BASE_PATH)/mkosi.extra MKOSI_EXTRA ?= $(BASE_PATH)/mkosi.extra
IMAGE_VERSION ?= v0.0.0 IMAGE_VERSION ?= v0.0.0
AUTOLOGIN ?= false
AUTOLOGIN_ARGS := $(if $(filter true,$(AUTOLOGIN)),--autologin) # set "--autologin" if AUTOLOGIN is true
export CONSOLE_MOTD = $(AUTOLOGIN)
-include $(CURDIR)/config.mk -include $(CURDIR)/config.mk
csps := aws qemu gcp azure csps := aws qemu gcp azure
certs := $(PKI)/PK.cer $(PKI)/KEK.cer $(PKI)/db.cer certs := $(PKI)/PK.cer $(PKI)/KEK.cer $(PKI)/db.cer
@ -33,7 +36,7 @@ prebuilt/rpms/azure/%.rpm:
@curl -sL -o $@ https://kojipkgs.fedoraproject.org/packages/kernel/5.19.4/300.fc37/x86_64/$*.rpm @curl -sL -o $@ https://kojipkgs.fedoraproject.org/packages/kernel/5.19.4/300.fc37/x86_64/$*.rpm
mkosi.output.%/fedora~37/image.raw: mkosi.files/mkosi.%.conf inject-bins inject-certs mkosi.output.%/fedora~37/image.raw: mkosi.files/mkosi.%.conf inject-bins inject-certs
mkosi --config mkosi.files/mkosi.$*.conf --image-version=$(IMAGE_VERSION) build mkosi --config mkosi.files/mkosi.$*.conf --image-version=$(IMAGE_VERSION) $(AUTOLOGIN_ARGS) --environment=CONSOLE_MOTD build
secure-boot/signed-shim.sh $@ secure-boot/signed-shim.sh $@
@if [ -n $(SUDO_UID) ] && [ -n $(SUDO_GID) ]; then \ @if [ -n $(SUDO_UID) ] && [ -n $(SUDO_GID) ]; then \
chown -R $(SUDO_UID):$(SUDO_GID) mkosi.output.$*; \ chown -R $(SUDO_UID):$(SUDO_GID) mkosi.output.$*; \

View File

@ -70,6 +70,8 @@ After that, you can build the image with:
```sh ```sh
# OPTIONAL: to create a debug image, export the following line # OPTIONAL: to create a debug image, export the following line
# export BOOTSTRAPPER_BINARY=$(realpath ${PWD}/../../build/debugd) # export BOOTSTRAPPER_BINARY=$(realpath ${PWD}/../../build/debugd)
# OPTIONAL: to enable the serial console, export the following line
# export AUTOLOGIN=true
# OPTIONAL: symlink custom path to secure boot PKI to ./pki # OPTIONAL: symlink custom path to secure boot PKI to ./pki
# ln -s /path/to/pki/folder ./pki # ln -s /path/to/pki/folder ./pki
sudo make -j $(nproc) sudo make -j $(nproc)