Managing podman quadlets, users subids and such
from kanera@feddit.cl to selfhosted@lemmy.world on 13 Jul 04:19
https://feddit.cl/post/12800226

So, I’ve finally gotten a comfortable setup for my beautiful podman quadlets, its a simple debian system, heavily systemd reliant, and I’m curious about how yall admin such a thing, I’ve got a couple of scripts to create users, skel the home directories, and templates for services.

I’m particularly curious about handling subids, I’m pretty careful about them and not using too too many, mostly for being afraid of running out of them lol. But from what I’ve seen, linux allows you to go real stupid with it, like having a shitton of range and entrances.

I personally give my quad users like 500 subids to work with and they generally work fine, it really depends on if I’m gonna have more than one service running on them or not.

#selfhosted

threaded - newest

Svinhufvud@sopuli.xyz on 13 Jul 05:46 next collapse

Are you running rootless or rootfull containers?

At least with rootless containers (I have not used roortfull) I think its quite pointless to create separate users for the services, as you could use just the subuids (and/or SELinux) to get container separation, as you already seem to do .

I run my quadlets with uidmap and gidmaps, so I get explicit control of the mappings. It can be a tad tedious at times but I think it’s worth the hassle.

kanera@feddit.cl on 13 Jul 15:03 collapse

I had no idea you could just use the subids from their respective etc files, I just followed what the podman documentation recommends, I like that the containermapping ids like this is def much simpler than creating users per process, and probably less resource intensive. thanks for sharing ur input :)

I’m also afraid of SELinux, def the way of having a more secure system, but I reaaaaaaally dont wanna get to more docs on linux hahaha.

dont@lemmy.world on 13 Jul 05:54 next collapse

Are you using one (system) user per quadlet? (Why?) Each of my quadlets is owned by the same (non-root) user and the containers are rootless. In that case, podman deals with (sub)id-allocation. selinux-labels take care of volume scopes and podman networks are as isolated as possible. Seems enough for me; never even considered using different users in that case.

kanera@feddit.cl on 13 Jul 15:18 collapse

Never delved into SELinux, honestly afraid (lazy) of navigating getting into yet another rabbit hole, but from the rest of the answers here, letting podman deal with isolation sounds like a better solution. tysm for ur input :)

helix@feddit.org on 13 Jul 06:20 next collapse

You can use configuration management software like Ansible or Puppet. I wouldn’t write my own scripts when there are good Ansible modules.

kanera@feddit.cl on 13 Jul 15:25 collapse

Had no idea either of these existed, I usually let myself go at the applications themselves searching for a way to setup a minimal environment, so I often miss these kind of convenience tools, either cuz I dont look for them, or cuz im a stubborn bitch lol, will check these out, so thanks for ur input :)

glizzyguzzler@piefed.blahaj.zone on 13 Jul 08:09 next collapse

I approach it the same as I did with Docker, one user per container.

I started with rootless but networking within Podman is moot with multiple users per container. And one user for all containers to get networking has to lead to subUID clashes (and thus escape vectors) - unless someone can explain how not…

But root Podman is just as secure anyway, and easier, so I just roll with UserNS=auto and use idmap= on the volumes to enable writing as the specified user for the container. And networking in Podman works because it’s one user space. By default UserNS=auto gives 1024 subUIDs to a container. I had to up that to the expected max of 65535 for Frigate to work (example bit I use with idmap, UserNS with the size and group mapping, and GroupAdd):

Volume=/mnt/camraz:/media/frigate:rw,noexec,nosuid,nodev,Z,idmap=uids=@1111-0-1;gids=@1111-0-1#1020-1020-1
UserNS=auto:size=65535,uidmapping=105:@105:1,gidmapping=105:@105:1
GroupAdd=105

So what’s going on here is on the Volume= I have the camera folder mounted to where Frigate wants it, and I specify that it accesses that volume with idmap= and frigate’s UID/GID 1111 and the camera group I made at GID 1020.

The order for the idmap is @${hostUID}-${containerUID}-${num2map}. The @ symbol means that 1111 is an absolute host UID; drop that and 1111 is pulled from the containers subUID/subGID list. Most containers run as root (0) so you just map to that user.

Side quest: For containers that have one of those mini-hypervisors like LinuxServers images and their “S6” thing, I worked around them starting with a root user but then requiring moving to a non-root user by specifying PUID=1 and PGID=1 then setting idmap=uids=@1999-0-2;gids=@1999-0-2 and reserving 1999 as username containerNameStartup and 2000 as containerName. This idmap= maps host 1999 to container 0 but maps two UID/GIDs consecutively, so it also maps host 2000 to container 1 keeping everything lined up perfectly - while LinuxServer images still don’t get host root like they so desperately want.

GroupAdd=105 adds in the group 105 to the container, which is notably not the host group 105. UserNS is needed to complete that. This just makes that group exist in the container.

UserNS=auto:size=65535,gidmapping=105:@105:1 accomplishes the subUID/subGID size allocation to the expected default max of 65535 (because Frigate needs it) and the group connection from host 105 to container 105. Note that this syntax helpfully uses the opposite order as idmap=. It goes ${containerUID}:@${hostUID}:${num2map} and uses colons instead of dashes.

Every other container is cool with the default 1024 (just UserNS=auto). The subUIDs are pulled from a non-existent user named containers that you need to enable for Podman root to work with UserNS, and it has like 2 million billion or something with their recommended setup, so it’s good on subUIDs/subGIDs.

Command to set up root Podman with UserNS=auto:

sudo echo "containers:2147483647:2147483648" >> /etc/subuid
sudo echo "containers:2147483647:2147483648" >> /etc/subgid

You can also have UserNS=auto and run the container as a specific host user directly instead of “nobody” with:

UserNS=auto:uidmapping=0:@1111:1,gidmapping=0:@1111:1

Same idea as how I mapped in the host group 105 above. Where the root user 0 is mapped to the host (via @) user 1111 so the container runs as the user. I don’t use that because the idmap= works perfectly and then the container doesn’t even run as the user that controls the files directly. But maybe there will be a use for that sometime(?).

And I do have a fuckton of users; Debian once complained it ran out of numbers or something after like 20 users, so I just ran the first thing I found to make the UID limit some really big number, and I never thought about it again! No idea what it was..

*Edit: * I cleaned it up and added examples

Also I mostly work with UIDs not users per-say, so I specify UID 1111 has access to Frigate files. I just make a user named frigate to make it a bit easier for me.

kanera@feddit.cl on 13 Jul 14:52 collapse

excellent solution, just have root container to --user and use the auto userns, had no idea about that, sounds super convenient. Much more self contained, just let the program do its thing, I had no idea about userns=auto with root, tysm for ur input!! :)

glizzyguzzler@piefed.blahaj.zone on 13 Jul 22:34 collapse

I added examples so you don’t have to dig as far if you want to give it a try!

makeshift0546@lemmy.today on 13 Jul 09:12 next collapse

I don’t understand why you people over complicate your lives by over engineering shit at home.

fleem@piefed.zeromedia.vip on 13 Jul 10:41 next collapse

im over here feeling jealous that i haven’t been able to swap to podman 😭

makeshift0546@lemmy.today on 13 Jul 12:30 collapse

Drop your compose files in an AI and it’ll take 20 seconds to convert. There really isn’t a huge migration costs.

fleem@piefed.zeromedia.vip on 13 Jul 12:53 collapse

last time i tried to spin one up, the graphics card was so loud and hot and it made my lights dim!

also when it got done it was fuckin wrong!! 😭

kanera@feddit.cl on 13 Jul 15:14 collapse

its my larp an I get to decide how hellish I want my server to be!!! 😡

makeshift0546@lemmy.today on 13 Jul 15:59 collapse

🤣

reluctant_squidd@lemmy.ca on 13 Jul 16:04 collapse

I setup custom bash scripts eons ago to handle all my subuid/gid and networking stuff, and I’m on the road now, so getting into the code is harder. If I have time tonight, I’ll reply back with how I did it for rootless.

I run everything in rootless podman with quadlets. Be prepared for the docker die-hard crowd to tell you podman is inferior, but it really isn’t. At least not in my 10ish years using it. Is it harder to get going? Sure, but the extra abstraction layer for security is worth it imo.

I have to get ready to update my scripts for the podman 6.0 changes upcoming, but otherwise they pretty much run themselves. Systemd gets a lot of hate sometimes, but when you get it working, it’s pretty much automated.

Want to have program x run after condition y. Use targets, sockets or a small monitor service. I have encrypted volumes that require me to enter the unlock password before they will unlock, the services will just wait until that is done.

Networking and permission issues? Run a pod. Podman unshare is also your friend.

The biggest thing I found getting everything figured out is the lack of step-by-step instructions on how it all works. The docs help, but can be a bit confusing/ambiguous at times.

Feel free to dm me if you have a specific question and I’d be glad to try and help. Just might be a bit delayed on responses for the next bit while I’m travelling.