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

Update getting-started.md #719

wants to merge 3 commits into from

Conversation

xmready
Copy link

@xmready xmready commented May 6, 2024

Updated to reflect necessary steps when creating and using unprivileged containers as a user. These steps became clear as I tried following the getting-started guide without them.

Updated to reflect necessary steps when creating and using unprivileged containers as a user. These steps became clear as I tried following the getting-started guide without them.

Signed-off-by: xmready <[email protected]>
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

@@ -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?

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?

Copy link
Member

@hallyn hallyn left a comment

Choose a reason for hiding this comment

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

Thanks. These are good points to add. However, hardcoding uid 1000 is not right. How about using 'id-u' and -g?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants