Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [NODE-1441] Upgrade GuestOS to 24.04 #938

Merged
merged 16 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

# machine-id is set up in initramfs and bind-mounted over to the rootfs. Since
# policy is not loaded in initramfs yet, it has wrong security context.
systemd-machine-id-setup --commit
restorecon -v /etc/machine-id
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
# over to the rootfs. Since policy is not loaded in initramfs yet, it has
# wrong security context. Fix this up, but ignore failures (this will not
# work on first boot).
systemd-machine-id-setup --commit
restorecon -v /etc/machine-id || true
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ while [ ! -f /boot/config/CONFIGURED ]; do
fi

# Fix up permissions. This is actually the wrong place.
chown ic-replica.nogroup -R /var/lib/ic/data
chown ic-replica:nogroup -R /var/lib/ic/data

if [ "${DEV}" != "" ]; then
umount /mnt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Description=Set up encrypted storage on first boot
DefaultDependencies=no
After=boot-config.mount
Requires=boot-config.mount
Before=systemd-cryptsetup@vda10\x2dcrypt.service
Before=cryptsetup-pre.target
Wants=cryptsetup-pre.target

[Install]
WantedBy=local-fs.target
RequiredBy=systemd-cryptsetup@vda10\x2dcrypt.service

[Service]
Type=oneshot
Expand Down
2 changes: 1 addition & 1 deletion ic-os/components/misc/guestos/crypttab
Original file line number Diff line number Diff line change
@@ -1 +1 @@
vda10-crypt /dev/vda10 /boot/config/store.keyfile luks2,discard
vda10-crypt /dev/vda10 /boot/config/store.keyfile luks,discard
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[Unit]
Description=Generate network config
After=bootstrap-ic-node.service
Requires=bootstrap-ic-node.service
Before=systemd-networkd.service

[Install]
Expand Down
3 changes: 3 additions & 0 deletions ic-os/components/selinux/filebeat/filebeat.te
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ init_daemon_domain(filebeat_t, filebeat_exec_t)
# Allow filebeat to perform its primary function, namely to read
# the journal files.
systemd_read_journal_files(filebeat_t)
systemd_watch_journal_dirs(filebeat_t)

# It wants to send the logs to remote host, allow unrestricted TCP for
# this for now. Maybe this can be reasonably constrained more tightly.
Expand All @@ -56,6 +57,7 @@ corenet_all_recvfrom_unlabeled(filebeat_t)

# Read generic etc files (e.g. nsswitch.conf)
files_read_etc_files(filebeat_t)
files_read_etc_runtime_files(filebeat_t)

# Read CA certificate
miscfiles_read_generic_certs(filebeat_t)
Expand Down Expand Up @@ -124,6 +126,7 @@ require {
search_dirs_pattern(filebeat_t, bin_t, bin_t)

# Allow to read `/sys/fs/cgroup/unified/system.slice/filebeat.service/cgroup.controllers`
require { type cgroup_t; }
fs_read_cgroup_files(filebeat_t)
allow filebeat_t cgroup_t:dir read;

Expand Down
1 change: 1 addition & 0 deletions ic-os/components/selinux/ic-node/ic-node.te
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ allow ic_canister_sandbox_t ic_canister_mem_t : file { map read write getattr };
allow ic_replica_t ic_canister_mem_t : file { map read write getattr };

# Wants to read its own control group. Should deny that.
require { type cgroup_t; }
dontaudit ic_canister_sandbox_t cgroup_t : dir { search };
dontaudit ic_canister_sandbox_t cgroup_t : file { open read getattr };

Expand Down
6 changes: 3 additions & 3 deletions ic-os/components/selinux/manageboot/manageboot.te
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ application_domain(ic_manageboot_t, ic_manageboot_exec_t)
# write upgrades into partition). Allow entering sudo, and return
# to the original domain when sudo re-executes the script (so
# it is now running same domain, but with root privileges).
sudo_role_template(ic_manageboot, system_r, ic_manageboot_t)
sudo_role_template(ic_manageboot, ic_manageboot_t, ic_manageboot_exec_t, system_r)
domtrans_pattern(ic_manageboot_sudo_t, ic_manageboot_exec_t, ic_manageboot_t)
# Under certain circumstances, sudo signals its children.
allow ic_manageboot_sudo_t ic_manageboot_t : process { signal };
Expand Down Expand Up @@ -123,7 +123,7 @@ allow ic_manageboot_t ic_manageboot_t : unix_stream_socket { connect create geta
# Allow searching runtime process directories (/var/run which is symlinked to /run).
# It is not perfectly clear what/why it is doing that, but it is harmless
# enough. May to to forbid it and see if it still works.
files_search_pids(ic_manageboot_t)
files_search_runtime(ic_manageboot_t)

# Allow reading /opt/ic/share/version.txt
read_files_pattern(ic_manageboot_t, usr_t, usr_t)
read_files_pattern(ic_manageboot_t, usr_t, usr_t)
6 changes: 5 additions & 1 deletion ic-os/components/selinux/misc-fixes/misc-fixes.te
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ permissive unconfined_t;
require { type lvm_t; }

# Note that "cryptsetup" is also running as lvm_t.
require { type initrc_t, initrc_runtime_t; }
allow lvm_t initrc_t : sem rw_sem_perms;

# cryptsetup needs to create /run/cryptsetup: This is its lockfile directory to
# track which devices, which is the lockfile directory tracking devices on
# which operations are in progress
require { type var_run_t; }
require { type var_run_t, initrc_runtime_t; }
create_dirs_pattern(lvm_t, var_run_t, var_run_t)
manage_dirs_pattern(lvm_t, initrc_runtime_t, initrc_runtime_t)
manage_files_pattern(lvm_t, initrc_runtime_t, initrc_runtime_t)

# lvm cryptsetup needs to manage its own cryptographic keys
allow lvm_t lvm_t : key manage_key_perms;
Expand Down
7 changes: 7 additions & 0 deletions ic-os/components/selinux/systemd-fixes/systemd-fixes.te
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ list_dirs_pattern(systemd_tmpfiles_t, unlabeled_t, unlabeled_t)
# A tempfile is used as part of setting up machine-id
read_files_pattern(systemd_tmpfiles_t, tmpfs_t, tmpfs_t)

###############################################################################
# systemd-generator

# systemd_generator_t is missing this permission, and it blocks ssh
require { type systemd_generator_t; }
init_delete_runtime_files(systemd_generator_t)

###############################################################################
# udev

Expand Down
22 changes: 4 additions & 18 deletions ic-os/guestos/context/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ RUN sed -e '/.*pam_motd.so.*/d' -i /etc/pam.d/login && \
# but this is per system (so backups are not persisted across upgrades)
# and thus not very useful, and /etc is read-only.
# So simply suppress generating backups.
RUN sed -e 's/\(backup *= *\)1/\10/' -e 's/\(archive *= *\)1/\10/' -i /etc/lvm/lvm.conf
RUN sed -e 's/\(# \)\?\(backup *= *\)[01]/\20/' -e 's/\(# \)\?\(archive *= *\)[01]/\20/' -i /etc/lvm/lvm.conf

# Deactivate systemd userdb. We don't use it.
RUN sed -e 's/ *systemd//' -i /etc/nsswitch.conf

# Clear files that may lead to indeterministic build.
RUN apt-get clean && \
find /usr/lib/python3.8 -name "*.pyc" | xargs rm && \
find /usr/lib/python3.12 -name "*.pyc" | xargs rm && \
find /usr/lib/python3 -name "*.pyc" | xargs rm && \
find /usr/share/python3 -name "*.pyc" | xargs rm && \
truncate --size 0 /etc/machine-id
Expand Down Expand Up @@ -96,6 +96,7 @@ RUN \
RUN systemctl enable \
chrony \
nftables \
ssh \
systemd-networkd \
systemd-networkd-wait-online \
systemd-resolved \
Expand All @@ -111,10 +112,6 @@ RUN systemctl disable \
fstrim.service \
fstrim.timer

# Clear additional files that may lead to indeterministic build.
RUN find /usr/local/share/fonts -name .uuid | xargs rm && \
find /usr/share/fonts -name .uuid | xargs rm

# ------ GUESTOS WORK --------------------------------------------

# Divert symbolic link for dynamically generated nftables
Expand All @@ -129,19 +126,8 @@ RUN mkdir -p /var/lib/ic/backup \
# Create two mount points for temporary use during setup of "var" partition
RUN mkdir -p /mnt/var_old /mnt/var_new

# Add user/group entries specified here: /usr/lib/sysusers.d/systemd.conf E.g., systemd-timesync/coredump.
## `systemd-sysusers` does not honor the SOURCE_DATE_EPOCH env var.
## With `podman --timestamp=0` each file gets written with timestamp of the Unix epoch.
## When systemd-sysusers writes the shadow entry for these users, the 2nd field in the row (# days since the epoch) is set to (today - unix epoch).
## This is not reproducible.
## Reset the passwords to the locked password ("!!"). `usermod` honors SOURCE_DATE_EPOCH (set in the base dockerfile). This removes the password timestamp.
## Why not use `faketime`? Doesn't work with `podman --timestamp=0`.
RUN systemd-sysusers && \
usermod -p '!!' systemd-timesync && \
usermod -p '!!' systemd-coredump

# Set /bin/sh to point to /bin/bash instead of the default /bin/dash
RUN echo "set dash/sh false" | debconf-communicate && dpkg-reconfigure -fnoninteractive dash
RUN ln -sf bash /usr/bin/sh

# Group accounts to which parts of the runtime state are assigned such that
# user accounts can be granted individual access rights.
Expand Down
4 changes: 2 additions & 2 deletions ic-os/guestos/context/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# First build stage:
# - Download 3rd party tools
#
FROM ubuntu:20.04 as download
FROM ubuntu:24.04 as download

USER root:root

Expand Down Expand Up @@ -48,7 +48,7 @@ RUN cd /tmp/ && \
# - Install and cache upstream packages from built-in Ubuntu repositories
# - Copy downloaded archives from first build stage into the target image
#
FROM ubuntu:20.04
FROM ubuntu:24.04

USER root:root

Expand Down
3 changes: 2 additions & 1 deletion ic-os/guestos/context/packages.common
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
# image only.

# Need kernel to boot anything
linux-image-virtual-hwe-20.04
linux-image-virtual-hwe-24.04
initramfs-tools

# Need systemd for boot process
systemd
systemd-sysv
systemd-journal-remote
systemd-resolved

# Third-party services we will be running
chrony
Expand Down
4 changes: 2 additions & 2 deletions ic-os/guestos/context/packages.dev
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ nano
# packages requested by networking
tcpdump
iperf
netcat
netcat-openbsd
curl
iputils-ping

Expand All @@ -22,7 +22,7 @@ strace
setools

# flamegraphs (scalability suite)
linux-tools-virtual-hwe-20.04
linux-tools-virtual-hwe-24.04

# performance testing additions
fio
Expand Down
1 change: 1 addition & 0 deletions ic-os/guestos/envs/dev-malicious/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load("//ic-os/guestos:defs.bzl", "image_deps")
# or //ic-os/defs.bzl for the full list of targets.
icos_build(
name = "dev-malicious",
build_local_base_image = True,
ic_version = "//bazel:rc_only_version.txt",
image_deps_func = image_deps,
malicious = True,
Expand Down
1 change: 1 addition & 0 deletions ic-os/guestos/envs/dev/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load("//ic-os/guestos:defs.bzl", "image_deps")
# or //ic-os/defs.bzl for the full list of targets.
icos_build(
name = "dev",
build_local_base_image = True,
ic_version = "//bazel:rc_only_version.txt",
image_deps_func = image_deps,
upload_prefix = "guest-os",
Expand Down
1 change: 1 addition & 0 deletions ic-os/guestos/envs/prod/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load("//ic-os/guestos:defs.bzl", "image_deps")
# or //ic-os/defs.bzl for the full list of targets.
icos_build(
name = "prod",
build_local_base_image = True,
image_deps_func = image_deps,
upload_prefix = "guest-os",
visibility = ["//rs:ic-os-pkg"],
Expand Down
6 changes: 6 additions & 0 deletions rs/tests/driver/src/driver/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,12 @@ async fn stream_journald_from_cursor(
cursor,
stream.write_all(b"Accept: application/json\n").await
);
unwrap_or_return!(
cursor,
stream
.write_all(format!("Host: {ipv6}:19531\n").as_bytes())
.await
);
unwrap_or_return!(
cursor,
stream
Expand Down
4 changes: 3 additions & 1 deletion rs/tests/driver/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,9 @@ impl LogStream {

// Use plaintext instead of json, because some messages are too large for the journal json serializer
stream
.write_all(b"GET /entries?follow HTTP/1.1\n\r\n\r")
.write_all(
format!("GET /entries?follow HTTP/1.1\r\nHost:{ip_addr}:19531\r\n\r\n").as_bytes(),
)
.await?;

let bf = BufReader::new(stream);
Expand Down
Loading