{"record":{"id":"d72c00d8142f6af7","repo":"bytebase/bytebase","slug":"uid-d-or-gid-d-exceeds-maximum-safe-value","errorCode":null,"errorMessage":"uid %d or gid %d exceeds maximum safe value","messagePattern":"uid (.+?) or gid (.+?) exceeds maximum safe value","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/resources/postgres/postgres.go","lineNumber":118,"sourceCode":"\t\tif !os.IsNotExist(err) {\n\t\t\treturn errors.Wrapf(err, \"failed to check data directory path existence %q\", path)\n\t\t}\n\t\tdirListToChown = append(dirListToChown, path)\n\t\tpath = filepath.Dir(path)\n\t}\n\tslog.Debug(\"Data directory list to Chown\", slog.Any(\"dirListToChown\", dirListToChown))\n\n\tif err := os.MkdirAll(pgDataDir, 0700); err != nil {\n\t\treturn errors.Wrapf(err, \"failed to make postgres data directory %q\", pgDataDir)\n\t}\n\n\tuid, gid, sameUser, err := shouldSwitchUser()\n\tif err != nil {\n\t\treturn err\n\t}\n\tif !sameUser {\n\t\tif uid > math.MaxInt32 || gid > math.MaxInt32 {\n\t\t\treturn errors.Errorf(\"uid %d or gid %d exceeds maximum safe value\", uid, gid)\n\t\t}\n\t\tslog.Info(fmt.Sprintf(\"Recursively change owner of data directory %q to bytebase...\", pgDataDir))\n\t\tfor _, dir := range dirListToChown {\n\t\t\tslog.Info(fmt.Sprintf(\"Change owner of %q to bytebase\", dir))\n\t\t\tif err := os.Chown(dir, int(uid), int(gid)); err != nil {\n\t\t\t\treturn errors.Wrapf(err, \"failed to change owner of %q to bytebase\", dir)\n\t\t\t}\n\t\t}\n\t}\n\n\targs := []string{\n\t\t\"-U\", pgUser,\n\t\t\"-D\", pgDataDir,\n\t}\n\tp := exec.Command(\"initdb\", args...)\n\tp.Env = append(os.Environ(),\n\t\t\"LC_ALL=en_US.UTF-8\",\n\t\t\"LC_CTYPE=en_US.UTF-8\",","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/resources/postgres/postgres.go#L100-L136","documentation":"When the app runs as root, it re-executes initdb/start as the `bytebase` user via syscall.Credential, which carries uid/gid as uint32 but the kernel expects values within a range the code guards as <= math.MaxInt32. If the looked-up bytebase user's uid or gid exceeds MaxInt32, initDB returns this error before chowning anything. It is a defensive guard: such uid/gid values would overflow the signed int conversion used for os.Chown/Credential.","triggerScenarios":"Running Bytebase as root while the system's `bytebase` user (or whatever user.Lookup resolves) has a uid or gid greater than 2147483647 — possible on systems with large uid ranges (e.g. some LDAP/FreeIPA or user-namespace setups assigning high ids).","commonSituations":"Container/Kubernetes images with arbitrary high uid mappings, AD/LDAP-integrated hosts issuing uidNumbers beyond 2^31, misconfigured adduser creating an out-of-range uid.","solutions":["Create the bytebase user with a small system uid: addgroup --gid 113 --system bytebase && adduser --uid 113 --system bytebase.","Inspect the existing user's ids (id bytebase) and change them if they exceed 2147483647 (usermod -u / groupmod -g).","Alternatively run Bytebase directly as a non-root user with a normal uid so the switch-user path is skipped entirely."],"exampleFix":"// before\n// adduser with a huge uid, then running bytebase as root\n// after\n// addgroup --gid 113 --system bytebase && adduser --uid 113 --system bytebase && adduser bytebase bytebase","handlingStrategy":"validation","validationCode":"u, err := user.Lookup(\"bytebase\")\nif err != nil { return err }\nuid, _ := strconv.ParseUint(u.Uid, 10, 64)\ngid, _ := strconv.ParseUint(u.Gid, 10, 64)\nif uid > math.MaxInt32 || gid > math.MaxInt32 {\n    return fmt.Errorf(\"bytebase user uid/gid (%d/%d) too large; recreate with a system uid\", uid, gid)\n}","typeGuard":null,"tryCatchPattern":"if err := postgres.StartEmbeddedInstance(ctx, cfg); err != nil && strings.Contains(err.Error(), \"exceeds maximum safe value\") {\n    return fmt.Errorf(\"recreate the bytebase user with uid/gid <= %d (e.g. 113)\", math.MaxInt32)\n}","preventionTips":["Create the bytebase user with a small fixed system uid/gid (e.g. 113) per the documented adduser command.","Avoid LDAP/AD uid ranges beyond 2^31 for the service account.","Prefer running the app directly as a non-root user to skip the switch-user path."],"tags":["postgres","unix","uid-gid","initdb","root"],"backgroundTag":"value-out-of-range","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}