Skip to content

Commit 8c7099f

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. While come JSON libraries preserve object key order or allow repeats, there are many JSON libraries which do not (e.g. Python and JavaScript both parse JSON objects into hash tables). Using objects here reinforces the unimportance of ordering or repeated entries. 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], although it is not documented in draft 4 of the JSON Schema RFC [3]. [1]: #564 (comment) [2]: https://spacetelescope.github.io/understanding-json-schema/reference/object.html#properties [3]: https://tools.ietf.org/html/draft-zyp-json-schema-04 Signed-off-by: W. Trevor King <[email protected]>
1 parent 1c7c27d commit 8c7099f

File tree

4 files changed

+32
-35
lines changed

4 files changed

+32
-35
lines changed

config.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,17 @@ 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) rlimits is an array of [rlimits][setrlimit.3] that allows setting resource limits for a process inside the container.
113+
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.
114+
Valid key values are `RLIMIT_*` resources.
115+
POSIX [defines several][setrlimit.3], and [Linux][setrlimit.2-linux] and [Solaris][setrlimit.2-solaris] add additional, platform-specific resources.
116+
117+
For Linux-based systems, the process structure supports the following process-specific fields:
111118

112119
* **`capabilities`** (array of strings, OPTIONAL) capabilities is an array that specifies Linux capabilities that can be provided to the process inside the container.
113120
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).
117121
* **`apparmorProfile`** (string, OPTIONAL) apparmor profile specifies the name of the apparmor profile that will be used for the container.
118122
For more information about Apparmor, see [Apparmor documentation](https://wiki.ubuntu.com/AppArmor)
119123
* **`selinuxLabel`** (string, OPTIONAL) SELinux process label specifies the label with which the processes in a container are run.
@@ -167,9 +171,8 @@ _Note: For Solaris, uid and gid specify the uid and gid of the process inside th
167171
"CAP_KILL",
168172
"CAP_NET_BIND_SERVICE"
169173
],
170-
"rlimits": [
171-
{
172-
"type": "RLIMIT_NOFILE",
174+
"rlimits": {
175+
"RLIMIT_NOFILE": {
173176
"hard": 1024,
174177
"soft": 1024
175178
}
@@ -415,18 +418,16 @@ Here is a full example `config.json` for reference.
415418
"CAP_KILL",
416419
"CAP_NET_BIND_SERVICE"
417420
],
418-
"rlimits": [
419-
{
420-
"type": "RLIMIT_CORE",
421+
"rlimits": {
422+
"RLIMIT_CORE": {
421423
"hard": 1024,
422424
"soft": 1024
423425
},
424-
{
425-
"type": "RLIMIT_NOFILE",
426+
"RLIMIT_NOFILE": {
426427
"hard": 1024,
427428
"soft": 1024
428429
}
429-
],
430+
},
430431
"apparmorProfile": "acme_secure_profile",
431432
"selinuxLabel": "system_u:system_r:svirt_lxc_net_t:s0:c124,c675",
432433
"noNewPrivileges": true
@@ -738,6 +739,9 @@ Here is a full example `config.json` for reference.
738739
```
739740

740741
[container-namespace]: glossary.md#container-namespace
742+
[setrlimit.2-linux]: http://man7.org/linux/man-pages/man2/setrlimit.2.html
743+
[setrlimit.2-solaris]: http://docs.oracle.com/cd/E36784_01/html/E36872/setrlimit-2.html
744+
[setrlimit.3]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/setrlimit.html
741745
[go-environment]: https://golang.org/doc/install/source#environment
742746
[runtime-namespace]: glossary.md#runtime-namespace
743747
[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: 1 addition & 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 container.
4848
Capabilities []string `json:"capabilities,omitempty" platform:"linux"`
4949
// Rlimits specifies rlimit options to apply to the process.
50-
Rlimits []Rlimit `json:"rlimits,omitempty" platform:"linux"`
50+
Rlimits map[string]Rlimit `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.
@@ -197,8 +197,6 @@ type IDMapping struct {
197197

198198
// Rlimit type and restrictions
199199
type Rlimit 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)