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

lint: Add a sysusers lint #1111

Merged
merged 10 commits into from
Feb 20, 2025
Merged

Conversation

cgwalters
Copy link
Collaborator

tmpfiles: Drop an unused file

This was a copy-pasteo.

Signed-off-by: Colin Walters walters@verbum.org


hack: Add missing sysusers.d entry for sudo

TODO add this to the base image

Signed-off-by: Colin Walters walters@verbum.org


sysusers: New stub crate

Signed-off-by: Colin Walters walters@verbum.org


sysusers: Import nameservice code from rpm-ostree

This imports the code from
https://github.com/coreos/rpm-ostree/tree/main/rust/src/nameservice
as of commit
coreos/rpm-ostree@e1d43ae

Signed-off-by: Colin Walters walters@verbum.org


sysusers: Add analysis support

Signed-off-by: Colin Walters walters@verbum.org


lint: Add a sysusers lint

This is not exhaustive yet, but catches things that invoke
useradd (whether a dpkg/rpm %post or just a plain RUN useradd in a container)
that don't have a sysusers.d entry.

Signed-off-by: Colin Walters walters@verbum.org


@cgwalters
Copy link
Collaborator Author

OK here's an initial pass at a sysusers analysis. And of course it turns out our default c9s base image has a missing one:

[2/2] STEP 10/10: RUN bootc container lint --fatal-warnings
Lint warning: sysusers: Found /etc/group entry without corresponding systemd sysusers.d:
  "sudo"

I need to dig in to that one...

But here's a better demo showing both tmpfiles.d and sysusers.d lints working together:

$ cat Dockerfile
FROM localhost/bootc
RUN <<EORUN
set -xeuo pipefail
useradd someuser
groupadd someothergroup
bootc container lint
EORUN
$ podman build -t localhost/test .
STEP 1/2: FROM localhost/bootc
STEP 2/2: RUN <<EORUN (set -xeuo pipefail...)
+ useradd someuser
Creating mailbox file: No such file or directory
+ groupadd someothergroup
+ bootc container lint
Lint warning: sysusers: Found /etc/passwd entry without corresponding systemd sysusers.d:
  someuser
Found /etc/group entry without corresponding systemd sysusers.d:
  "someothergroup"
  "someuser"

Lint warning: var-tmpfiles: Found content in /var missing systemd tmpfiles.d entries:
  d /var/home/someuser 0700 someuser someuser - -
Found non-directory/non-symlink files in /var:
  "var/home/someuser/.bash_profile"
  "var/home/someuser/.bash_logout"
  "var/home/someuser/.bashrc"

Checks passed: 8
Checks skipped: 1
Warnings: 2
COMMIT localhost/test
--> 7f5dbb635478
Successfully tagged localhost/test:latest

@cgwalters
Copy link
Collaborator Author

There's quite a bit more here; a big thing we need to lint against is the case of floating users that own files in the image.

@cgwalters cgwalters force-pushed the tmpfiles-sysusers branch 4 times, most recently from 25e9cf6 to 5186bc0 Compare February 14, 2025 01:02
@cgwalters cgwalters changed the title Tmpfiles sysusers lint: Add a sysusers lint Feb 14, 2025
@cgwalters
Copy link
Collaborator Author

cgwalters commented Feb 14, 2025

Lint warning: sysusers: Found /etc/group entry without corresponding systemd sysusers.d:
"sudo"

Wow. Some archaeology with git log -S sudo in fedora-coreos-config quickly turns up this commit:

coreos/fedora-coreos-config@685f213

So yeah we've just been cargo culting this thing forward because Container Linux had it, it doesn't exist by default in other Fedora derivatives AFAICS...

Edit: Filed https://gitlab.com/fedora/bootc/base-images/-/issues/41

In the interest of cleanliness.

Signed-off-by: Colin Walters <walters@verbum.org>
There's probably an equivalent of this somewhere in a crate, but
basically dealing with `&Path` and printing it is annoying because
we always end up with quotes around a path, even if it's UTF-8
without any spaces.

This takes a Path and displays it in a way that will be parsable
by a shell, and takes care not to emit quotes in the simple case
where a path has no shell metacharacters, just `/`, `.` and
alphanumerics.

Signed-off-by: Colin Walters <walters@verbum.org>
This was a copy-pasteo.

Signed-off-by: Colin Walters <walters@verbum.org>
TODO add this to the base image

Signed-off-by: Colin Walters <walters@verbum.org>
Signed-off-by: Colin Walters <walters@verbum.org>
Signed-off-by: Colin Walters <walters@verbum.org>
This is not exhaustive yet, but catches things that invoke
`useradd` (whether a dpkg/rpm `%post` or just a plain `RUN useradd` in a container)
that don't have a sysusers.d entry.

Signed-off-by: Colin Walters <walters@verbum.org>
On general principle; this fixes a test failure in the lint unit
tests which don't create /etc/passwd.

But also, someone might reasonably create an image this way.

Signed-off-by: Colin Walters <walters@verbum.org>
This is more readable.

Signed-off-by: Colin Walters <walters@verbum.org>
@cgwalters
Copy link
Collaborator Author

I think we can merge this one but the downside here is it will emit a warning on the current base image until we merge https://gitlab.com/fedora/bootc/base-images/-/merge_requests/94

@jmarrero jmarrero enabled auto-merge February 14, 2025 20:57
Copy link
Contributor

@jmarrero jmarrero left a comment

Choose a reason for hiding this comment

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

lgtm

@jmarrero jmarrero merged commit 5309d5b into bootc-dev:main Feb 20, 2025
23 checks passed
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.

2 participants