From nobody Sat Sep 27 22:06:03 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cZ1k36rNGz68mnv; Sat, 27 Sep 2025 22:06:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cZ1k35zKHz3s21; Sat, 27 Sep 2025 22:06:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759010763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=odxQWpg7y6AOK+pSLcIJGjIY26VHKxw1iQcJm8tXeKo=; b=PhKIPwdVR98jkxYRQ2ts7HLs5vVezXWHKFKnRY7zqyIdqFf++zE2cjWSOWCwHMWxywSp9z bkmkgeRe9DcpyP5wukZUyzXAHo04T3DleibsuAMGCgvUEF/AEQIoyCiEIEH4DQGGZukWec KL4jSsd1zVQ97+kFppY02xBM8n+opER4Zu9dgCI1erNGpUmgfY1QbqR2KQLpUsieXshEdD Sc79c2BqNqOzk37D3NjTaO5FTtuk1gmWXQ4OzDbF9XrPX163gfyzSfaKyOh4Nt8jDCf4ty g8EzX02Jw1YPWTAEWVM0s/CBcdGsarZsz0ArnoEyJnWWKKWks5fp/8iQ95c9+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759010763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=odxQWpg7y6AOK+pSLcIJGjIY26VHKxw1iQcJm8tXeKo=; b=kwA7Ke0aWRUdZSsiRHH43t9YlQpUCfCvLIKlP0bTsbl2ofLxY7dPMFQdMpU6mubWNeGWJM a33HZmRIwSv2BEwEpofuxWQcySW+v4NE0X37x3ps2YlZFZKLF9/6i3HPsKDzNKmqz+BZjD F1h6vZJsxoKcaP3ohjLC4ssdhnBz8uXAWWKuD9vX2QN/Pe8qh56SGkGWbEkVYAuNmEfw6K 8FtqSsnCD7XWzJpB2OQKfb/0EPCSFBZDQPpidKuuq6Gj04EAoCLlaoUI1UaU/7exZh54Yn 1tttPr0jusoR7oPq0XRGk5qQYr59/vQ/6XKT0BfxU/E9K0VhYQlJZxfyoTCEBQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1759010763; a=rsa-sha256; cv=none; b=H8RQlnqwzUvhri4QA7RRJLZVRkje+kOaxz7vPqKyTN4a0FMM46cNvKctVgFvtFvyJPJjEY 5yiiYbc1QcfrXTWwRn2FkMrIh5t2YahWQjAKZaMdHtjYYAlDhuMJHt1W1zwlwDdE7LheH5 C6Wm8HhNVlPovRFnv6zEnunin3jpa5gc3UKB1GHqbzLpzK1zFrOToKKj+VStYwRkuFpJVp /gY6xAO6DPg2aE0tIWzkEx+2r7I/yjna2s6sNGjdfS/eSe1sGryBNEBv8+JQbwQJrz1hIU wkNMaQa/OuNX0MpC7k1BFmSnCAb/Osfu4DyX8syk21uIrxCazdEB02n8WxpHag== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cZ1k358MJzsVr; Sat, 27 Sep 2025 22:06:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 58RM63we050010; Sat, 27 Sep 2025 22:06:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58RM63Gi050007; Sat, 27 Sep 2025 22:06:03 GMT (envelope-from git) Date: Sat, 27 Sep 2025 22:06:03 GMT Message-Id: <202509272206.58RM63Gi050007@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Jes=C3=BAs?= Daniel Colmenares Oviedo Subject: git: 68691160f41b - main - nuageinit: Ignore non-existent groups List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dtxdf X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 68691160f41bf6ce9ab70ddeeb7eeec2a7bff245 Auto-Submitted: auto-generated The branch main has been updated by dtxdf: URL: https://cgit.FreeBSD.org/src/commit/?id=68691160f41bf6ce9ab70ddeeb7eeec2a7bff245 commit 68691160f41bf6ce9ab70ddeeb7eeec2a7bff245 Author: Jesús Daniel Colmenares Oviedo AuthorDate: 2025-09-27 22:03:09 +0000 Commit: Jesús Daniel Colmenares Oviedo CommitDate: 2025-09-27 22:05:03 +0000 nuageinit: Ignore non-existent groups In cloud-init, when a group specified in the 'users.{index}.groups' parameter does not exist, it is ignored, but the user is created anyway. In the case of nuageinit, it exits with an exception, since pw(8) expects each group to exist. Reviewed by: bapt@ Approved by: bapt@ Differential Revision: https://reviews.freebsd.org/D52718 --- libexec/nuageinit/nuage.lua | 61 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/libexec/nuageinit/nuage.lua b/libexec/nuageinit/nuage.lua index ef3cfd994fe1..3eeb2ea0b44c 100644 --- a/libexec/nuageinit/nuage.lua +++ b/libexec/nuageinit/nuage.lua @@ -139,6 +139,58 @@ local function splitlist(list) return ret end +local function splitlines(s) + local ret = {} + + for line in string.gmatch(s, "[^\n]+") do + ret[#ret + 1] = line + end + + return ret +end + +local function getgroups() + local ret = {} + + local root = os.getenv("NUAGE_FAKE_ROOTDIR") + local cmd = "pw " + if root then + cmd = cmd .. "-R " .. root .. " " + end + + local f = io.popen(cmd .. "groupshow -a 2> /dev/null | cut -d: -f1") + local groups = f:read("*a") + f:close() + + return splitlines(groups) +end + +local function checkgroup(group) + local groups = getgroups() + + for _, group2chk in ipairs(groups) do + if group == group2chk then + return true + end + end + + return false +end + +local function purge_group(groups) + local ret = {} + + for _, group in ipairs(groups) do + if checkgroup(group) then + ret[#ret + 1] = group + else + warnmsg("ignoring non-existent group '" .. group .. "'") + end + end + + return ret +end + local function adduser(pwd) if (type(pwd) ~= "table") then warnmsg("Argument should be a table") @@ -164,7 +216,14 @@ local function adduser(pwd) local extraargs = "" if pwd.groups then local list = splitlist(pwd.groups) - extraargs = " -G " .. table.concat(list, ",") + -- pw complains if the group does not exist, so if the user + -- specifies one that cannot be found, nuageinit will generate + -- an exception and exit, unlike cloud-init, which only issues + -- a warning but creates the user anyway. + list = purge_group(list) + if #list > 0 then + extraargs = " -G " .. table.concat(list, ",") + end end -- pw will automatically create a group named after the username -- do not add a -g option in this case