Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update getting-started.md #719

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions content/lxc/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,15 @@ Next up is `/etc/lxc/lxc-usernet` which is used to set network devices quota for

This means that "your-username" is allowed to create up to 10 veth devices connected to the lxcbr0 bridge.

Create the `~/.local/share/lxc` directory if it doesn't exist and ensure `~/.local` is executable.

mkdir -p ~/.local/share/lxc && chmod -R +x ~/.local

With that done, the last step is to create an LXC configuration file.

* Create the `~/.config/lxc` directory if it doesn't exist.
* Copy `/etc/lxc/default.conf` to `~/.config/lxc/default.conf`
* Set `lxc.apparmor.profile = lxc-container-default-cgns`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows things we should not allow by default, yes modern systemd needs it in some cases but that's still not a good idea to have it recommended by default.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's clear that copying the default config as recommended has generate set which fails for unprivileged containers started by a user. Considering this part of the guide is for that use case, what would be recommend default if the current recommendation fails?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lxc-container-default is the safe profile

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I guess that is confusing given the manpages saying

The default is lxc-container-default-cgns if the host kernel is cgroup namespace aware, or lxc-container-default otherwise.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lxc-container-default is the safe profile

Is lxc-container-default only recommended for non cgroup systems? Is there ever a time when lxc-container-default is appropriate for cgroup v2 systems? Can you be a little more explicit about these safety problems you are referring to?

* Append the following two lines to it:
* `lxc.idmap = u 0 100000 65536`
* `lxc.idmap = g 0 100000 65536`
Expand Down Expand Up @@ -430,7 +435,11 @@ The download template will show you a list of distributions, versions, and archi

To run unprivileged containers as an unprivileged user, the user must be allocated an empty delegated cgroup (this is required because of the leaf-node and delegation model of cgroup2, not because of liblxc). See [cgroups: Full cgroup2 support](/lxc/news/2020_03_25_13_03.html#cgroups-full-cgroup2-support) for more information.

It is not possible to simply start a container from a shell as a user and automatically delegate a cgroup. Therefore, you need to wrap each call to any of the `lxc-*` commands in a `systemd-run` command. For example, to start a container, use the following command instead of just `lxc-start mycontainer`:
In newer versions of lxc, to start a container, use the following command instead of just `lxc-start mycontainer`:

lxc-unpriv-start --name mycontainer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a distro-specific command, not an upstream one


In older versions of lxc it's not possible to simply start a container from a shell as a user and automatically delegate a cgroup. Therefore, you need to wrap each call to any of the `lxc-*` commands in a `systemd-run` command. For example, to start a container, use the following command instead of just `lxc-start mycontainer`:

systemd-run --unit=my-unit --user --scope -p "Delegate=yes" -- lxc-start --name mycontainer

Expand All @@ -443,7 +452,7 @@ You can then confirm its status with either of:

And get a shell inside it with:

lxc-attach --name mycontainer
lxc-unpriv-attach --name mycontainer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a distro-specific command, not an upstream one

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For distros without lxc-unpriv-attach how are users supposed to attach unprivileged containers? It fails with permission errors

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stgraber would you care to answer so that I may fix this document properly?


Stopping it can be done with:

Expand Down