Skip to content

Commit 5309d5b

Browse files
authored
Merge pull request #1111 from cgwalters/tmpfiles-sysusers
2 parents 1518855 + bf10e34 commit 5309d5b

File tree

16 files changed

+1211
-97
lines changed

16 files changed

+1211
-97
lines changed

Cargo.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ members = [
88
"blockdev",
99
"xtask",
1010
"tests-integration",
11-
"tmpfiles"
11+
"tmpfiles",
12+
"sysusers",
1213
]
1314
resolver = "2"
1415

hack/provision-derived.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,10 @@ d /var/roothome/buildinfo/content_manifests 0755 - - -
3737
f /var/roothome/buildinfo/content_manifests/content-sets.json 0644 - - -
3838
EOF
3939
fi
40+
41+
# And add missing sysusers.d entries
42+
if ! grep -q -r sudo /usr/lib/sysusers.d; then
43+
cat >/usr/lib/sysusers.d/bootc-sudo-workaround.conf <<'EOF'
44+
g sudo 16
45+
EOF
46+
fi

lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ anyhow = { workspace = true }
1919
bootc-utils = { path = "../utils" }
2020
bootc-blockdev = { path = "../blockdev" }
2121
bootc-tmpfiles = { path = "../tmpfiles" }
22+
bootc-sysusers = { path = "../sysusers" }
2223
camino = { workspace = true, features = ["serde1"] }
2324
ostree-ext = { path = "../ostree-ext", features = ["bootc"] }
2425
chrono = { workspace = true, features = ["serde"] }

lib/src/lints.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::fmt::Write as WriteFmt;
1111
use std::os::unix::ffi::OsStrExt;
1212

1313
use anyhow::Result;
14+
use bootc_utils::PathQuotedDisplay;
1415
use camino::{Utf8Path, Utf8PathBuf};
1516
use cap_std::fs::Dir;
1617
use cap_std_ext::cap_std;
@@ -505,8 +506,58 @@ fn check_var_tmpfiles(_root: &Dir) -> LintResult {
505506
bootc_utils::iterator_split_nonempty_rest_count(r.unsupported.iter(), 5)
506507
{
507508
msg.push_str("Found non-directory/non-symlink files in /var:\n");
509+
for elt in samples.map(PathQuotedDisplay::new) {
510+
writeln!(msg, " {elt}")?;
511+
}
512+
if rest > 0 {
513+
writeln!(msg, " ...and {} more", rest)?;
514+
}
515+
}
516+
lint_err(msg)
517+
}
518+
519+
#[distributed_slice(LINTS)]
520+
static LINT_SYSUSERS: Lint = Lint {
521+
name: "sysusers",
522+
ty: LintType::Warning,
523+
description: indoc! { r#"
524+
Check for users in /etc/passwd and groups in /etc/group that do not have corresponding
525+
systemd sysusers.d entries in /usr/lib/sysusers.d.
526+
This can cause a problem across upgrades because if /etc is not transient and is locally
527+
modified (commonly due to local user additions), then the contents of /etc/passwd in the new container
528+
image may not be visible.
529+
530+
Using systemd-sysusers to allocate users and groups will ensure that these are allocated
531+
on system startup alongside other users.
532+
533+
More on this topic in <https://containers.github.io/bootc/building/users-and-groups.html>
534+
"#},
535+
f: check_sysusers,
536+
root_type: None,
537+
};
538+
fn check_sysusers(rootfs: &Dir) -> LintResult {
539+
let r = bootc_sysusers::analyze(rootfs)?;
540+
if r.is_empty() {
541+
return lint_ok();
542+
}
543+
let mut msg = String::new();
544+
if let Some((samples, rest)) =
545+
bootc_utils::iterator_split_nonempty_rest_count(r.missing_users.iter(), 5)
546+
{
547+
msg.push_str("Found /etc/passwd entry without corresponding systemd sysusers.d:\n");
508548
for elt in samples {
509-
writeln!(msg, " {elt:?}")?;
549+
writeln!(msg, " {elt}")?;
550+
}
551+
if rest > 0 {
552+
writeln!(msg, " ...and {} more", rest)?;
553+
}
554+
}
555+
if let Some((samples, rest)) =
556+
bootc_utils::iterator_split_nonempty_rest_count(r.missing_groups.iter(), 5)
557+
{
558+
msg.push_str("Found /etc/group entry without corresponding systemd sysusers.d:\n");
559+
for elt in samples {
560+
writeln!(msg, " {elt}")?;
510561
}
511562
if rest > 0 {
512563
writeln!(msg, " ...and {} more", rest)?;

sysusers/Cargo.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "bootc-sysusers"
3+
version = "0.1.0"
4+
license = "MIT OR Apache-2.0"
5+
edition = "2021"
6+
publish = false
7+
8+
[dependencies]
9+
anyhow = { workspace = true }
10+
camino = { workspace = true }
11+
fn-error-context = { workspace = true }
12+
cap-std-ext = { version = "4", features = ["fs_utf8"] }
13+
hex = "0.4"
14+
thiserror = { workspace = true }
15+
tempfile = { workspace = true }
16+
bootc-utils = { path = "../utils" }
17+
rustix = { workspace = true }
18+
uzers = "0.12"
19+
20+
[dev-dependencies]
21+
indoc = { workspace = true }
22+
similar-asserts = { workspace = true }
23+
24+
[lints]
25+
workspace = true

0 commit comments

Comments
 (0)