userdb: define new 64K "foreign UID" range (#35932)
This is establish the basic concepts for #35685, in the hope to get this merged first. This defines a special, fixed 64K UID range that is supposed to be used by directory container images on disk, that is mapped to a dynamic UID range at runtime (via idmapped mounts). This enables a world where each container can run with a dynamic UID range, but this in no way leaks onto the disk, thus making supposedly dynamic, transient UID range assignments persistent. This is infrastructure later used for the primary part of #35685: unpriv container execution with directory images inside user's home dirs, that are assigned to this special "foreign UID range". This PR only defines the ranges, synthesizes NSS records for them via userdb, and then exposes them in a new "systemd-dissect --shift" command that can re-chown a container directory tree into this range (and in fact any range). This comes with docs. But no tests. There are tests in #35685 that cover all this, but they are more comprehensive and also test nspawn's hook-up with this, hence are excluded from this PR.
This commit is contained in:
@@ -127,5 +127,5 @@ bool uid_for_system_journal(uid_t uid) {
|
||||
|
||||
/* Returns true if the specified UID shall get its data stored in the system journal. */
|
||||
|
||||
return uid_is_system(uid) || uid_is_dynamic(uid) || uid == UID_NOBODY || uid_is_container(uid);
|
||||
return uid_is_system(uid) || uid_is_dynamic(uid) || uid == UID_NOBODY || uid_is_container(uid) || uid_is_foreign(uid);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@ assert_cc((CONTAINER_UID_BASE_MAX & 0xFFFFU) == 0);
|
||||
#define CONTAINER_UID_MIN (CONTAINER_UID_BASE_MIN)
|
||||
#define CONTAINER_UID_MAX (CONTAINER_UID_BASE_MAX + 0xFFFFU)
|
||||
|
||||
assert_cc((FOREIGN_UID_BASE & 0xFFFFU) == 0);
|
||||
#define FOREIGN_UID_MIN (FOREIGN_UID_BASE)
|
||||
#define FOREIGN_UID_MAX (FOREIGN_UID_BASE + 0xFFFFU)
|
||||
|
||||
bool uid_is_system(uid_t uid);
|
||||
bool gid_is_system(gid_t gid);
|
||||
|
||||
@@ -31,6 +35,14 @@ static inline bool gid_is_container(gid_t gid) {
|
||||
return uid_is_container((uid_t) gid);
|
||||
}
|
||||
|
||||
static inline bool uid_is_foreign(uid_t uid) {
|
||||
return FOREIGN_UID_MIN <= uid && uid <= FOREIGN_UID_MAX;
|
||||
}
|
||||
|
||||
static inline bool gid_is_foreign(gid_t gid) {
|
||||
return uid_is_foreign((uid_t) gid);
|
||||
}
|
||||
|
||||
typedef struct UGIDAllocationRange {
|
||||
uid_t system_alloc_uid_min;
|
||||
uid_t system_uid_max;
|
||||
|
||||
Reference in New Issue
Block a user