Skip to content

error: slice base-passwd_data: invalid content path: /usr/share/base-passwd/group.master #221

Closed

Description

@polarathene
$ chisel cut --release ubuntu-24.04 --root / base-passwd_data
25.34 error: slice base-passwd_data: invalid content path: /usr/share/base-passwd/group.master

https://github.com/canonical/chisel-releases/blob/fb99e66e3127c73b40e4269f475d292e119414e2/slices/base-passwd.yaml#L11

FROM alpine AS get-chisel
ARG CHISEL_VERSION=1.1.0
ARG TARGETARCH
ARG CHISEL_RELEASE="https://github.com/canonical/chisel/releases/download/v${CHISEL_VERSION}/chisel_v${CHISEL_VERSION}_linux_${TARGETARCH}.tar.gz"
# NOTE: `--no-same-owner` used as `chisel` release has ownership of `1001:128`
RUN wget -qO - "${CHISEL_RELEASE}" | tar -xz --no-same-owner -C /usr/local/bin chisel


FROM scratch AS chisel
# Copy over chisel binary and it's external dependency to `ca-certificates.crt`:
COPY --link --from=get-chisel /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --link --from=get-chisel /usr/local/bin/chisel /usr/local/bin/chisel
# Provision bash and make it the default shell for `RUN`:
RUN   [ "/usr/local/bin/chisel", "cut", "--release", "ubuntu-24.04", "--root", "/", "base-files_base", "bash_bins" ]
SHELL [ "/bin/bash", "-c" ]
# This fails:
RUN chisel cut --release ubuntu-24.04 --root / base-passwd_data

If the last line is replaced with the following, it would work:

WORKDIR /root-fs
RUN chisel cut --release ubuntu-24.04 --root /root-fs base-passwd_data

I'm not sure if other slices would be similarly affected by this failure for --root /, it is unclear why the slice only fails with --root /? It doesn't seem to be about any conflict with existing directories AFAIK, I have run chisel from a different path than /usr/local/bin/chisel (such as /chisel instead) but it still fails with this error.

NOTE: This same error for the affected slice was reported in June 2022 but was related to a relative --root (using --root ./ or --root . for relative path does not help however).

Activity

  1. letFunny commented on May 2, 2025

    @letFunny
    Collaborator

    Thanks for reporting this. It is an issue of how we handle the root being only a single slash (/) in the code. The fix is very simple, getting the testing to be comprehensive is going to be a bit more difficult but we are going to look into it.

  2. polarathene commented on May 2, 2025

    @polarathene
    Author

    I tried to reproduce a scenario I encountered at some point after reporting this issue, but was unsuccessful.

    I recall doing something where chisel populated /etc/passwd and /etc/group with FIXME instead of actual user/groups. I suppose a slice added the files with that content, but didn't mutate it. I think that was only the case with --root /, while --root /root-fs was fine.


    I wanted to add a new user without the extra weight of passwd_bins (or future adduser_bins slice).

    Using a separate stage to add and modify users/groups, then COPY to chisel stage
    FROM alpine AS base
    # Minimal version of these two files,
    # Users: `root` + `nobody` + `nonroot`, and extra `tty` + `staff` (base-files).
    COPY --link --from=gcr.io/distroless/static-debian12 /etc/passwd /etc/passwd
    COPY --link --from=gcr.io/distroless/static-debian12 /etc/group /etc/group
    RUN apk add shadow \
     && useradd --system --uid 500 --user-group --create-home --home /var/lib/clamav --shell /usr/sbin/nologin clamav
    
    # Use `chisel` here:
    FROM scratch
    COPY --link --from=base /etc/group /etc/group
    COPY --link --from=base /etc/passwd /etc/passwd

    That was based on my findings here when looking into how to best add new users.

    Embedding the files directly with custom user
    # NOTE: You can use build args within the file content if you need extra flexibility:
    ARG NEW_USER=clamav
    COPY <<HEREDOC /etc/passwd
    root:x:0:0:root:/root:/sbin/nologin
    nobody:x:65534:65534:nobody:/nonexistent:/sbin/nologin
    ${NEW_USER}:x:500:500:ClamAV:/var/lib/${NEW_USER}:/sbin/nologin
    HEREDOC
    
    COPY <<HEREDOC /etc/group
    root:x:0:
    nobody:x:65534:
    tty:x:5:
    ${NEW_USER}:x:500:
    HEREDOC
    
    # Optionally create home dir:
    RUN --mount=type=bind,from=busybox:latest,source=/bin,target=/bin \
        install --directory --mode 2775 --owner clamav --group clamav /var/lib/clamav
    Append to files directly via shell commands
    # clamav:clamav (user:group => 500:500)
    echo 'clamav:!::0:::::' >> /etc/shadow
    echo 'clamav:x:500:clamav' >> /etc/group
    echo 'clamav:x:500:500:ClamAV:/var/lib/clamav:/sbin/nologin' >> /etc/passwd
    # Optionally create a home dir:
    install --directory --mode 2775 --owner clamav --group clamav /var/lib/clamav

    I suppose another approach (beyond external files with ADD/COPY) is a custom slice, but presently that's a bit more to support due to how --release works with custom slices requiring a full clone to overlay onto a release channel 😅

  3. upils commented on Mar 2, 2026

    @upils
    Collaborator

    Closing as solved by #224

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions