2015-07-07 08:35:32 +08:00
# Linux-specific configuration
2015-06-25 08:15:48 +08:00
2015-07-01 06:18:40 +08:00
The Linux container specification uses various kernel features like namespaces,
2015-07-07 08:35:32 +08:00
cgroups, capabilities, LSM, and file system jails to fulfill the spec.
Additional information is needed for Linux over the [default spec configuration ](config.md )
2015-07-01 06:18:40 +08:00
in order to configure these various kernel features.
2015-07-01 06:13:13 +08:00
## Linux namespaces
A namespace wraps a global system resource in an abstraction that makes it
appear to the processes within the namespace that they have their own isolated
instance of the global resource. Changes to the global resource are visible to
other processes that are members of the namespace, but are invisible to other
processes. For more information, see [the man page ](http://man7.org/linux/man-pages/man7/namespaces.7.html )
Namespaces are specified in the spec as an array of entries. Each entry has a
type field with possible values described below and an optional path element.
If a path is specified, that particular file is used to join that type of namespace.
2015-06-30 02:54:10 +08:00
```json
2015-06-25 08:15:48 +08:00
"namespaces": [
2015-06-28 07:19:27 +08:00
{
"type": "pid",
"path": "/proc/1234/ns/pid"
},
{
"type": "net",
"path": "/var/run/netns/neta"
},
{
"type": "mnt",
},
{
"type": "ipc",
},
{
"type": "uts",
},
{
"type": "user",
},
2015-06-30 02:54:10 +08:00
]
2015-06-25 08:15:48 +08:00
```
2015-07-01 06:13:13 +08:00
#### Namespace types
2015-06-25 08:15:48 +08:00
2015-07-01 06:13:13 +08:00
* **pid** processes inside the container will only be able to see other processes inside the same container.
* **network** the container will have it's own network stack.
* **mnt** the container will have an isolated mount table.
* **ipc** processes inside the container will only be able to communicate to other processes inside the same
container via system level IPC.
* **uts** the container will be able to have it's own hostname and domain name.
* **user** the container will be able to remap user and group IDs from the host to local users and groups
within the container.
2015-06-25 08:15:48 +08:00
2015-07-01 06:13:13 +08:00
### Access to devices
2015-06-25 08:15:48 +08:00
2015-08-06 06:25:15 +08:00
Devices is an array specifying the list of devices to be created in the container.
Next parameters can be specified:
* type - type of device: 'c', 'b', 'u' or 'p'. More info in `man mknod`
* path - full path to device inside container
* major, minor - major, minor numbers for device. More info in `man mknod` .
There is special value: `-1` , which means `*` for `device`
cgroup setup.
* permissions - cgroup permissions for device. A composition of 'r'
(read), 'w' (write), and 'm' (mknod).
* fileMode - file mode for device file
* uid - uid of device owner
* gid - gid of device owner
2015-06-25 12:14:35 +08:00
2015-06-30 02:54:10 +08:00
```json
"devices": [
2015-08-06 06:25:15 +08:00
{
"path": "/dev/random",
"type": "c",
"major": 1,
"minor": 8,
"permissions": "rwm",
"fileMode": 0666,
"uid": 0,
"gid": 0
},
{
"path": "/dev/urandom",
"type": "c",
"major": 1,
"minor": 9,
"permissions": "rwm",
"fileMode": 0666,
"uid": 0,
"gid": 0
},
{
"path": "/dev/null",
"type": "c",
"major": 1,
"minor": 3,
"permissions": "rwm",
"fileMode": 0666,
"uid": 0,
"gid": 0
},
{
"path": "/dev/zero",
"type": "c",
"major": 1,
"minor": 5,
"permissions": "rwm",
"fileMode": 0666,
"uid": 0,
"gid": 0
},
{
"path": "/dev/tty",
"type": "c",
"major": 5,
"minor": 0,
"permissions": "rwm",
"fileMode": 0666,
"uid": 0,
"gid": 0
},
{
"path": "/dev/full",
"type": "c",
"major": 1,
"minor": 7,
"permissions": "rwm",
"fileMode": 0666,
"uid": 0,
"gid": 0
}
2015-06-30 02:54:10 +08:00
]
```
2015-07-01 06:13:13 +08:00
## Linux control groups
2015-06-30 02:54:10 +08:00
2015-07-01 06:13:13 +08:00
Also known as cgroups, they are used to restrict resource usage for a container and handle
2015-07-01 06:18:40 +08:00
device access. cgroups provide controls to restrict cpu, memory, IO, and network for
2015-07-01 06:45:10 +08:00
the container. For more information, see the [kernel cgroups documentation ](https://www.kernel.org/doc/Documentation/cgroups/cgroups.txt )
2015-06-25 08:15:48 +08:00
2015-07-01 06:13:13 +08:00
## Linux capabilities
2015-06-25 08:15:48 +08:00
2015-07-01 06:13:13 +08:00
Capabilities is an array that specifies Linux capabilities that can be provided to the process
inside the container. Valid values are the string after `CAP_` for capabilities defined
in [the man page ](http://man7.org/linux/man-pages/man7/capabilities.7.html )
2015-06-25 08:15:48 +08:00
2015-06-30 02:54:10 +08:00
```json
2015-06-25 08:15:48 +08:00
"capabilities": [
"AUDIT_WRITE",
"KILL",
"NET_BIND_SERVICE"
2015-06-30 02:54:10 +08:00
]
2015-06-25 08:15:48 +08:00
```
2015-07-01 06:13:13 +08:00
## Linux sysctl
2015-06-25 08:15:48 +08:00
2015-07-02 01:03:17 +08:00
sysctl allows kernel parameters to be modified at runtime for the container.
2015-07-01 06:13:13 +08:00
For more information, see [the man page ](http://man7.org/linux/man-pages/man8/sysctl.8.html )
2015-06-27 02:20:17 +08:00
2015-07-26 16:08:26 +08:00
```json
2015-06-27 02:20:17 +08:00
"sysctl": {
"net.ipv4.ip_forward": "1",
"net.core.somaxconn": "256"
}
```
2015-07-01 06:02:58 +08:00
## Linux rlimits
2015-07-26 16:08:26 +08:00
```json
2015-07-01 06:02:58 +08:00
"rlimits": [
{
2015-07-01 10:25:46 +08:00
"type": "RLIMIT_NPROC",
2015-07-01 06:02:58 +08:00
"soft": 1024,
"hard": 102400
}
]
```
2015-07-01 10:25:46 +08:00
rlimits allow setting resource limits. The type is from the values defined in [the man page ](http://man7.org/linux/man-pages/man2/setrlimit.2.html ). 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.
2015-07-01 06:02:58 +08:00
2015-07-02 05:32:03 +08:00
## Linux user namespace mappings
2015-07-26 16:08:26 +08:00
```json
2015-07-02 05:32:03 +08:00
"uidMappings": [
{
2015-07-08 15:16:51 +08:00
"hostID": 1000,
"containerID": 0,
"size": 10
2015-07-02 05:32:03 +08:00
}
],
"gidMappings": [
{
2015-07-08 15:16:51 +08:00
"hostID": 1000,
"containerID": 0,
"size": 10
2015-07-02 05:32:03 +08:00
}
]
```
2015-07-26 15:14:09 +08:00
uid/gid mappings describe the user namespace mappings from the host to the container. *hostID* is the starting uid/gid on the host to be mapped to *containerID* which is the starting uid/gid in the container and *size* refers to the number of ids to be mapped. The Linux kernel has a limit of 5 such mappings that can be specified.
2015-07-02 05:32:03 +08:00
2015-07-16 04:16:09 +08:00
## Rootfs Mount Propagation
rootfsPropagation sets the rootfs's mount propagation. Its value is either slave, private, or shared. [The kernel doc ](https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt ) has more information about mount propagation.
2015-07-26 16:08:26 +08:00
```json
2015-07-16 04:16:09 +08:00
"rootfsPropagation": "slave",
```
2015-07-01 06:02:58 +08:00
## Security
2015-06-25 08:15:48 +08:00
2015-07-01 06:13:13 +08:00
**TODO:** security profiles
2015-06-25 08:15:48 +08:00