Unprivileged chroot() and Outrun
Unprivileged chroot() and Outrun
Posted Mar 16, 2021 7:52 UTC (Tue) by smurf (subscriber, #17840)In reply to: Unprivileged chroot() and Outrun by mcon147
Parent article: Unprivileged chroot()
There's no way to do that without chroot.
Posted Mar 16, 2021 19:07 UTC (Tue)
by floppus (guest, #137245)
[Link] (7 responses)
logfile = fopen("foo.log", "a");
Posted Mar 17, 2021 10:09 UTC (Wed)
by smurf (subscriber, #17840)
[Link] (5 responses)
Posted Mar 17, 2021 17:39 UTC (Wed)
by floppus (guest, #137245)
[Link] (4 responses)
Posted Mar 18, 2021 1:03 UTC (Thu)
by pabs (subscriber, #43278)
[Link] (3 responses)
Posted Mar 18, 2021 12:54 UTC (Thu)
by domenpk (guest, #12382)
[Link] (2 responses)
Posted Mar 27, 2021 18:54 UTC (Sat)
by l0kod (subscriber, #111864)
[Link] (1 responses)
Posted Apr 6, 2021 19:28 UTC (Tue)
by immibis (subscriber, #105511)
[Link]
Posted Mar 17, 2021 22:39 UTC (Wed)
by NYKevin (subscriber, #129325)
[Link]
1. You have to set up uid_map and gid_map if you want to interact with the filesystem. Since you are using chroot(), you almost certainly do want to interact with the filesystem, so this is an obvious source of friction. Not impossible, just annoying.
Unprivileged chroot() and Outrun
sqlite3_open("foo.db", &db);
sprintf(rootdir, "/run/user/%d/my-jail", getuid());
chdir(rootdir);
unshare(CLONE_NEWUSER);
chroot(".");
caps = cap_get_proc();
cap_clear(caps);
cap_set_proc(caps);
Unprivileged chroot() and Outrun
Unprivileged chroot() and Outrun
Unprivileged chroot() and Outrun
Unprivileged chroot() and Outrun
Unprivileged chroot() and Outrun
Unprivileged chroot() and Outrun
Unprivileged chroot() and Outrun
2. Assuming you don't have CAP_SETUID/GID (in the parent user namespace), which is a safe assumption because otherwise you wouldn't be asking for "unprivileged chroot" in the first place, then the man page appears to say that you can only map your own UID/GID. That certainly makes logical sense (the whole point of this operation is to give you a "containerized" or unprivileged CAP_SETUID, so we need to constrain it somehow), but it also means that stat(2) will lie to you about the ownership of any file you don't own (the UID/GID is unmapped, so it gets converted to a generic "don't know" value in the child namespace).
3. SCM_CREDENTIALS will also produce unmapped garbage, as will plenty of other UID/GID-related interfaces. If you want to IPC with any process owned by a different user (e.g. a daemon running under a role account), you basically can't confirm its identity, although it can confirm yours (which may be sufficient in some cases).
4. Pervasively fixing all of the above, testing it, and maintaining everything, is likely harder than just granting CAP_SYS_CHROOT in the first place.