mirror of
https://github.com/games-on-whales/LXC2Docker.git
synced 2026-10-15 12:52:04 +00:00
[PR #65] [MERGED] feat(containers): honor Config.User as lxc.init.uid/gid #64
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
games-on-whales/LXC2Docker#64
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/games-on-whales/LXC2Docker/pull/65
Author: @JBailes
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @JBailes
Base:
main← Head:fix/honor-container-user📝 Commits (1)
04ee142feat(containers): honor Config.User as lxc.init.uid/gid📊 Changes
3 files changed (+190 additions, -0 deletions)
View changed files
📝
internal/api/containers.go(+7 -0)📝
internal/lxc/config.go(+127 -0)📝
internal/lxc/config_test.go(+56 -0)📄 Description
Problem
The daemon stores and echoes a container's
User(Config.User) but never applies it — every container's PID 1 runs as root regardless of the requested user. Anything depending on the requested uid/gid silently runs as root.This surfaced running a postgres container on a volume whose backing store forces a non-root owner (a SmoothNAS smoothfs tier that forces uid 1000): the stock postgres entrypoint drops to the
postgresuser (uid 999), but the data dir is owned by the forced uid →initdb: could not access directory ... Permission denied. Setting--user 1000:1000had no effect because the daemon ignored it (verified: a container created withUser=1000:1000still ran as uid 0).Fix
Translate the requested user spec (
uid,uid:gid,user, oruser:group) intolxc.init.uid/lxc.init.gidwhen generating both the LXC and PVE container configs. Names are resolved against the container rootfs's/etc/passwdand/etc/group(matching how Docker resolves an image's USER); a user given without a group inherits its passwd primary GID. An empty or unresolvable spec leaves PID 1 as root.Scope: only an explicitly requested
Useris applied. The image's ownUSERis deliberately not auto-applied — the daemon has always run containers as root, and silently honoring image USER would change the runtime identity of every existing image (breaking those whose volumes were provisioned for root). Callers wanting the image USER can read it from inspect and pass it explicitly.Test
TestInitUserConfigItemscovers numeric (uid,uid:gid), name resolution (user → uid + primary gid), mixed name/numeric, numeric-uid-not-in-passwd (gid omitted → LXC defaults to 0), and unresolvable specs. Fullinternal/lxc+internal/apisuites pass;go vetclean.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.