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.

  • glizzyguzzler@piefed.blahaj.zone
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    9 hours ago

    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. When you do ls -l it says frigate instead of 1111; life is easier.

    Overall, it has been a lot of work to divine these things because the documentation and useful examples for Podman are confusing and non-existent. I think I’ve gotten most of this idmap= and UserNS= stuff working from reading GitHub issues that drop little tidbits. But after I get it working as I want it, it’s solid, and I can now rinse-and-repeat in the future. No Docker daemon to fuck with or get hacked, and it’s reliable since I just let systemd start these quadlets up.

    I’m not 100% done, but I’m close. Outstanding issue right now is that on server restart sometimes some Podman networks don’t actually start up correctly and then containers that want them fail to start because of that (I have to restart the Podman network via systemctl to get them to exist in Podman). But eventually I’ll find the stupid GitHub issue where someone mentions something relevant for that, and then I’ll be golden!

    • kanera@feddit.clOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      17 hours ago

      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!! :)

        • kanera@feddit.clOP
          link
          fedilink
          English
          arrow-up
          2
          ·
          7 hours ago

          this is incredible thank you very much, I will read through this once I have more energy lmao, this looks like okay dense content, very interesting