Skip to contentSkip to conversation

CI: Switch the alpine containers to be non-root

PATCH In review Andrew Cooper 2 participants 4 messages Sep 10, 2025 – Sep 24, 2025 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 CI: Switch the alpine containers to be non-root

Testing on staging-4.19 is hitting a reliable failure, caused by alpine/3.18 being a root build container, but debian/12-x86_64 being a non-root test container. Specifically, the test container can't copy XEN_PAGING_DIR and XEN_DUMP_DIR (both 700) from the build root in order to construct the initrd.

staging-4.20 and later do not repack the initrd in this way, so are not affected.

Switch both alpine containers to being non-root. This is still slightly fragile, but better than depending on using root containers for both.

---
CC: Anthony PERARD <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Marek Marczykowski-Górecki <[email protected]>
CC: Jan Beulich <[email protected]>

The only less fragile option I can think of would be to backport the initrd CPIO optimisations. I backported it from 4.21 to 4.20, and can't remember if there was a blocking reason on 4.19, or simply that it would be a lot of work.

I've rebuilt these containers in registry.gitlab.com/xen-project/people/andyhhp/xen

Runs using this registry:
staging:

    https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/2031831044
  staging-4.19:
    https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/2031832855

(There will be a delay until these can run fully. The CPPCheck container takes an unreasonable amount of time to rebuild, and it's holding up a couple of others.)

---
 automation/build/alpine/3.18-arm64v8.dockerfile | 16 ++++++++--------
 automation/build/alpine/3.18.dockerfile         | 16 ++++++++--------
 2 files changed, 16 insertions(+), 16 deletions(-)
automation/build/alpine/3.18-arm64v8.dockerfile +8 -8
index b8482d5bf43f..360da8281054 100644
@@ -3,13 +3,10 @@ FROM --platform=linux/arm64/v8 alpine:3.18
 LABEL maintainer.name="The Xen Project" \
       maintainer.email="[email protected]"
 
-ENV USER root
-
-RUN mkdir /build
-WORKDIR /build
-
-# build depends
-RUN apk --no-cache add \
+RUN adduser -S user && \
+  mkdir /build && \
+  # build depends
+  apk --no-cache add \
   \
   # xen build deps
   argp-standalone \
@@ -48,4 +45,7 @@ RUN apk --no-cache add \
   # qubes test deps
   openssh-client \
   fakeroot \
-  expect \
+  expect
+
+USER user
+WORKDIR /build
automation/build/alpine/3.18.dockerfile +8 -8
index 263e9e90d888..4ccbe8e5c1b3 100644
@@ -3,13 +3,10 @@ FROM --platform=linux/amd64 alpine:3.18
 LABEL maintainer.name="The Xen Project" \
       maintainer.email="[email protected]"
 
-ENV USER root
-
-RUN mkdir /build
-WORKDIR /build
-
-# build depends
-RUN apk --no-cache add \
+RUN adduser -S user && \
+  mkdir /build && \
+  # build depends
+  apk --no-cache add \
   \
   # xen build deps
   argp-standalone \
@@ -49,4 +46,7 @@ RUN apk --no-cache add \
   ninja \
   pixman-dev \
   # livepatch-tools deps
-  elfutils-dev \
+  elfutils-dev
+
+USER user
+WORKDIR /build
Signature · 1 line
2.39.5

A message that is not in the archive (sent off-list or not yet received): aMFnqW7xgbL1ZSBi@mail-itl

#2 lore raw
Quoted 27 lines · Marek Marczykowski-Górecki
Quoted 10 lines · Andrew Cooper

Testing on staging-4.19 is hitting a reliable failure, caused by alpine/3.18 being a root build container, but debian/12-x86_64 being a non-root test container. Specifically, the test container can't copy XEN_PAGING_DIR and XEN_DUMP_DIR (both 700) from the build root in order to construct the initrd.

staging-4.20 and later do not repack the initrd in this way, so are not affected.

Switch both alpine containers to being non-root. This is still slightly fragile, but better than depending on using root containers for both.

This will likely explode done as is...

First, grub.cfg is not writable anymore:
https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/11305545275#L170

I'm not sure what 'user' gets remapped to here, but the whole container is running under rootless podman, as gitlab-runner user. Files on the host are owned by gitlab-runner user.

But second, repacking initrd as non-root, without any extra care will result in broken initrd. At the very least /sbin/mount is suid root - when repacked as normal user, it will end up as suid to non-root, breaking it quite effectively. I've run into this issue when needing to repack rootfs anyway and ended up using fakeroot (again):
https://gitlab.com/xen-project/people/marmarek/xen/-/commit/bab939159127a9f8e56e119c1fa553c7bbb6d4f7

Quoted 3 lines

At least your "CI: Create initrd fragments explicitly as root" patch may need backporting, but TBH I'm not sure if that's enough. /dev will likely be messed up too.

There's a lot of collateral damage here.  Summarising things a little.

* We cannot change the root-ness of alpine/3.18-arm64v8.  Like xilinx-xenial, it does need root to drive real hardware

* We can change the root-ness of alpine/3.18.  It is only used as a build container, not a test container.

* Contrary to my previous analysis, we have backported the test-artefact CPIO work to 4.19, but not the build step CPIO archive.

And, what to do:

* We really do need to be rootless in the build containers.  Therefore I think we need to split alpine/3.18-arm64v8 in two, and when bumping to the next version is the obvious point to do this.  We should make a dedicated qubes container similar to xilinx-xenial, and separate it from the build step.

* I should see about backporting the build step CPIO archive.  I'm beginning to think that was an oversight of mine, because I didn't intend to end up with a split like this.  This should avoid the step causing us problems here.

* I'm very inclined to change the root-ness of alpine/3.18.  Testing suggests this is fine.

~Andrew

#3 lore raw
Quoted 51 lines · Andrew Cooper
Quoted 27 lines · Marek Marczykowski-Górecki
Quoted 10 lines · Andrew Cooper

Testing on staging-4.19 is hitting a reliable failure, caused by alpine/3.18 being a root build container, but debian/12-x86_64 being a non-root test container. Specifically, the test container can't copy XEN_PAGING_DIR and XEN_DUMP_DIR (both 700) from the build root in order to construct the initrd.

staging-4.20 and later do not repack the initrd in this way, so are not affected.

Switch both alpine containers to being non-root. This is still slightly fragile, but better than depending on using root containers for both.

This will likely explode done as is...

First, grub.cfg is not writable anymore:
https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/11305545275#L170

I'm not sure what 'user' gets remapped to here, but the whole container is running under rootless podman, as gitlab-runner user. Files on the host are owned by gitlab-runner user.

But second, repacking initrd as non-root, without any extra care will result in broken initrd. At the very least /sbin/mount is suid root - when repacked as normal user, it will end up as suid to non-root, breaking it quite effectively. I've run into this issue when needing to repack rootfs anyway and ended up using fakeroot (again):
https://gitlab.com/xen-project/people/marmarek/xen/-/commit/bab939159127a9f8e56e119c1fa553c7bbb6d4f7

Quoted 3 lines

At least your "CI: Create initrd fragments explicitly as root" patch may need backporting, but TBH I'm not sure if that's enough. /dev will likely be messed up too.

There's a lot of collateral damage here.  Summarising things a little.

* We cannot change the root-ness of alpine/3.18-arm64v8.  Like xilinx-xenial, it does need root to drive real hardware

* We can change the root-ness of alpine/3.18.  It is only used as a build container, not a test container.

* Contrary to my previous analysis, we have backported the test-artefact CPIO work to 4.19, but not the build step CPIO archive.

And, what to do:

* We really do need to be rootless in the build containers.  Therefore I think we need to split alpine/3.18-arm64v8 in two, and when bumping to the next version is the obvious point to do this.  We should make a dedicated qubes container similar to xilinx-xenial, and separate it from the build step.

Quoted 7 lines

* I should see about backporting the build step CPIO archive.  I'm beginning to think that was an oversight of mine, because I didn't intend to end up with a split like this.  This should avoid the step causing us problems here.

* I'm very inclined to change the root-ness of alpine/3.18.  Testing suggests this is fine.

To follow up here, backporting the remaining CPIO patches has resolved the issue.
https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/2032200270

~Andrew

#4 lore raw
In reply to Andrew Cooper
Quoted 28 lines · Andrew Cooper
Quoted 27 lines · Marek Marczykowski-Górecki
Quoted 10 lines · Andrew Cooper

Testing on staging-4.19 is hitting a reliable failure, caused by alpine/3.18 being a root build container, but debian/12-x86_64 being a non-root test container. Specifically, the test container can't copy XEN_PAGING_DIR and XEN_DUMP_DIR (both 700) from the build root in order to construct the initrd.

staging-4.20 and later do not repack the initrd in this way, so are not affected.

Switch both alpine containers to being non-root. This is still slightly fragile, but better than depending on using root containers for both.

This will likely explode done as is...

First, grub.cfg is not writable anymore:
https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/11305545275#L170

I'm not sure what 'user' gets remapped to here, but the whole container is running under rootless podman, as gitlab-runner user. Files on the host are owned by gitlab-runner user.

But second, repacking initrd as non-root, without any extra care will result in broken initrd. At the very least /sbin/mount is suid root - when repacked as normal user, it will end up as suid to non-root, breaking it quite effectively. I've run into this issue when needing to repack rootfs anyway and ended up using fakeroot (again):
https://gitlab.com/xen-project/people/marmarek/xen/-/commit/bab939159127a9f8e56e119c1fa553c7bbb6d4f7

Quoted 8 lines
Quoted 3 lines

At least your "CI: Create initrd fragments explicitly as root" patch may need backporting, but TBH I'm not sure if that's enough. /dev will likely be messed up too.

There's a lot of collateral damage here.  Summarising things a little.

* We cannot change the root-ness of alpine/3.18-arm64v8.  Like xilinx-xenial, it does need root to drive real hardware

Apologies for joining this thread late. I wanted to add that it is OK to separate containers intended to drive real hardware, such as xenial-xilinx, from regular build containers. For example, 3.18-arm64v8 could be moved out and used only in .adl-x86-64, similar to how xenial-xilinx is used only in .xilinx-arm64. Normal build jobs, such as alpine-3.18-gcc-arm64, could use a different container.

I suggest we rename 3.18-arm64v8 to something else and create a new 3.18-arm64v8 specifically for builds, to be used only in build jobs.

The renamed original 3.18-arm64v8, together with xenial-xilinx, could be moved under test-artifacts/ or another appropriate location, as they do not quite belong with the other build containers. This separation also aligns with the root/non-root distinction.