Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: incorrect conversion of linux runtime identity types (#2410)
Kyle Mendellbe375221125c
diff --git a/backend/pkg/libarcane/startup/runtime_identity.go b/backend/pkg/libarcane/startup/runtime_identity.goindex 4a58ada6b..54b3317c7 100644--- a/backend/pkg/libarcane/startup/runtime_identity.go+++ b/backend/pkg/libarcane/startup/runtime_identity.go@@ -6,7 +6,6 @@ import ("net/url""os""path/filepath"- "strconv""strings"pkgutils "github.com/getarcaneapp/arcane/backend/pkg/utils"@@ -21,9 +20,11 @@ const ()type runtimeIdentityRequest struct {- Enabled bool- UID uint32- GID uint32+ Enabled bool+ UID int+ GID int+ CredentialUID uint32+ CredentialGID uint32}// ApplyRequestedRuntimeIdentity switches the current process to the configured@@ -37,8 +38,8 @@ func ApplyRequestedRuntimeIdentity(ctx context.Context) error {return err}- runtimeUID := int(req.UID)- runtimeGID := int(req.GID)+ runtimeUID := req.UID+ runtimeGID := req.GID// Avoid re-execing forever when the requested runtime identity is already active,// including explicit root requests such as PUID=0/PGID=0.@@ -57,7 +58,7 @@ func ApplyRequestedRuntimeIdentity(ctx context.Context) error {return fmt.Errorf("load mountpoints: %w", err)}- if err := prepareWritablePathsInternal(req, mountpoints); err != nil {+ if err := prepareWritablePathsInternal(runtimeUID, runtimeGID, mountpoints); err != nil {return err}@@ -76,32 +77,25 @@ func loadRuntimeIdentityRequestInternal(getenv func(string) string) (runtimeIdenreturn runtimeIdentityRequest{}, "PUID and PGID must both be set to enable non-root mode; continuing with default runtime user", nil}- uid, err := parseRuntimeIdentityValueInternal(puid, "PUID")+ uid, credentialUID, err := parseRuntimeIdentityValueInternal(puid, "PUID")if err != nil {return runtimeIdentityRequest{}, "", fmt.Errorf("invalid PUID %q: %w", puid, err)}- gid, err := parseRuntimeIdentityValueInternal(pgid, "PGID")+ gid, credentialGID, err := parseRuntimeIdentityValueInternal(pgid, "PGID")if err != nil {return runtimeIdentityRequest{}, "", fmt.Errorf("invalid PGID %q: %w", pgid, err)}return runtimeIdentityRequest{- Enabled: true,- UID: uid,- GID: gid,+ Enabled: true,+ UID: uid,+ GID: gid,+ CredentialUID: credentialUID,+ CredentialGID: credentialGID,}, "", nil}-func parseRuntimeIdentityValueInternal(raw string, key string) (uint32, error) {- value, err := strconv.ParseUint(raw, 10, 32)- if err != nil {- return 0, fmt.Errorf("parse %s: %w", key, err)- }-- return uint32(value), nil-}-func runtimeIdentitySupplementaryGroupsInternal(getenv func(string) string, resolveSocketGroup func(string) (uint32, bool)) []uint32 {socketPath, ok := dockerSocketPathInternal(getenv("DOCKER_HOST"))if !ok {@@ -147,10 +141,7 @@ func dockerSocketPathInternal(raw string) (string, bool) {return filepath.Clean(socketPath), true}-func prepareWritablePathsInternal(req runtimeIdentityRequest, mountpoints map[string]struct{}) error {- uid := int(req.UID)- gid := int(req.GID)-+func prepareWritablePathsInternal(uid int, gid int, mountpoints map[string]struct{}) error {if err := os.MkdirAll(defaultDataDirectory, pkgutils.DirPerm); err != nil {return fmt.Errorf("create data directory: %w", err)}diff --git a/backend/pkg/libarcane/startup/runtime_identity_int_32bit.go b/backend/pkg/libarcane/startup/runtime_identity_int_32bit.gonew file mode 100644index 000000000..74e465a5d--- /dev/null+++ b/backend/pkg/libarcane/startup/runtime_identity_int_32bit.go@@ -0,0 +1,21 @@+//go:build 386 || arm || mips || mipsle || wasm++package startup++import (+ "fmt"+ "strconv"+)++func parseRuntimeIdentityValueInternal(raw string, key string) (int, uint32, error) {+ value, err := strconv.ParseInt(raw, 10, 32)+ if err != nil {+ return 0, 0, fmt.Errorf("parse %s: %w", key, err)+ }++ if value < 0 {+ return 0, 0, fmt.Errorf("%s must be >= 0", key)+ }++ return int(value), uint32(value), nil+}diff --git a/backend/pkg/libarcane/startup/runtime_identity_int_64bit.go b/backend/pkg/libarcane/startup/runtime_identity_int_64bit.gonew file mode 100644index 000000000..db92c97c7--- /dev/null+++ b/backend/pkg/libarcane/startup/runtime_identity_int_64bit.go@@ -0,0 +1,26 @@+//go:build amd64 || arm64 || loong64 || mips64 || mips64le || ppc64 || ppc64le || riscv64 || s390x++package startup++import (+ "fmt"+ "math"+ "strconv"+)++func parseRuntimeIdentityValueInternal(raw string, key string) (int, uint32, error) {+ value, err := strconv.Atoi(raw)+ if err != nil {+ return 0, 0, fmt.Errorf("parse %s: %w", key, err)+ }++ if value < 0 {+ return 0, 0, fmt.Errorf("%s must be >= 0", key)+ }++ if value > math.MaxUint32 {+ return 0, 0, fmt.Errorf("%s value %d exceeds max uint32", key, value)+ }++ return value, uint32(value), nil+}diff --git a/backend/pkg/libarcane/startup/runtime_identity_linux.go b/backend/pkg/libarcane/startup/runtime_identity_linux.goindex 3c61f3b44..758ef4874 100644--- a/backend/pkg/libarcane/startup/runtime_identity_linux.go+++ b/backend/pkg/libarcane/startup/runtime_identity_linux.go@@ -27,8 +27,8 @@ func reexecWithRuntimeIdentityInternal(ctx context.Context, req runtimeIdentityRcmd.Stderr = os.Stderrcmd.SysProcAttr = &syscall.SysProcAttr{Credential: &syscall.Credential{- Uid: req.UID,- Gid: req.GID,+ Uid: req.CredentialUID,+ Gid: req.CredentialGID,Groups: groups,},}diff --git a/backend/pkg/libarcane/startup/runtime_identity_test.go b/backend/pkg/libarcane/startup/runtime_identity_test.goindex e8248b1a4..95f722e1e 100644--- a/backend/pkg/libarcane/startup/runtime_identity_test.go+++ b/backend/pkg/libarcane/startup/runtime_identity_test.go@@ -67,8 +67,21 @@ func TestLoadRuntimeIdentityRequest(t *testing.T) {require.NoError(t, err)require.Empty(t, warning)require.True(t, req.Enabled)- require.Equal(t, uint32(1001), req.UID)- require.Equal(t, uint32(2001), req.GID)+ require.Equal(t, 1001, req.UID)+ require.Equal(t, 2001, req.GID)+ require.Equal(t, uint32(1001), req.CredentialUID)+ require.Equal(t, uint32(2001), req.CredentialGID)+ })++ t.Run("error when value is negative", func(t *testing.T) {+ _, _, err := loadRuntimeIdentityRequestInternal(func(key string) string {+ if key == "PUID" {+ return "-1"+ }+ return "1001"+ })+ require.Error(t, err)+ require.Contains(t, err.Error(), "invalid PUID")})}