Skip to content

Commit 5a8a779

Browse files
author
Michael Crosby
committed
Move process specific settings to process
This moves process specific settings like caps, apparmor, and selinux process label onto the process structure to allow the same settings to be changed at exec time. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
1 parent 95e1259 commit 5a8a779

File tree

4 files changed

+27
-54
lines changed

4 files changed

+27
-54
lines changed

config-linux.md

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@
33
The Linux container specification uses various kernel features like namespaces, cgroups, capabilities, LSM, and file system jails to fulfill the spec.
44
Additional information is needed for Linux over the [default spec configuration](config.md) in order to configure these various kernel features.
55

6-
## Capabilities
7-
8-
Capabilities is an array that specifies Linux capabilities that can be provided to the process inside the container.
9-
Valid values are the strings for capabilities defined in [the man page](http://man7.org/linux/man-pages/man7/capabilities.7.html)
10-
11-
```json
12-
"capabilities": [
13-
"CAP_AUDIT_WRITE",
14-
"CAP_KILL",
15-
"CAP_NET_BIND_SERVICE"
16-
]
17-
```
18-
196
## Default File Systems
207

218
The Linux ABI includes both syscalls and several special file paths.
@@ -486,28 +473,6 @@ The kernel enforces the `soft` limit for a resource while the `hard` limit acts
486473
]
487474
```
488475

489-
## SELinux process label
490-
491-
SELinux process label specifies the label with which the processes in a container are run.
492-
For more information about SELinux, see [Selinux documentation](http://selinuxproject.org/page/Main_Page)
493-
494-
###### Example
495-
496-
```json
497-
"selinuxProcessLabel": "system_u:system_r:svirt_lxc_net_t:s0:c124,c675"
498-
```
499-
500-
## Apparmor profile
501-
502-
Apparmor profile specifies the name of the apparmor profile that will be used for the container.
503-
For more information about Apparmor, see [Apparmor documentation](https://wiki.ubuntu.com/AppArmor)
504-
505-
###### Example
506-
507-
```json
508-
"apparmorProfile": "acme_secure_profile"
509-
```
510-
511476
## seccomp
512477

513478
Seccomp provides application sandboxing mechanism in the Linux kernel.
@@ -574,17 +539,6 @@ Its value is either slave, private, or shared.
574539
"rootfsPropagation": "slave",
575540
```
576541

577-
## No new privileges
578-
579-
Setting `noNewPrivileges` to true prevents the processes in the container from gaining additional privileges.
580-
[The kernel doc](https://www.kernel.org/doc/Documentation/prctl/no_new_privs.txt) has more information on how this is achieved using a prctl system call.
581-
582-
###### Example
583-
584-
```json
585-
"noNewPrivileges": true,
586-
```
587-
588542
[cgroup-v1]: https://www.kernel.org/doc/Documentation/cgroup-v1/cgroups.txt
589543
[cgroup-v1-blkio]: https://www.kernel.org/doc/Documentation/cgroup-v1/blkio-controller.txt
590544
[cgroup-v1-cpusets]: https://www.kernel.org/doc/Documentation/cgroup-v1/cpusets.txt

config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ type Process struct {
3333
// Cwd is the current working directory for the process and must be
3434
// relative to the container's root.
3535
Cwd string `json:"cwd"`
36+
// Capabilities are linux capabilities that are kept for the container.
37+
Capabilities []string `json:"capabilities,omitempty"`
38+
// ApparmorProfile specified the apparmor profile for the container.
39+
ApparmorProfile string `json:"apparmorProfile,omitempty"`
40+
// SelinuxProcessLabel specifies the selinux context that the container process is run as.
41+
SelinuxLabel string `json:"selinuxLabel,omitempty"`
42+
// NoNewPrivileges controls whether additional privileges could be gained by processes in the container.
43+
NoNewPrivileges bool `json:"noNewPrivileges,omitempty"`
3644
}
3745

3846
// Root contains information about the container's root filesystem on the host.

config.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ See links for details about [mountvol](http://ss64.com/nt/mountvol.html) and [Se
9090
* **`env`** (array of strings, optional) contains a list of variables that will be set in the process's environment prior to execution. Elements in the array are specified as Strings in the form "KEY=value". The left hand side must consist solely of letters, digits, and underscores `_` as outlined in [IEEE Std 1003.1-2001](http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html).
9191
* **`args`** (string, required) executable to launch and any flags as an array. The executable is the first element and must be available at the given path inside of the rootfs. If the executable path is not an absolute path then the search $PATH is interpreted to find the executable.
9292

93+
For Linux-based systemd the process structure supports the following process specific fields:
94+
95+
* **`capabilities`** (array of strings, optional) capabilities is an array that specifies Linux capabilities that can be provided to the process inside the container.
96+
Valid values are the strings for capabilities defined in [the man page](http://man7.org/linux/man-pages/man7/capabilities.7.html)
97+
* **`apparmorProfile`** (string, optional) apparmor profile specifies the name of the apparmor profile that will be used for the container.
98+
For more information about Apparmor, see [Apparmor documentation](https://wiki.ubuntu.com/AppArmor)
99+
* **`selinuxLabel`** (string, optional) SELinux process label specifies the label with which the processes in a container are run.
100+
For more information about SELinux, see [Selinux documentation](http://selinuxproject.org/page/Main_Page)
101+
* **`noNewPrivileges`** (bool, optional) setting `noNewPrivileges` to true prevents the processes in the container from gaining additional privileges.
102+
[The kernel doc](https://www.kernel.org/doc/Documentation/prctl/no_new_privs.txt) has more information on how this is achieved using a prctl system call.
103+
93104
The user for the process is a platform-specific structure that allows specific control over which user the process runs as.
94105
For Linux-based systems the user structure has the following fields:
95106

@@ -114,6 +125,14 @@ For Linux-based systems the user structure has the following fields:
114125
"cwd": "/root",
115126
"args": [
116127
"sh"
128+
],
129+
"apparmorProfile": "acme_secure_profile",
130+
"selinuxLabel": "system_u:system_r:svirt_lxc_net_t:s0:c124,c675",
131+
"noNewPrivileges": true,
132+
"capabilities": [
133+
"CAP_AUDIT_WRITE",
134+
"CAP_KILL",
135+
"CAP_NET_BIND_SERVICE"
117136
]
118137
}
119138
```

config_linux.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ type LinuxSpec struct {
1414

1515
// Linux contains platform specific configuration for linux based containers.
1616
type Linux struct {
17-
// Capabilities are linux capabilities that are kept for the container.
18-
Capabilities []string `json:"capabilities"`
1917
// UIDMapping specifies user mappings for supporting user namespaces on linux.
2018
UIDMappings []IDMapping `json:"uidMappings,omitempty"`
2119
// GIDMapping specifies group mappings for supporting user namespaces on linux.
@@ -35,16 +33,10 @@ type Linux struct {
3533
Namespaces []Namespace `json:"namespaces"`
3634
// Devices are a list of device nodes that are created for the container
3735
Devices []Device `json:"devices"`
38-
// ApparmorProfile specified the apparmor profile for the container.
39-
ApparmorProfile string `json:"apparmorProfile"`
40-
// SelinuxProcessLabel specifies the selinux context that the container process is run as.
41-
SelinuxProcessLabel string `json:"selinuxProcessLabel"`
4236
// Seccomp specifies the seccomp security settings for the container.
4337
Seccomp Seccomp `json:"seccomp"`
4438
// RootfsPropagation is the rootfs mount propagation mode for the container.
4539
RootfsPropagation string `json:"rootfsPropagation,omitempty"`
46-
// NoNewPrivileges controls whether additional privileges could be gained by processes in the container.
47-
NoNewPrivileges bool `json:"noNewPrivileges,omitempty"`
4840
}
4941

5042
// User specifies linux specific user and group information for the container's

0 commit comments

Comments
 (0)