@@ -22,6 +22,7 @@ import (
2222 "math/rand"
2323 "os"
2424 "os/exec"
25+ "strconv"
2526 "strings"
2627 "time"
2728
@@ -50,6 +51,10 @@ func CreateTimer(ctx context.Context, container containerd.Container) error {
5051 log .G (ctx ).Debugf ("Creating healthcheck timer unit: %s" , hcName )
5152
5253 cmd := []string {}
54+ if rootlessutil .IsRootless () {
55+ cmd = append (cmd , fmt .Sprintf ("--uid=%d" , rootlessutil .ParentEUID ()))
56+ }
57+
5358 if path := os .Getenv ("PATH" ); path != "" {
5459 cmd = append (cmd , "--setenv=PATH=" + path )
5560 }
@@ -300,14 +305,30 @@ func shouldSkipHealthCheckSystemd(hc *Healthcheck) bool {
300305 return true
301306 }
302307
303- // Skip healthchecks in rootless environments to avoid systemd DBUS permission issues
304- if rootlessutil .IsRootless () {
305- return true
306- }
308+ // // Skip healthchecks in rootless environments to avoid systemd DBUS permission issues
309+ // if rootlessutil.IsRootless() {
310+ // return true
311+ // }
307312
308313 // Don't proceed if health check is nil, empty, explicitly NONE or interval is 0.
309314 if hc == nil || len (hc .Test ) == 0 || hc .Test [0 ] == "NONE" || hc .Interval == 0 {
310315 return true
311316 }
312317 return false
313318}
319+
320+ // GetEffectiveUID returns the effective user ID as a string, handling UserNS correctly.
321+ // In rootless environments with User Namespaces, os.Geteuid() may return the mapped UID
322+ // inside the namespace rather than the real host UID. This function prioritizes
323+ // ROOTLESSKIT_PARENT_EUID when available to get the real host UID.
324+ // func GetEffectiveUID(ctx context.Context) string {
325+ // if parentEuid, ok := os.LookupEnv("ROOTLESSKIT_PARENT_EUID"); ok {
326+ // // Validate it's a valid number (following XDGRuntimeDir pattern)
327+ // if _, err := strconv.Atoi(parentEuid); err != nil {
328+ // log.G(ctx).Warnf("invalid ROOTLESSKIT_PARENT_EUID: %v, falling back to current euid", err)
329+ // return strconv.Itoa(os.Geteuid())
330+ // }
331+ // return parentEuid
332+ // }
333+ // return strconv.Itoa(os.Geteuid())
334+ }
0 commit comments