Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/kiri-init/src/linux/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,18 @@ fn finish_child(p: &Prepared, io: &ChildStdio, console: bool) -> ! {
}
.unwrap_or_else(|e| fail("seccomp", e));
let (uid, gid) = resolve_user(&p.user).unwrap_or_else(|e| fail("user", e));
// Docker creates a missing working directory (mkdir -p) as root, 0755,
// before it switches user, so a non-root container can still enter it
// (#370). A failure shows up as the chdir's error below.
if uid != 0 {
// SAFETY: `p.cwd` is a NUL-terminated path we own.
if unsafe { libc::access(p.cwd.as_ptr(), libc::F_OK) } != 0 {
use std::os::unix::fs::DirBuilderExt;
// SAFETY: the bytes came from a &str, so they are valid UTF-8.
let dir = unsafe { std::ffi::OsStr::from_encoded_bytes_unchecked(p.cwd.as_bytes()) };
let _ = fs::DirBuilder::new().recursive(true).mode(0o755).create(dir);
}
}
// The user's /etc/group memberships and --group-add, as Docker gives them.
let groups = super::hostopts::supplementary_groups(&p.user, uid, &p.host.groups).unwrap_or_else(|e| fail("groups", e));
give_stdio([0, 1, 2], uid).unwrap_or_else(|e| fail("stdio", e));
Expand Down
4 changes: 3 additions & 1 deletion crates/kiri/src/daemon/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,9 @@ pub(super) fn reference_matches(pattern: &str, name: &str) -> bool {

fn images(req: &Request, engine: &Engine) -> Result<Value, Error> {
let f = filters(req, &["reference", "dangling", "label"])?;
let list = engine.store.images()?;
let mut list = engine.store.images()?;
// Newest first, as Docker lists them (#364).
list.sort_by_key(|i| std::cmp::Reverse(time::parse_unix(&i.created)));
// Every stored image is tagged, so there are no dangling ones.
if f.bool("dangling") == Some(true) {
return Ok(json!([]));
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ t pull-alpine "alpine:latest" $D pull alpine:latest
t pull-busybox "busybox" $D pull busybox
t pull-tag "3.21" $D pull alpine:3.21
t images-list "alpine" $D images
# Newest first, as Docker lists them (#364).
t images-newest-first "sorted" bash -c "$D images --format '{{.CreatedAt}}' | sort -rc && echo sorted"
t image-inspect-arch "$($D version -f '{{.Server.Arch}}')" $D image inspect -f '{{.Architecture}}' alpine
t image-inspect-cmd "/bin/sh" $D image inspect -f '{{.Config.Cmd}}' alpine
code pull-missing 1 $D pull kiri-does-not-exist/nope:none
Expand Down Expand Up @@ -130,6 +132,9 @@ t env "bar" $D run --rm -e FOO=bar alpine sh -c 'echo $FOO'
t env-image "PATH=/usr/local/sbin" $D run --rm alpine env
t workdir "/tmp" $D run --rm -w /tmp alpine pwd
t workdir-created "/made/here" $D run --rm -w /made/here alpine pwd
# A non-root user gets the missing directory too, made by root as 0755 (#370).
t workdir-created-nonroot "/made/for/1000" $D run --rm -u 1000:1000 -w /made/for/1000 alpine pwd
t workdir-created-nonroot-mode "755 root" $D run --rm -u 1000:1000 -w /made/x alpine stat -c '%a %U' /made/x
t user-numeric "uid=1000" $D run --rm -u 1000 alpine id
t user-name "uid=70(postgres)" $D run --rm -u postgres postgres:17-alpine id
t user-group "gid=0(root)" $D run --rm -u 1000:0 alpine id
Expand Down