Skip to content

Commit b4d7fae

Browse files
committed
config: Make rlimits POSIX-specific
This property was initially Linux-specific. 718f9f3 (minor narrative cleanup regarding config compatibility, 2017-01-30, opencontainers#673) removed the Linux restriction, but the rlimit concept is from POSIX and Windows doesn't support it [1]. This commit adds new subsections for the POSIX-specific and Linux-specific process entries (to match the approach we currently use for process.user), and punts to POSIX for the Solaris values and compliance testing approach. If/when we get a Solaris-specific doc for valid values, we can replace the POSIX punt there, but we probably want to continue punting to POSIX for getrlimit(3)-based compliance testing. I've renamed the overly-specific LinuxRlimit to POSIXRlimit. We could use the generic Rlimit, but then we'd be stuck if/when Windows adds support for some rlimit-like thing that doesn't match up cleanly enough for us to use the POSIX structure. [1]: opencontainers#835 (comment) Signed-off-by: W. Trevor King <[email protected]>
1 parent 87f2861 commit b4d7fae

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

config.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,33 @@ For Solaris, the mount entry corresponds to the 'fs' resource in the [zonecfg(1M
130130
* **`env`** (array of strings, OPTIONAL) with the same semantics as [IEEE Std 1003.1-2001's `environ`][ieee-1003.1-2001-xbd-c8.1].
131131
* **`args`** (array of strings, REQUIRED) with similar semantics to [IEEE Std 1003.1-2001 `execvp`'s *argv*][ieee-1003.1-2001-xsh-exec].
132132
This specification extends the IEEE standard in that at least one entry is REQUIRED, and that entry is used with the same semantics as `execvp`'s *file*.
133-
* **`rlimits`** (array of objects, OPTIONAL) allows setting resource limits for a process inside the container.
134-
Each entry has the following structure:
135133

136-
* **`type`** (string, REQUIRED) - the platform resource being limited, for example on Linux as defined in the [setrlimit(2)][setrlimit.2] man page.
137-
* **`soft`** (uint64, REQUIRED) - the value of the limit enforced for the corresponding resource.
138-
* **`hard`** (uint64, REQUIRED) - the ceiling for the soft limit that could be set by an unprivileged process. Only a privileged process (e.g. under Linux: one with the CAP_SYS_RESOURCE capability) can raise a hard limit.
134+
### <a name="configLinuxAndSolarisProcess" />Linux and Solaris Process
139135

140-
If `rlimits` contains duplicated entries with same `type`, the runtime MUST error out.
136+
For POSIX-based systems (Linux and Solaris), the `process` object supports the following process-specific properties:
141137

138+
* **`rlimits`** (array of objects, OPTIONAL) allows setting resource limits for the process.
139+
Each entry has the following structure:
142140

143-
For Linux-based systems the process structure supports the following process-specific fields.
141+
* **`type`** (string, REQUIRED) the platform resource being limited.
142+
* Linux: valid values are defined in the [`getrlimit(2)`][setrlimit.2] man page, such as `RLIMIT_MSGQUEUE`.
143+
* Solaris: valid values are defined in the [`getrlimit(3)`][getrlimit.3] man page, such as `RLIMIT_CORE`.
144+
145+
The runtime MUST [generate an error](runtime.md#errors) for any values which cannot be mapped to a relevant kernel interface
146+
For each entry in `rlimits`, a [`getrlimit(3)`][getrlimit.3] on `type` MUST succeed.
147+
For the following properties, `rlim` refers to the status returned by the `getrlimit(3)` call.
148+
149+
* **`soft`** (uint64, REQUIRED) the value of the limit enforced for the corresponding resource.
150+
`rlim.rlim_cur` MUST match the configured value.
151+
* **`hard`** (uint64, REQUIRED) the ceiling for the soft limit that could be set by an unprivileged process.
152+
`rlim.rlim_max` MUST match the configured value.
153+
Only a privileged process (e.g. one with the `CAP_SYS_RESOURCE` capability) can raise a hard limit.
154+
155+
If `rlimits` contains duplicated entries with same `type`, the runtime MUST [generate an error](runtime.md#errors).
156+
157+
### <a name="configLinuxProcess" />Linux Process
158+
159+
For Linux-based systems, the `process` object supports the following process-specific properties.
144160

145161
* **`apparmorProfile`** (string, OPTIONAL) specifies the name of the AppArmor profile to be applied to processes in the container.
146162
For more information about AppArmor, see [AppArmor documentation][apparmor].
@@ -846,7 +862,8 @@ Here is a full example `config.json` for reference.
846862
[mount.8]: http://man7.org/linux/man-pages/man8/mount.8.html
847863
[mount.8-filesystem-independent]: http://man7.org/linux/man-pages/man8/mount.8.html#FILESYSTEM-INDEPENDENT_MOUNT%20OPTIONS
848864
[mount.8-filesystem-specific]: http://man7.org/linux/man-pages/man8/mount.8.html#FILESYSTEM-SPECIFIC_MOUNT%20OPTIONS
849-
[setrlimit.2]: http://man7.org/linux/man-pages/man2/setrlimit.2.html
865+
[getrlimit.2]: http://man7.org/linux/man-pages/man2/getrlimit.2.html
866+
[getrlimit.3]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getrlimit.html
850867
[stdin.3]: http://man7.org/linux/man-pages/man3/stdin.3.html
851868
[uts-namespace.7]: http://man7.org/linux/man-pages/man7/namespaces.7.html
852869
[zonecfg.1m]: https://docs.oracle.com/cd/E36784_01/html/E36871/zonecfg-1m.html

specs-go/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type Process struct {
4747
// Capabilities are Linux capabilities that are kept for the process.
4848
Capabilities *LinuxCapabilities `json:"capabilities,omitempty" platform:"linux"`
4949
// Rlimits specifies rlimit options to apply to the process.
50-
Rlimits []LinuxRlimit `json:"rlimits,omitempty" platform:"linux"`
50+
Rlimits []POSIXRlimit `json:"rlimits,omitempty" platform:"linux,solaris"`
5151
// NoNewPrivileges controls whether additional privileges could be gained by processes in the container.
5252
NoNewPrivileges bool `json:"noNewPrivileges,omitempty" platform:"linux"`
5353
// ApparmorProfile specifies the apparmor profile for the container.
@@ -215,8 +215,8 @@ type LinuxIDMapping struct {
215215
Size uint32 `json:"size"`
216216
}
217217

218-
// LinuxRlimit type and restrictions
219-
type LinuxRlimit struct {
218+
// POSIXRlimit type and restrictions
219+
type POSIXRlimit struct {
220220
// Type of the rlimit to set
221221
Type string `json:"type"`
222222
// Hard is the hard limit for the specified type

0 commit comments

Comments
 (0)