git: eca5b28692ea - main - nuageinit: Add support for uid
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 11 Nov 2026 15:22:23 UTC
The branch main has been updated by emaste:
URL: https://cgit.FreeBSD.org/src/commit/?id=eca5b28692eac5ae597eff6a13629c17c1e40ace
commit eca5b28692eac5ae597eff6a13629c17c1e40ace
Author: Kushagra Chauhan <zenzesama@gmail.com>
AuthorDate: 2026-11-03 23:48:00 +0000
Commit: Ed Maste <emaste@FreeBSD.org>
CommitDate: 2026-11-11 15:21:58 +0000
nuageinit: Add support for uid
Adds support for specifying an explicit UID when creating users through nuageinit. Both numeric and string UID values are supported. Invalid or negative UIDs are rejected. The new uid option is documented in nuageinit(7). Existing automatic UID allocation remains unchanged when no UID is specified. A UID already in use or out of range is left to pw(8) to reject.
PR: 293716
Reported by: Einar Bjarni Halldórsson <einar@isnic.is>
Reviewed by: dtxdf, bapt
Signed-off-by: Kushagra Chauhan <zenzesama@gmail.com>
Differential Revision: https://reviews.freebsd.org/D61174
---
libexec/nuageinit/nuage.lua | 11 +++++++++++
libexec/nuageinit/nuageinit.7 | 4 +++-
libexec/nuageinit/tests/Makefile | 1 +
libexec/nuageinit/tests/adduser_uid.lua | 27 +++++++++++++++++++++++++++
libexec/nuageinit/tests/nuage.sh | 19 +++++++++++++++++++
5 files changed, 61 insertions(+), 1 deletion(-)
diff --git a/libexec/nuageinit/nuage.lua b/libexec/nuageinit/nuage.lua
index 738c6dabf140..8310c4751ece 100644
--- a/libexec/nuageinit/nuage.lua
+++ b/libexec/nuageinit/nuage.lua
@@ -355,6 +355,17 @@ local function adduser(pwd)
if pwd.primary_group and pwd.primary_group ~= pwd.name then
extraargs = extraargs .. " -g " .. shell_escape(pwd.primary_group)
end
+
+ -- explicitly specify an uid
+ if pwd.uid ~= nil then
+ local uid = math.tointeger(pwd.uid)
+ if not uid or uid < 0 then
+ warnmsg("invalid uid for user " .. pwd.name)
+ return nil
+ end
+ extraargs = extraargs .. " -u " .. tostring(uid)
+ end
+
if not pwd.no_create_home then
extraargs = extraargs .. " -m "
end
diff --git a/libexec/nuageinit/nuageinit.7 b/libexec/nuageinit/nuageinit.7
index 6a72d322cca4..5a0210e43189 100644
--- a/libexec/nuageinit/nuageinit.7
+++ b/libexec/nuageinit/nuageinit.7
@@ -3,7 +3,7 @@
.\" Copyright (c) 2025 Baptiste Daroussin <bapt@FreeBSD.org>
.\" Copyright (c) 2025 Jesús Daniel Colmenares Oviedo <dtxdf@FreeBSD.org>
.\"
-.Dd June 8, 2026
+.Dd November 11, 2026
.Dt NUAGEINIT 7
.Os
.Sh NAME
@@ -546,6 +546,8 @@ Specify a list of users to be created:
.Bl -tag -width "ssh_authorized_keys"
.It Ic name
Name of the user.
+.It Ic uid
+The numeric user ID to assign to the user.
.It Ic gecos
GECOS for the user.
.It Ic homedir
diff --git a/libexec/nuageinit/tests/Makefile b/libexec/nuageinit/tests/Makefile
index fc7765268660..2ec2d20bcdf2 100644
--- a/libexec/nuageinit/tests/Makefile
+++ b/libexec/nuageinit/tests/Makefile
@@ -12,6 +12,7 @@ ${PACKAGE}FILES+= addgroup.lua
${PACKAGE}FILES+= addsshkey.lua
${PACKAGE}FILES+= adduser.lua
${PACKAGE}FILES+= adduser_passwd.lua
+${PACKAGE}FILES+= adduser_uid.lua
${PACKAGE}FILES+= dirname.lua
${PACKAGE}FILES+= err.lua
${PACKAGE}FILES+= sethostname.lua
diff --git a/libexec/nuageinit/tests/adduser_uid.lua b/libexec/nuageinit/tests/adduser_uid.lua
new file mode 100644
index 000000000000..703b9d65ce59
--- /dev/null
+++ b/libexec/nuageinit/tests/adduser_uid.lua
@@ -0,0 +1,27 @@
+#!/usr/libexec/flua
+
+local n = require("nuage")
+
+local pw1 = {}
+pw1.name = "numericuser"
+pw1.uid = 1600
+local res = n.adduser(pw1)
+if not res then
+ n.err("adduser with numeric uid should return a path")
+end
+
+local pw2 = {}
+pw2.name = "stringuser"
+pw2.uid = "1601"
+res = n.adduser(pw2)
+if not res then
+ n.err("adduser with string uid should return a path")
+end
+
+local pw3 = {}
+pw3.name = "baduser"
+pw3.uid = -1
+res = n.adduser(pw3)
+if res then
+ n.err("adduser should reject negative uid")
+end
diff --git a/libexec/nuageinit/tests/nuage.sh b/libexec/nuageinit/tests/nuage.sh
index 1e08c990eacd..c5cea2f138c7 100644
--- a/libexec/nuageinit/tests/nuage.sh
+++ b/libexec/nuageinit/tests/nuage.sh
@@ -12,6 +12,7 @@ atf_test_case settimezone
atf_test_case addsshkey
atf_test_case adduser
atf_test_case adduser_passwd
+atf_test_case adduser_uid
atf_test_case addgroup
atf_test_case addfile
atf_test_case decode_base64
@@ -80,6 +81,23 @@ adduser_passwd_body()
$(atf_get_srcdir)/crypt $passhash "barcrypted"
}
+adduser_uid_head()
+{
+ atf_set "require.user" root
+}
+
+adduser_uid_body()
+{
+ mkdir etc
+ printf "root:*:0:0::0:0:Charlie &:/root:/bin/sh\n" > etc/master.passwd
+ pwd_mkdb -d etc etc/master.passwd
+ printf "wheel:*:0:root\n" > etc/group
+ atf_check -e inline:"nuageinit: invalid uid for user baduser\n" /usr/libexec/flua $(atf_get_srcdir)/adduser_uid.lua
+ atf_check -s exit:1 grep '^baduser:' etc/master.passwd
+ atf_check -o inline:"1600\n" awk -F ':' '/^numericuser:/ {print $3}' etc/master.passwd
+ atf_check -o inline:"1601\n" awk -F ':' '/^stringuser:/ {print $3}' etc/master.passwd
+}
+
addgroup_body()
{
mkdir etc
@@ -122,6 +140,7 @@ atf_init_test_cases()
atf_add_test_case addsshkey
atf_add_test_case adduser
atf_add_test_case adduser_passwd
+ atf_add_test_case adduser_uid
atf_add_test_case addgroup
atf_add_test_case addfile
atf_add_test_case decode_base64