nspawn: add new --rlimit= switch, and always set resource limits explicitly for our container payloads
This ensures we set the various resource limits of our container explicitly on each invocation so that we inherit less from our callers into the payload. By default resource limits are now set to the same values Linux generally passes to the host PID 1, thus minimizing needless differences between host and container environments. The limits are now also configurable using a new --rlimit= switch. This is preparation for teaching nspawn native OCI runtime support as OCI permits setting resource limits for container payloads, and it hence probably makes sense if we do too.
This commit is contained in:
@@ -32,24 +32,26 @@ typedef enum UserNamespaceMode {
|
||||
} UserNamespaceMode;
|
||||
|
||||
typedef enum SettingsMask {
|
||||
SETTING_START_MODE = 1 << 0,
|
||||
SETTING_ENVIRONMENT = 1 << 1,
|
||||
SETTING_USER = 1 << 2,
|
||||
SETTING_CAPABILITY = 1 << 3,
|
||||
SETTING_KILL_SIGNAL = 1 << 4,
|
||||
SETTING_PERSONALITY = 1 << 5,
|
||||
SETTING_MACHINE_ID = 1 << 6,
|
||||
SETTING_NETWORK = 1 << 7,
|
||||
SETTING_EXPOSE_PORTS = 1 << 8,
|
||||
SETTING_READ_ONLY = 1 << 9,
|
||||
SETTING_VOLATILE_MODE = 1 << 10,
|
||||
SETTING_CUSTOM_MOUNTS = 1 << 11,
|
||||
SETTING_WORKING_DIRECTORY = 1 << 12,
|
||||
SETTING_USERNS = 1 << 13,
|
||||
SETTING_NOTIFY_READY = 1 << 14,
|
||||
SETTING_PIVOT_ROOT = 1 << 15,
|
||||
SETTING_SYSCALL_FILTER = 1 << 16,
|
||||
_SETTINGS_MASK_ALL = (1 << 17) -1
|
||||
SETTING_START_MODE = UINT64_C(1) << 0,
|
||||
SETTING_ENVIRONMENT = UINT64_C(1) << 1,
|
||||
SETTING_USER = UINT64_C(1) << 2,
|
||||
SETTING_CAPABILITY = UINT64_C(1) << 3,
|
||||
SETTING_KILL_SIGNAL = UINT64_C(1) << 4,
|
||||
SETTING_PERSONALITY = UINT64_C(1) << 5,
|
||||
SETTING_MACHINE_ID = UINT64_C(1) << 6,
|
||||
SETTING_NETWORK = UINT64_C(1) << 7,
|
||||
SETTING_EXPOSE_PORTS = UINT64_C(1) << 8,
|
||||
SETTING_READ_ONLY = UINT64_C(1) << 9,
|
||||
SETTING_VOLATILE_MODE = UINT64_C(1) << 10,
|
||||
SETTING_CUSTOM_MOUNTS = UINT64_C(1) << 11,
|
||||
SETTING_WORKING_DIRECTORY = UINT64_C(1) << 12,
|
||||
SETTING_USERNS = UINT64_C(1) << 13,
|
||||
SETTING_NOTIFY_READY = UINT64_C(1) << 14,
|
||||
SETTING_PIVOT_ROOT = UINT64_C(1) << 15,
|
||||
SETTING_SYSCALL_FILTER = UINT64_C(1) << 16,
|
||||
SETTING_RLIMIT_FIRST = UINT64_C(1) << 17, /* we define one bit per resource limit here */
|
||||
SETTING_RLIMIT_LAST = UINT64_C(1) << (17 + _RLIMIT_MAX - 1),
|
||||
_SETTINGS_MASK_ALL = (UINT64_C(1) << (17 + _RLIMIT_MAX))
|
||||
} SettingsMask;
|
||||
|
||||
typedef struct Settings {
|
||||
@@ -71,6 +73,7 @@ typedef struct Settings {
|
||||
bool notify_ready;
|
||||
char **syscall_whitelist;
|
||||
char **syscall_blacklist;
|
||||
struct rlimit *rlimit[_RLIMIT_MAX];
|
||||
|
||||
/* [Image] */
|
||||
int read_only;
|
||||
|
||||
Reference in New Issue
Block a user