-
Notifications
You must be signed in to change notification settings - Fork 168
WIP: Fallback to running system's auth.json #1934
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,27 +12,31 @@ | |
| # <verify new bound images are pulled> | ||
| # <reboot> | ||
| # <verify booted state> | ||
| # | ||
| # This test also verifies that authenticated LBIs work in two scenarios: | ||
| # 1. Auth credentials stored in the image itself | ||
| # 2. Auth credentials stored on the running system | ||
| # | ||
| # The test uses cstor-dist to serve images from containers-storage via an | ||
| # authenticated OCI registry endpoint. | ||
|
|
||
| use std assert | ||
| use tap.nu | ||
| use bootc_testlib.nu [CSTOR_DIST_REGISTRY, start_cstor_dist, get_cstor_auth, setup_insecure_registry, setup_system_auth] | ||
|
|
||
| # This code runs on *each* boot. | ||
| bootc status | ||
| let st = bootc status --json | from json | ||
| let booted = $st.status.booted.image | ||
|
|
||
| # The tests here aren't fetching from a registry which requires auth by default, | ||
| # but we can replicate the failure in https://github.com/bootc-dev/bootc/pull/1852 | ||
| # by just injecting any auth file. | ||
| echo '{}' | save -f /run/ostree/auth.json | ||
|
|
||
| def initial_setup [] { | ||
| bootc image copy-to-storage | ||
| podman images | ||
| podman image inspect localhost/bootc | from json | ||
| } | ||
|
|
||
| def build_image [name images containers] { | ||
| # Build an image with optional auth.json baked in | ||
| def build_image [name images containers --with-auth] { | ||
| let td = mktemp -d | ||
| cd $td | ||
| mkdir usr/share/containers/systemd | ||
|
|
@@ -59,6 +63,16 @@ RUN echo sanity check > /usr/share/bound-image-sanity-check.txt | |
| } | ||
| } | ||
|
|
||
| # Optionally bake auth.json into the image | ||
| if $with_auth { | ||
| let cstor = get_cstor_auth | ||
| print "Baking auth.json into the image" | ||
| mkdir etc/ostree | ||
| let auth_json = $'{"auths": {"($cstor.registry)": {"auth": "($cstor.auth_b64)"}}}' | ||
| echo $auth_json | save etc/ostree/auth.json | ||
| echo "COPY etc/ /etc/\n" | save Dockerfile --append | ||
| } | ||
|
|
||
| # Build it | ||
| podman build -t $name . | ||
| # Just sanity check it | ||
|
|
@@ -74,12 +88,13 @@ def verify_images [images containers] { | |
| let image_names = podman --storage-opt=additionalimagestore=/usr/lib/bootc/storage images --format json | from json | select -i Names | ||
|
|
||
| for $image in $bound_images { | ||
| let found = $image_names | where Names == [$image.image] | ||
| # Check if the expected image name is IN the Names array (not exact match) | ||
| let found = $image_names | where { |row| $image.image in $row.Names } | ||
| assert (($found | length) > 0) $"($image.image) not found" | ||
| } | ||
|
|
||
| for $container in $bound_containers { | ||
| let found = $image_names | where Names == [$container.image] | ||
| let found = $image_names | where { |row| $container.image in $row.Names } | ||
| assert (($found | length) > 0) $"($container.image) not found" | ||
| } | ||
| } | ||
|
|
@@ -89,18 +104,29 @@ def first_boot [] { | |
|
|
||
| initial_setup | ||
|
|
||
| # build a bootc image that includes bound images | ||
| # Start cstor-dist for authenticated LBI testing | ||
| start_cstor_dist | ||
| setup_insecure_registry | ||
|
|
||
| # Set up auth on running system for the switch operation | ||
| # The image will also have auth baked in - both should work | ||
| setup_system_auth | ||
|
|
||
| # Build a bootc image that includes bound images | ||
| # Include an authenticated LBI from cstor-dist with auth baked into the image | ||
| let images = [ | ||
| { "bound": true, "image": "registry.access.redhat.com/ubi9/ubi-minimal:9.4", "name": "ubi-minimal" }, | ||
| { "bound": false, "image": "quay.io/centos-bootc/centos-bootc:stream9", "name": "centos-bootc" } | ||
| { "bound": false, "image": "quay.io/centos-bootc/centos-bootc:stream9", "name": "centos-bootc" }, | ||
| { "bound": true, "image": $"($CSTOR_DIST_REGISTRY)/docker.io/library/alpine:latest", "name": "cstor-alpine" } | ||
| ] | ||
|
|
||
| let containers = [{ | ||
| "bound": true, "image": "docker.io/library/alpine:latest", "name": "alpine" | ||
| "bound": true, "image": "docker.io/library/alpine:latest", "name": "alpine" | ||
| }] | ||
|
|
||
| let image_name = "localhost/bootc-bound" | ||
| build_image $image_name $images $containers | ||
| print "Building image WITH auth.json baked in (tests auth from image)" | ||
| build_image $image_name $images $containers --with-auth | ||
| bootc switch --transport containers-storage $image_name | ||
| verify_images $images $containers | ||
| tmt-reboot | ||
|
|
@@ -111,21 +137,39 @@ def second_boot [] { | |
| assert equal $booted.image.transport containers-storage | ||
| assert equal $booted.image.image localhost/bootc-bound | ||
|
|
||
| # verify images are still there after boot | ||
| # Start cstor-dist again (container doesn't survive reboot) | ||
| start_cstor_dist | ||
| setup_insecure_registry | ||
|
|
||
| # Set up auth on the RUNNING SYSTEM for the upgrade | ||
| # The new image will NOT have auth baked in, so the fallback to system auth is needed | ||
| setup_system_auth | ||
|
|
||
| # Verify images from first switch are still there | ||
| let images = [ | ||
| { "bound": true, "image": "registry.access.redhat.com/ubi9/ubi-minimal:9.4", "name": "ubi-minimal" }, | ||
| { "bound": false, "image": "quay.io/centos-bootc/centos-bootc:stream9", "name": "centos-bootc" } | ||
| { "bound": false, "image": "quay.io/centos-bootc/centos-bootc:stream9", "name": "centos-bootc" }, | ||
| { "bound": true, "image": $"($CSTOR_DIST_REGISTRY)/docker.io/library/alpine:latest", "name": "cstor-alpine" } | ||
| ] | ||
|
|
||
| let containers = [{ | ||
| "bound": true, "image": "docker.io/library/alpine:latest", "name": "alpine" | ||
| "bound": true, "image": "docker.io/library/alpine:latest", "name": "alpine" | ||
| }] | ||
| verify_images $images $containers | ||
|
|
||
| # build a new bootc image with an additional bound image | ||
| # Build a NEW bootc image WITHOUT auth baked in | ||
| # Add a DIFFERENT authenticated LBI (busybox instead of alpine) | ||
| # This tests that auth from the running system works (the fallback fix) | ||
| print "bootc upgrade with another bound image" | ||
| let image_name = "localhost/bootc-bound" | ||
| let more_images = $images | append [{ "bound": true, "image": "registry.access.redhat.com/ubi9/ubi-minimal:9.3", "name": "ubi-minimal-9-3" }] | ||
| let more_images = [ | ||
| { "bound": true, "image": "registry.access.redhat.com/ubi9/ubi-minimal:9.4", "name": "ubi-minimal" }, | ||
| { "bound": true, "image": "registry.access.redhat.com/ubi9/ubi-minimal:9.3", "name": "ubi-minimal-9-3" }, | ||
| { "bound": false, "image": "quay.io/centos-bootc/centos-bootc:stream9", "name": "centos-bootc" }, | ||
| { "bound": true, "image": $"($CSTOR_DIST_REGISTRY)/docker.io/library/alpine:latest", "name": "cstor-alpine" }, | ||
| { "bound": true, "image": $"($CSTOR_DIST_REGISTRY)/docker.io/library/busybox:latest", "name": "cstor-busybox" } | ||
| ] | ||
|
Comment on lines
+165
to
+171
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve readability and reduce repetition, you can define |
||
| print "Building image WITHOUT auth.json (tests auth fallback from running system)" | ||
| build_image $image_name $more_images $containers | ||
| bootc upgrade | ||
| verify_images $more_images $containers | ||
|
|
@@ -137,14 +181,17 @@ def third_boot [] { | |
| assert equal $booted.image.transport containers-storage | ||
| assert equal $booted.image.image localhost/bootc-bound | ||
|
|
||
| # No need to start cstor-dist - we're just verifying the images are in storage | ||
| let images = [ | ||
| { "bound": true, "image": "registry.access.redhat.com/ubi9/ubi-minimal:9.4", "name": "ubi-minimal" }, | ||
| { "bound": true, "image": "registry.access.redhat.com/ubi9/ubi-minimal:9.3", "name": "ubi-minimal-9-3" }, | ||
| { "bound": false, "image": "quay.io/centos-bootc/centos-bootc:stream9", "name": "centos-bootc" } | ||
| { "bound": false, "image": "quay.io/centos-bootc/centos-bootc:stream9", "name": "centos-bootc" }, | ||
| { "bound": true, "image": $"($CSTOR_DIST_REGISTRY)/docker.io/library/alpine:latest", "name": "cstor-alpine" }, | ||
| { "bound": true, "image": $"($CSTOR_DIST_REGISTRY)/docker.io/library/busybox:latest", "name": "cstor-busybox" } | ||
| ] | ||
|
Comment on lines
185
to
191
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This list of images is identical to the For example, you could add a helper function: def get_final_images [] {
[
{ "bound": true, "image": "registry.access.redhat.com/ubi9/ubi-minimal:9.4", "name": "ubi-minimal" },
{ "bound": true, "image": "registry.access.redhat.com/ubi9/ubi-minimal:9.3", "name": "ubi-minimal-9-3" },
{ "bound": false, "image": "quay.io/centos-bootc/centos-bootc:stream9", "name": "centos-bootc" },
{ "bound": true, "image": $"($CSTOR_DIST_REGISTRY)/docker.io/library/alpine:latest", "name": "cstor-alpine" },
{ "bound": true, "image": $"($CSTOR_DIST_REGISTRY)/docker.io/library/busybox:latest", "name": "cstor-busybox" }
]
}Then you could use |
||
|
|
||
| let containers = [{ | ||
| "bound": true, "image": "docker.io/library/alpine:latest", "name": "alpine" | ||
| "bound": true, "image": "docker.io/library/alpine:latest", "name": "alpine" | ||
| }] | ||
|
|
||
| verify_images $images $containers | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
if let ... else if let ...chain can be simplified by combining the fallback logic into a singleelseblock, which makes the code slightly more concise.