Skip to content

Commit 7fe0814

Browse files
committed
lxc.md: expand LXC section
1 parent a13bab8 commit 7fe0814

File tree

1 file changed

+61
-26
lines changed

1 file changed

+61
-26
lines changed

src/config/lxc.md

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,55 @@ configuration; simply use the various `lxc-*` commands, such as
1919

2020
### Creating unprivileged containers
2121

22-
Both [subuid(5)](https://man.voidlinux.org/subuid.5) and
23-
[subgid(5)](https://man.voidlinux.org/subgid.5) need to have entries for the
24-
user who will be running unprivileged containers. That user will also need to
25-
have a `default.conf` file specifying use of the relevant subuids and subgids.
26-
`/etc/subuid` and `/etc/subgid` contain an entry for `root` by default, but
27-
entries for other users need to be added manually.
28-
29-
Edit `/etc/subuid` and `/etc/subgid` as root to add the relevant entries:
22+
Unprivileged containers enhance security by mapping normal the normal range
23+
(0--65535) of user IDs (UIDs) and group IDs (GIDs) inside each container to
24+
ranges not in use by the host system. The host ranges must be *subordinated* to
25+
the user who will be running the unprivileged containers. The
26+
[subuid(5)](https://man.voidlinux.org/subuid.5) and
27+
[subgid(5)](https://man.voidlinux.org/subgid.5) files respectively assign
28+
subordinate UIDs and GIDs. The superuser may launch unprivileged containers in
29+
the system store; regular users may launch unprivileged containers in their
30+
individual stores.
31+
32+
To create unprivileged containers, first edit `/etc/subuid` and `/etc/subgid`
33+
to delegate ranges. For example:
3034

3135
```
3236
root:1000000:65536
33-
<user>:2000000:65536
37+
user:2000000:65536
3438
```
3539

36-
In each case, the entry specifies a base value, and the number of subuids
37-
available to that user starting from the base value. Thus, root will have
38-
subuids/subgids 1000000 to 1065535.
40+
In colon-deliminated each entry, the first field is the user to which a
41+
subordinate range will be assigned, the second field is the smallest numeric ID
42+
defining a subordinate range, and the third field is the number of consecutive
43+
IDs in the range. Generally, the number of consecutive IDs should be an integer
44+
multiple of 65536; the starting value is not important, except to ensure that
45+
the various ranges defined in the file do not overlap. In this example, `root`
46+
controls UIDs (or, from `subgid`, GIDs) ranging from 1000000 to 1065535,
47+
inclusive; `user` controls IDs ranging from 2000000 to 20655535.
48+
49+
Before creating a container, the user owning the container will need a
50+
`default.conf` file specifying the subuid and subgid range to use. For
51+
root-owned containers, this file resides at `/etc/lxc/default.conf`; for
52+
unprivileged users, the file resides at `~/.config/lxc/default.conf`. Mappings
53+
are described in lines of the form
54+
55+
```
56+
lxc.idmap = u 0 1000000 65536
57+
lxc.idmap = g 0 1000000 65536
58+
```
59+
60+
The isolated `u` character indicates a UID mapping, while the isolated `g`
61+
indicates a GID mapping. The first numeric value should generally always be 0;
62+
this indicates the start of the UID or GID range *as seen from within the
63+
container*. The second numeric value is the start of the corresponding range
64+
*as seen from outside the container*, and may be an arbitrary value within the
65+
range delegated in `/etc/subuid` or `/etc/subgid`. The final value is the numer
66+
of consecutive IDs to map.
67+
68+
**Note:** Although the external range start is arbitrary, care must be taken to
69+
ensure that the end of the range implied by the start and number does not
70+
extend beyond the range of IDs delegated to the user.
3971

4072
If configuring a non-root user, edit `/etc/lxc/lxc-usernet` as root to specify a
4173
network device quota. For example, to allow the user named `user` to create up
@@ -45,24 +77,27 @@ to 10 `veth` devices connected to the `lxcbr0` bridge:
4577
user veth lxcbr0 10
4678
```
4779

48-
If configuring root, specify the subuid and subgid in `/etc/lxc/default.conf`:
49-
50-
```
51-
lxc.idmap = u 0 1000000 65536
52-
lxc.idmap = g 0 1000000 65536
53-
```
54-
55-
Otherwise, create `~/.config/lxc/default.conf`:
80+
The user can now create and use unprivileged containers with the `lxc-*`
81+
utilities. To create a simple Void container named `mycontainer`, use a command
82+
similar to
5683

5784
```
58-
$ mkdir ~/.config/lxc
59-
$ cp /etc/lxc/default.conf ~/.config/lxc/default.conf
85+
lxc-create -n mycontainer -t download -- \
86+
--dist voidlinux --release current --arch x86_64
6087
```
6188

62-
and edit the user's `default.conf` to include the relevant `lxc.idmap` entries.
63-
64-
The user can now create and use unprivileged containers with the `lxc-*`
65-
utilities.
89+
You may substitute another architecture for `x86_64`, and you may specify a
90+
`musl` image by adding `--variant musl` to the end of the the command. See the
91+
[LXC Image Server](http://images.linuxcontainers.org) for a list of available
92+
containers.
93+
94+
All containers will share the same subordinate UID and GID maps by default.
95+
This is permissible, but it means that an attacker who gains elevated access
96+
within one container and can somehow break out of the container will have
97+
similar access to other containers. To isolate containers from each other,
98+
alter the `lxc.idmap` ranges in `default.conf` to point to a unique range
99+
*before* you create each container. Trying to fix permissions on a container
100+
created with the wrong map is possible, but inconvenient.
66101

67102
## LXD
68103

0 commit comments

Comments
 (0)