LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 02-07-2022, 12:22 AM   #1
grokkingnix
LQ Newbie
 
Registered: Dec 2020
Posts: 10

Rep: Reputation: Disabled
Unprivileged Linux containers in Slackware 15.0


First of all thank you to the entire Slackware team and community for the latest stable release!

I am trying to setup unprivileged containers but have hit a bit of a roadblock, I'd appreciate any advice.

I have read Chris' excellent guide and have a problem compiling uidmapshift from Step 2 - Remap uids & gids in the second part of the guide.

My environment is a fresh full install of Slackware 15.0:

Code:
root@slack15:~# uname -r
5.15.19

root@slack15:~# slackpkg search lxc

Looking for lxc in package list. Please wait... DONE

The list below shows all packages with name matching "lxc".

[ installed ] - lxc-4.0.11-x86_64-3

You can search specific files using "slackpkg file-search file".
The errors I get seem to be related to syntax, so I'm not sure if I'm missing anything obvious due to my lack of experience with using gcc. Below is part of the output of the suggested command in the guide:

Code:
root@slack15:~# gcc -o uidmapshift uidmapshift.c
uidmapshift.c:1:1: error: expected identifier or ‘(’ before ‘<’ token
    1 | <?xml version="1.0"?>
      | ^
uidmapshift.c:11:19: warning: character constant too long for its type
   11 | var global_path = '/~serge-hallyn/+junk/nsexec/';
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uidmapshift.c:12:1: error: unknown type name ‘var’
   12 | var collapsed_icon_path = '/static/images/treeCollapsed.png';
      | ^~~
uidmapshift.c:12:27: warning: character constant too long for its type
   12 | var collapsed_icon_path = '/static/images/treeCollapsed.png';
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uidmapshift.c:13:1: error: unknown type name ‘var’
   13 | var expanded_icon_path = '/static/images/treeExpanded.png';
      | ^~~
uidmapshift.c:13:26: warning: character constant too long for its type
   13 | var expanded_icon_path = '/static/images/treeExpanded.png';
      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uidmapshift.c:14:1: error: expected identifier or ‘(’ before ‘<’ token
   14 | </script>
      | ^
uidmapshift.c:28:1: error: stray ‘\342’ in program
   28 | ← Back to branch summary
      | ^
There is mention in Chris' guide of an alternate way of running unprivileged containers.

Quote:
There are now two distinct methods we can use to create an unprivileged container, the classic and the modern.
However the modern method does not seem to be mentioned after that.

I imagine it's by directly creating them via a default.conf file that has entries like what is described in St้phane Graber's
guide:

Code:
lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:xx:xx:xx
lxc.id_map = u 0 100000 65536
lxc.id_map = g 0 100000 65536
But when trying that approach with my non-privileged user I get the following error:

Code:
lxcuser@slack15:~$ release=15.0 MIRROR=http://mirrors.us.kernel.org/slackware lxc-create -n c1 -t slackware -f ~/.config/lxc/default.conf
getopt: unrecognized option '--mapped-uid'
getopt: unrecognized option '--mapped-gid'
lxc-slackware -h|--help -p|--path=<path> --clean
lxc-create: c1: lxccontainer.c: create_run_template: 1618 Failed to create container from template
lxc-create: c1: tools/lxc_create.c: main: 317 Failed to create container c1
These are the contents of the ~/.config/lxc/default.conf file:

Code:
lxcuser@slack15:~$ cat ~/.config/lxc/default.conf
lxc.net.0.type = veth
lxc.net.0.flags = up
lxc.net.0.link = lxcbr0
lxc.net.0.hwaddr = 00:16:3e:xx:xx:xx
lxc.idmap = u 0 100000 65536
lxc.idmap = g 0 100000 65536
This seems to suggest that the lxc-slackware script in /usr/share/lxc/templates can't handle these additional options for unprivileged containers.

I was not able to find anything related to this specific issue in these threads: 1 2 3

I'd appreciate any input, thank you.
 
Old 02-07-2022, 06:37 AM   #2
Chuck56
Member
 
Registered: Dec 2006
Distribution: Slackware
Posts: 933

Rep: Reputation: 493Reputation: 493Reputation: 493Reputation: 493Reputation: 493
Did you update both the host's /etc/subuid & /etc/subgid config files with the appropriate values?

Example:
Code:
root:100000:65536
Also, just in case, are both the host's /etc/rc.d/rc.cgconfig & /etc/rc.d/rc.cgred executable?

Hope that helps.
 
Old 02-07-2022, 10:55 AM   #3
slackerDude
Member
 
Registered: Jan 2016
Posts: 167

Rep: Reputation: 62
I think you used this URL: http://bazaar.launchpad.net/~serge-h.../uidmapshift.c

and did "page source" on it? That gives you a javascript / html version of the webpage. I was able to match up your error lines 1-1 by doing that.

You need to DOWNLOAD the uishiftmap.c file, not look at the html source of a page that lets you view it.
 
Old 02-08-2022, 04:41 AM   #4
grokkingnix
LQ Newbie
 
Registered: Dec 2020
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thank you for the replies @Chuck56 and @slackerDude.

As you suggested the issue was with how I was downloading the file, silly mistake on my end.

I was able to successfully create unprivileged containers in Slackware 15!

I created a write up about the required steps over at my blog and a script to automate the process.

I hope they help others trying to use unprivileged containers on Slackware.

Thanks again for the help!
 
2 members found this post helpful.
Old 02-08-2022, 05:35 AM   #5
franzen
Member
 
Registered: Nov 2012
Distribution: slackware
Posts: 544

Rep: Reputation: 386Reputation: 386Reputation: 386Reputation: 386
Quote:
Originally Posted by slackerDude View Post
You need to DOWNLOAD the uishiftmap.c file, not look at the html source of a page that lets you view it.
To shift UIDs, there's also "lxc-usernsexec" coming already installed with lxc.
man lxc-usernsexec:
Quote:
...
If your user id is 1000, root in a container is mapped to 190000, and
you wish to chown a file you own to root in the container, you can use:

lxc-usernsexec -m b:0:1000:1 -m b:1:190000:1 -- /bin/chown 1:1 $file

This maps your userid to root in the user namespace, and 190000 to uid 1.
Since root in the user namespace is privileged over all userids
mapped into the namespace, you are allowed to change the file owner‐
ship, which you could not do on the host using a simple chown.

...
 
1 members found this post helpful.
Old 02-10-2022, 12:53 PM   #6
grokkingnix
LQ Newbie
 
Registered: Dec 2020
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thank you for the input @franzen.

Quote:
To shift UIDs, there's also "lxc-usernsexec" coming already installed with lxc.
This definitely looks like something worth looking into. I wonder if this could be used instead of uidmapshift as a more "native" solution.

I'll look into this a bit more when I have additional time (might be a while) and report back.
 
1 members found this post helpful.
Old 02-10-2022, 04:30 PM   #7
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,834
Blog Entries: 17

Rep: Reputation: 644Reputation: 644Reputation: 644Reputation: 644Reputation: 644Reputation: 644
Howdy,

I'd like to put this information in https://docs.slackware.com/ as soon as I have time for that.

Would it be possible for someone here to write down(/sum up) raw minimal reproducible steps in a single post in this thread so I can use that as a basis? (to be reproduced on a clean Slackware 15.0 install on a machine without internet)

Last edited by zeebra; 02-10-2022 at 04:39 PM.
 
  


Reply

Tags
lxc


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: The rocky road to better Linux software installation: Containers, containers, containers LXer Syndicated Linux News 0 11-27-2021 10:49 AM
LXer: How rootless Buildah works: Building containers in unprivileged environments LXer Syndicated Linux News 0 03-05-2019 05:20 PM
Networking worked fine on privileged containers but can't get it working on unprivileged container Uzer40239028 Linux - Containers 1 01-01-2018 04:43 PM
Network help with unprivileged lxc containers on -current Rinndalir Slackware 6 09-10-2015 11:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 05:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration