Skip to content

Commit bde2aa9

Browse files
committed
config: Convert process.rlimits from an array to an object
Rlimits do not need either ordering or repeat entries for a single type. Using an object leans on the new wording from eeaccfa (glossary: Make objects explicitly unordered and forbid duplicate names, 2016-09-27, #584) to make both of those points explicit. Also add Solaris support. I'm not entirely clear on this, because while Solaris is POSIX-certified system and there is a Solaris man page for setrlimit, Abhijeeth claims no Solaris support for rlimits [1]. The additionalProperties object bit comes from [2,3], although it is not documented in draft 4 of the JSON Schema RFC [4]. [1]: #564 (comment) [2]: https://spacetelescope.github.io/understanding-json-schema/reference/object.html#properties [3]: https://tools.ietf.org/html/draft-wright-json-schema-validation-00#section-5.18 [4]: https://tools.ietf.org/html/draft-zyp-json-schema-04 Signed-off-by: W. Trevor King <[email protected]>
1 parent 81888fe commit bde2aa9

File tree

4 files changed

+37
-36
lines changed

4 files changed

+37
-36
lines changed

config.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,21 @@ See links for details about [mountvol](http://ss64.com/nt/mountvol.html) and [Se
107107
The executable is the first element and MUST be available at the given path inside of the rootfs.
108108
If the executable path is not an absolute path then the search $PATH is interpreted to find the executable.
109109

110-
For Linux-based systems the process structure supports the following process specific fields:
110+
For Linux and Solaris systems, the process structure supports the following process-specific fields:
111+
112+
* **`rlimits`** (object, OPTIONAL) configures [rlimits][setrlimit.3] for the container process.
113+
Valid keys are `RLIMIT_*` resources.
114+
POSIX [defines several][setrlimit.3], and [Linux][setrlimit.2-linux] and [Solaris][setrlimit.2-solaris] add additional, platform-specific resources.
115+
Values have the following properties:
116+
117+
* **`soft`** (uint64, OPTIONAL) The current limit on the resource.
118+
* **`hard`** (uint64, OPTIONAL) The ceiling for soft limts going forward.
119+
Only a process with appropriate privileges can raise a hard limit.
120+
121+
For Linux-based systems, the process structure supports the following process-specific fields:
111122

112123
* **`capabilities`** (array of strings, OPTIONAL) capabilities is an array that specifies Linux capabilities that can be provided to the process inside the container.
113124
Valid values are the strings for capabilities defined in [the man page](http://man7.org/linux/man-pages/man7/capabilities.7.html)
114-
* **`rlimits`** (array of rlimits, OPTIONAL) rlimits is an array of rlimits that allows setting resource limits for a process inside the container.
115-
The kernel enforces the `soft` limit for a resource while the `hard` limit acts as a ceiling for that value that could be set by an unprivileged process.
116-
Valid values for the 'type' field are the resources defined in [the man page](http://man7.org/linux/man-pages/man2/setrlimit.2.html).
117125
* **`apparmorProfile`** (string, OPTIONAL) apparmor profile specifies the name of the apparmor profile that will be used for the container.
118126
For more information about Apparmor, see [Apparmor documentation](https://wiki.ubuntu.com/AppArmor)
119127
* **`selinuxLabel`** (string, OPTIONAL) SELinux process label specifies the label with which the processes in a container are run.
@@ -167,9 +175,8 @@ _Note: For Solaris, uid and gid specify the uid and gid of the process inside th
167175
"CAP_KILL",
168176
"CAP_NET_BIND_SERVICE"
169177
],
170-
"rlimits": [
171-
{
172-
"type": "RLIMIT_NOFILE",
178+
"rlimits": {
179+
"RLIMIT_NOFILE": {
173180
"hard": 1024,
174181
"soft": 1024
175182
}
@@ -415,18 +422,16 @@ Here is a full example `config.json` for reference.
415422
"CAP_KILL",
416423
"CAP_NET_BIND_SERVICE"
417424
],
418-
"rlimits": [
419-
{
420-
"type": "RLIMIT_CORE",
425+
"rlimits": {
426+
"RLIMIT_CORE": {
421427
"hard": 1024,
422428
"soft": 1024
423429
},
424-
{
425-
"type": "RLIMIT_NOFILE",
430+
"RLIMIT_NOFILE": {
426431
"hard": 1024,
427432
"soft": 1024
428433
}
429-
],
434+
},
430435
"apparmorProfile": "acme_secure_profile",
431436
"selinuxLabel": "system_u:system_r:svirt_lxc_net_t:s0:c124,c675",
432437
"noNewPrivileges": true
@@ -738,6 +743,9 @@ Here is a full example `config.json` for reference.
738743
```
739744

740745
[container-namespace]: glossary.md#container-namespace
746+
[setrlimit.2-linux]: http://man7.org/linux/man-pages/man2/setrlimit.2.html
747+
[setrlimit.2-solaris]: http://docs.oracle.com/cd/E36784_01/html/E36872/setrlimit-2.html
748+
[setrlimit.3]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/setrlimit.html
741749
[go-environment]: https://golang.org/doc/install/source#environment
742750
[runtime-namespace]: glossary.md#runtime-namespace
743751
[uts-namespace]: http://man7.org/linux/man-pages/man7/namespaces.7.html

schema/config-schema.json

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,9 @@
133133
},
134134
"rlimits": {
135135
"id": "https://opencontainers.org/schema/bundle/linux/rlimits",
136-
"type": "array",
137-
"items": {
138-
"id": "https://opencontainers.org/schema/bundle/linux/rlimits/0",
139-
"type": "object",
140-
"properties": {
141-
"hard": {
142-
"id": "https://opencontainers.org/schema/bundle/linux/rlimits/0/hard",
143-
"$ref": "defs.json#/definitions/uint64"
144-
},
145-
"soft": {
146-
"id": "https://opencontainers.org/schema/bundle/linux/rlimits/0/soft",
147-
"$ref": "defs.json#/definitions/uint64"
148-
},
149-
"type": {
150-
"id": "https://opencontainers.org/schema/bundle/linux/rlimits/0/type",
151-
"type": "string",
152-
"pattern": "^RLIMIT_[A-Z]+$"
153-
}
154-
}
136+
"type": "object",
137+
"additionalProperties": {
138+
"$ref": "defs-linux.json#/definitions/Rlimit"
155139
}
156140
}
157141
}

schema/defs-linux.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@
7777
}
7878
}
7979
},
80+
"Rlimit": {
81+
"type": "object",
82+
"properties": {
83+
"hard": {
84+
"$ref": "defs.json#/definitions/uint64"
85+
},
86+
"soft": {
87+
"$ref": "defs.json#/definitions/uint64"
88+
}
89+
}
90+
},
8091
"Capability": {
8192
"description": "Linux process permissions",
8293
"type": "string",

specs-go/config.go

Lines changed: 2 additions & 4 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 container.
4848
Capabilities []string `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 map[string]LinuxRlimit `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.
@@ -195,10 +195,8 @@ type LinuxIDMapping struct {
195195
Size uint32 `json:"size"`
196196
}
197197

198-
// LinuxRlimit type and restrictions
198+
// LinuxRlimit resource limitations
199199
type LinuxRlimit struct {
200-
// Type of the rlimit to set
201-
Type string `json:"type"`
202200
// Hard is the hard limit for the specified type
203201
Hard uint64 `json:"hard"`
204202
// Soft is the soft limit for the specified type

0 commit comments

Comments
 (0)