hashicorp/nomad · error

unable to convert userid to uint32: %w

Error message

unable to convert userid to uint32: %w

What it means

After group setup, setCmdUser converts the resolved user's u.Uid string to uint32 with strconv.ParseUint so it can be placed in syscall.Credential. A failure here means the user database returned a uid that is not a valid 32-bit unsigned integer; the parse error is wrapped with %w so callers can inspect it.

Source

Thrown at drivers/shared/executor/executor_unix.go:86

	gidStrings, err := u.GroupIds()
	if err != nil {
		return fmt.Errorf("unable to lookup user's group membership: %v", err)
	}

	gids := make([]uint32, len(gidStrings))
	for _, gidString := range gidStrings {
		u, err := strconv.ParseUint(gidString, 10, 32)
		if err != nil {
			return fmt.Errorf("unable to convert user's group to uint32 %s: %v", gidString, err)
		}

		gids = append(gids, uint32(u))
	}

	// Convert the uid and gid
	uid, err := strconv.ParseUint(u.Uid, 10, 32)
	if err != nil {
		return fmt.Errorf("unable to convert userid to uint32: %w", err)
	}
	gid, err := strconv.ParseUint(u.Gid, 10, 32)
	if err != nil {
		return fmt.Errorf("unable to convert groupid to uint32: %s", err)
	}

	// Set the command to run as that user and group.
	if cmd.SysProcAttr == nil {
		cmd.SysProcAttr = &syscall.SysProcAttr{}
	}
	if cmd.SysProcAttr.Credential == nil {
		cmd.SysProcAttr.Credential = &syscall.Credential{}
	}
	cmd.SysProcAttr.Credential.Uid = uint32(uid)
	cmd.SysProcAttr.Credential.Gid = uint32(gid)
	cmd.SysProcAttr.Credential.Groups = gids

	// Override USER, LOGNAME, and HOME environment variables.

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Check 'getent passwd <userid>' output and confirm the uid field is a valid numeric uid < 4294967296.
  2. Fix the offending /etc/passwd line or LDAP uidNumber attribute.
  3. Re-create the user with a sane uid (e.g. 'useradd -u 1005 appuser').

Example fix

// before (/etc/passwd)
appuser:x:abc:1005::/home/appuser:/bin/false
// after
appuser:x:1005:1005::/home/appuser:/bin/false
Defensive patterns

Strategy: validation

Validate before calling

// Go: verify uid is numeric before launching
u, err := user.Lookup(taskUser)
if err != nil {
    return err
}
if _, err := strconv.ParseUint(u.Uid, 10, 32); err != nil {
    return fmt.Errorf("user %q has malformed uid %q", taskUser, u.Uid)
}

Type guard

func hasValidUid(u *user.User) bool {
    _, err := strconv.ParseUint(u.Uid, 10, 32)
    return err == nil
}

Try / catch

if err := exec.SetUser(cmd, userid); err != nil {
    var perr *strconv.NumError
    if errors.As(err, &perr) {
        return fmt.Errorf("bad numeric id from user db: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: u.Uid (from users.Lookup) is empty, non-numeric, or >4294967295 — e.g. a broken NSS backend returning malformed passwd entries.

Common situations: LDAP passwd entries with malformed uidNumber; corrupted /etc/passwd line for the task user; custom NSS module returning bad data.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/e57d23881a9ab73f. Report an issue: GitHub.