Skip to content

Commit edc9a05

Browse files
authored
Configure default user for the seed device and test cloud-init config (#273)
1 parent 3f38950 commit edc9a05

File tree

24 files changed

+759
-58
lines changed

24 files changed

+759
-58
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trim_trailing_whitespace = true
2020
spaces_around_operators = true
2121
spaces_around_brackets = false
2222

23-
[*.{hcl.tpl,lock.hcl,sh,tf,tfvars,yml,yaml}]
23+
[*.{hcl.tpl,lock.hcl,sh,tf,tfvars,yml,yaml,yaml.jinja}]
2424
indent_size = 2
2525

2626
[{Makefile,**.mk,go.mod,go.sum,*.go,.gitmodules}]

.github/dependabot.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@ updates:
77
schedule:
88
interval: "daily"
99
- package-ecosystem: "docker"
10-
directory: "/provisioning/os-images/docker"
10+
directory: "/docker/os-image-builder"
11+
schedule:
12+
interval: "daily"
13+
- package-ecosystem: "docker"
14+
directory: "/docker/cloud-init"
15+
schedule:
16+
interval: "daily"
17+
- package-ecosystem: "docker"
18+
directory: "/docker/template-renderer"
19+
schedule:
20+
interval: "daily"
21+
- package-ecosystem: "pip"
22+
directory: "/docker/template-renderer"
1123
schedule:
1224
interval: "daily"
1325
...

.github/workflows/build-os-images.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ on:
88
push:
99
paths:
1010
- ".github/workflows/build-os-images.yaml"
11+
- "docker/os-image-builder/**"
1112
- "provisioning/os-images/**"
1213
pull_request:
1314
paths:
1415
- ".github/workflows/build-os-images.yaml"
16+
- "docker/os-image-builder/**"
1517
- "provisioning/os-images/**"
1618

1719
jobs:
@@ -50,7 +52,7 @@ jobs:
5052
with:
5153
cache-from: type=gha
5254
cache-to: type=gha,mode=max
53-
context: provisioning/os-images/docker
55+
context: docker/os-image-builder
5456
load: true
5557
push: false
5658
tags: "${{ env.OS_BUILDER_CONTAINER_IMAGE_ID }}"
@@ -99,7 +101,7 @@ jobs:
99101
strategy:
100102
matrix:
101103
build-configuration-file-path:
102-
- "${GITHUB_WORKSPACE}/provisioning/os-images/config/builds/seed-device/ubuntu-20.04-cidata-iso-seed-device.conf"
104+
- "${GITHUB_WORKSPACE}/config/seed-device/os-images/ubuntu-20.04-cidata-iso-seed-device.conf"
103105
update-release-draft:
104106
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
105107
outputs:

.yaml-lint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ rules:
1111
# See https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.comments
1212
ignore: |
1313
**/cloud-init/**/user-data.yaml
14+
**/cloud-init/**/user-data-autoinstall.yaml
1415
comments-indentation:
1516
level: error
1617
document-end:

provisioning/os-images/config/builds/seed-device/cloud-init/user-data.yaml renamed to config/seed-device/os-images/cloud-init/user-data-autoinstall.yaml

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#cloud-config
2+
# This file is autogenerated from a template. Don't apply changes manually.
23
---
34
autoinstall:
5+
version: 1
46

57
keyboard:
68
layout: us
@@ -23,20 +25,27 @@ autoinstall:
2325
- edge.lab.ferrari.how
2426
optional: true
2527

26-
ssh:
27-
allow-pw: false
28-
install-server: true
29-
3028
storage:
3129
layout:
3230
name: lvm
3331

3432
user-data:
33+
34+
# Set the password to a known value, and expire it right after the first login,
35+
# so that the user is forced to change it.
36+
chpasswd:
37+
expire: true
38+
list:
39+
- "marco:marco"
40+
41+
groups:
42+
- microk8s
43+
3544
hostname: home-lab-1
3645

37-
locale: "en_US.UTF-8"
46+
locale: en_US.UTF-8
3847

39-
# update the contents of /etc/hosts based on the hostname/fqdn specified
48+
# Update the contents of /etc/hosts based on the hostname/fqdn specified
4049
manage_etc_hosts: true
4150

4251
# Set up the NTP client with default configuration and client
@@ -67,16 +76,26 @@ autoinstall:
6776

6877
snap:
6978
commands:
70-
"001": "snap install microk8s --classic --channel=1.23/stable"
79+
"1": "snap install microk8s --classic --channel=1.23/stable"
7180

72-
# Disable password authentication with the SSH daemon
73-
# for the default user
74-
ssh_pwauth: false
81+
# Enable SSH password authentication. We use for the first authentication,
82+
# then we switch to key-based authentication later in the setup process.
83+
ssh_pwauth: true
7584

7685
# Remove default host keys if any
7786
ssh_deletekeys: true
7887

79-
timezone: "Etc/UTC"
80-
81-
version: 1
88+
timezone: Etc/UTC
89+
90+
# Create users and don't preserve the default user,
91+
# so that we've full control on which accounts we expect to be there.
92+
users:
93+
- name: marco
94+
gecos: Marco
95+
groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, microk8s, netdev, plugdev, sudo, video]
96+
# Don't lock the user to allow the first login with a password,
97+
# so that we initialize key-based authentication later.
98+
lock_passwd: false
99+
shell: /usr/bin/bash
100+
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
82101
...
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#cloud-config
2+
# This file is autogenerated from a template. Don't apply changes manually.
3+
---
4+
5+
# Set the password to a known value, and expire it right after the first login,
6+
# so that the user is forced to change it.
7+
chpasswd:
8+
expire: true
9+
list:
10+
- "marco:marco"
11+
12+
groups:
13+
- microk8s
14+
15+
hostname: home-lab-1
16+
17+
locale: en_US.UTF-8
18+
19+
# Update the contents of /etc/hosts based on the hostname/fqdn specified
20+
manage_etc_hosts: true
21+
22+
# Set up the NTP client with default configuration and client
23+
ntp:
24+
enabled: true
25+
ntp_client: auto
26+
27+
packages:
28+
- openssh-server
29+
30+
package_update: true
31+
package_upgrade: true
32+
package_reboot_if_required: true
33+
34+
random_seed:
35+
file: /dev/urandom
36+
command: ["pollinate", "-r", "-s", "https://entropy.ubuntu.com"]
37+
command_required: true
38+
39+
resize_rootfs: true
40+
41+
# We don't use a script because Ubuntu autoinstall doesn't support generating
42+
# a user-data file that includes scripts that are not in autoinstall.user-data
43+
runcmd:
44+
- /snap/bin/microk8s status --wait-ready
45+
- /snap/bin/microk8s enable dashboard dns gpu ingress storage
46+
- /snap/bin/microk8s status --wait-ready
47+
48+
snap:
49+
commands:
50+
"1": "snap install microk8s --classic --channel=1.23/stable"
51+
52+
# Enable SSH password authentication. We use for the first authentication,
53+
# then we switch to key-based authentication later in the setup process.
54+
ssh_pwauth: true
55+
56+
# Remove default host keys if any
57+
ssh_deletekeys: true
58+
59+
timezone: Etc/UTC
60+
61+
# Create users and don't preserve the default user,
62+
# so that we've full control on which accounts we expect to be there.
63+
users:
64+
- name: marco
65+
gecos: Marco
66+
groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, microk8s, netdev, plugdev, sudo, video]
67+
# Don't lock the user to allow the first login with a password,
68+
# so that we initialize key-based authentication later.
69+
lock_passwd: false
70+
shell: /usr/bin/bash
71+
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
72+
...
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ OS_IMAGE_FILE_TAG="seed-device"
33

44
OS_IMAGE_URL="https://releases.ubuntu.com/focal/ubuntu-20.04.3-live-server-amd64.iso"
55
OS_IMAGE_CHECKSUM_FILE_URL="https://releases.ubuntu.com/focal/SHA256SUMS"
6+
7+
UBUNTU_AUTOINSTALL="true"

docker/cloud-init/Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
FROM ubuntu:20.04
2+
3+
SHELL ["/bin/bash", "-o", "errexit", "-o", "nounset", "-o", "pipefail", "-c"]
4+
5+
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections \
6+
&& apt-get update \
7+
&& DEBIAN_FRONTEND=noninteractive \
8+
TERM=linux \
9+
TZ=Etc/UTC \
10+
apt-get \
11+
--no-install-recommends --yes install \
12+
ca-certificates \
13+
cloud-init \
14+
dbus \
15+
fuse \
16+
kmod \
17+
locales \
18+
lsb-release \
19+
ntp \
20+
openssh-client \
21+
openssh-server \
22+
pollinate \
23+
snap-confine \
24+
snapd \
25+
squashfuse \
26+
sudo \
27+
systemd \
28+
udev \
29+
&& rm -rf /var/lib/apt/lists/* \
30+
&& ln -s "$(command -v systemd)" /sbin/init \
31+
&& dpkg-divert --local --rename --add /sbin/udevadm \
32+
&& ln -s /bin/true /sbin/udevadm \
33+
&& systemctl enable snapd
34+
35+
# Don't clean up apt cache
36+
RUN rm /etc/apt/apt.conf.d/docker-clean
37+
38+
# tell systemd that it is in docker
39+
# https://www.freedesktop.org/software/systemd/man/systemd-detect-virt.html
40+
ENV container docker
41+
# systemd exits on SIGRTMIN+3, not SIGTERM
42+
# https://www.freedesktop.org/software/systemd/man/systemd.html#SIGRTMIN+3
43+
STOPSIGNAL SIGRTMIN+3
44+
ENTRYPOINT [ "/sbin/init" ]
45+
46+
# Set the root user password to a known value that we can use to login as needed
47+
RUN echo 'root:root' | chpasswd
48+
49+
COPY etc/ /etc/
50+
51+
# Cloud-init supplemental configuration file are written in YAML, but require a
52+
# .cfg extension. Rename them after copying in the image.
53+
RUN for f in /etc/cloud/cloud.cfg.d/*.cfg.yaml; do mv -- "${f}" "${f%.yaml}"; done
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
# Only allow the NoCloud datasource
3+
datasource_list: [NoCloud, None]
4+
5+
# Explicitly set the datasource path because we can't rely on filesystem labels
6+
datasource:
7+
NoCloud:
8+
seedfrom: "file:///etc/cloud/datasources/NoCloud/"
9+
10+
# Don't disable the root account because we use that account to login to the system
11+
disable_root: false
12+
13+
# Don't configure the network. Docker takes care of this
14+
network:
15+
config: disabled
16+
...

0 commit comments

Comments
 (0)