Skip to content

test(container): assert OCI Config.User is unset in static-image checks#17621

Open
christopherco wants to merge 1 commit into
4.0from
chrco/static-image-no-config-user
Open

test(container): assert OCI Config.User is unset in static-image checks#17621
christopherco wants to merge 1 commit into
4.0from
chrco/static-image-no-config-user

Conversation

@christopherco
Copy link
Copy Markdown
Collaborator

@christopherco christopherco commented Jun 4, 2026

Add a shared static-image-checks test that fails if a container image's
OCI manifest declares an explicit Config.User (e.g. user="root" in the
kiwi ). An explicit user diverges from the unset default
used by AZL 3.0 and mainstream base images.

  • conftest: new session fixture oci_image_config returning the parsed
    skopeo inspect --config output.
  • extract: inspect_oci_config() helper using skopeo inspect --config
    (skopeo is already a declared container tool; no umoci needed).
  • cases/test_oci_config.py: shared test gated on the container
    capability via @pytest.mark.require_capability("container") (matching
    the existing test_packages.py convention) so it runs for every
    container image family and skips VM images. Asserts User is absent
    from the OCI config (an explicit empty string also fails).
  • images.toml: wire the three distroless images into static-image-checks
    with a container = true capability table so the new test covers them
    (package tests correctly skip — no runtime-package-management).

Fixes: AB#20622

@christopherco
Copy link
Copy Markdown
Collaborator Author

Corresponding OCI test fixtures and static test for #17619

@christopherco christopherco marked this pull request as ready for review June 4, 2026 04:35
Copilot AI review requested due to automatic review settings June 4, 2026 04:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a shared static-image-checks assertion for Azure Linux container images to ensure OCI config.User is not explicitly set, aligning container image metadata with AZL 3.0 and common base-image conventions. This expands the static test suite coverage to distroless container images and introduces a small helper to inspect OCI config without unpacking.

Changes:

  • Add inspect_oci_config() helper that runs skopeo inspect --config and parses the OCI config JSON.
  • Add a session-scoped oci_image_config fixture (container-only; cleanly skips for VM images) and a shared test validating Config.User is absent.
  • Wire distroless container images into static-image-checks and declare container capabilities (including runtime-package-management = false).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
base/images/tests/utils/extract.py Adds inspect_oci_config() helper to fetch OCI config JSON via skopeo.
base/images/tests/README.md Documents the new shared container test and the oci_image_config fixture.
base/images/tests/conftest.py Adds oci_image_config session fixture gated by image_type.
base/images/tests/cases/test_oci_config.py Introduces shared test asserting OCI config.User key is absent.
base/images/images.toml Enables static-image-checks and capability declarations for distroless container images.

Copy link
Copy Markdown
Member

@reubeno reubeno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the idea of the test! A couple of quick comments.

Comment thread base/images/images.toml
[images.container-distroless-minimal]
description = "Container Distroless Minimal Image"
definition = { type = "kiwi", path = "container-base/container-base.kiwi", profile = "distroless-minimal" }
tests.test-suites = [{ name = "static-image-checks" }]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the metadata updates here; their omission on the distroless containers was an oversight.

from __future__ import annotations


def test_no_explicit_config_user(oci_image_config: dict[str, object]) -> None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use a marker, e.g.: @pytest.mark.require_capability with an appropriate capability if there is one.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the container capability

Add a shared static-image-checks test that fails if a container image's
OCI manifest declares an explicit Config.User (e.g. user="root" in the
kiwi <containerconfig>). An explicit user diverges from the unset default
used by AZL 3.0 and mainstream base images.

- conftest: new session fixture `oci_image_config` returning the parsed
  `skopeo inspect --config` output.
- extract: `inspect_oci_config()` helper using `skopeo inspect --config`
  (skopeo is already a declared container tool; no umoci needed).
- cases/test_oci_config.py: shared test gated on the `container`
  capability via `@pytest.mark.require_capability("container")` (matching
  the existing test_packages.py convention) so it runs for every
  container image family and skips VM images. Asserts `User` is absent
  from the OCI config (an explicit empty string also fails).
- images.toml: wire the three distroless images into static-image-checks
  with a `container = true` capability table so the new test covers them
  (package tests correctly skip — no runtime-package-management).

Fixes: AB#20622

Signed-off-by: Chris Co <chrco@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@christopherco christopherco force-pushed the chrco/static-image-no-config-user branch from f84b96e to d344d8d Compare June 4, 2026 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants