From nobody Sun Jun 15 15:18:51 2025 X-Original-To: dev-commits-src-main@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 4bKxcC5HQhz5VnKD; Sun, 15 Jun 2025 15:18:51 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bKxcC4SS4z453B; Sun, 15 Jun 2025 15:18:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750000731; 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=pR/L1O+JzrgUHwy1Ad3T0pBdc6aXt+75tjeNj3iyios=; b=k2+Tc7D8uaRJRwpb+FEy/cZyGnQ9p+FViTDvwwcB1tG8HtDs8ALbgxicQgiD5zHyj3fO0U aX560Am4421tMvAKLSoBHCkWlIkSpVqCPok1CMQbI5PjmRSElAV7S3yAm5UWyCkFMVIdH5 UxqXk9ENKLI8M6QVOjE/2f8dLGzvNq6VlVnLOdz9rz2zHR3uTUxFUGmNLkHeTDT1UBKBXy l3y7bwWC4qXtuUX7xdKZxjcBc4RuSdLNF1gzDhEyslg0zmGfSRYF4Qa4Jf3SuSYWVEkxFC duju1e4+vQZ+K8R/Irwec/PQH6/QVVySPSN3z7CTU9OE9FcE+bC+tsfoyQroRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750000731; 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=pR/L1O+JzrgUHwy1Ad3T0pBdc6aXt+75tjeNj3iyios=; b=psVhfNu5ncomlanzahaENMWC9civmKJXEzFvDCt2Pz/PPkZVBwsFrAHazEZ2USBntPWto7 Vb2G5hrK2LK6MCrnBkNz6F8QgTTCWmfUP+feZIallxv+EP/LFOG6XY9o/7S9Xzs0IJuN9R /ZHxNDp9jJ/hlUk3SjRwo6XIpypleC42wKpDsyRgx/RMSmqk0KiEL69qfOnUWHFXQH8IS0 TeRqz2ttjt0SD/KwX8WYsblydNdB2BKgSS8kjtVv+U6ItDZasq5KJ9ieMs3Y/om+l4+JZB mMKWaQzTzvWbkA2gA2UZ/3bOa9xo/zM+WurTmYR+OGT/HI4rFmALX4yWI1jv+w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1750000731; a=rsa-sha256; cv=none; b=sgQubN/E3K9cAE01PZoj8pHzqDxc0gF2W/pSAkG0blnDR7RTF2ZG8q75EYU/UHrSYA2dGe moMRnEZk4q5TjIoT+5NJGAP8gSM9/ExZudGFBTL3EyCm5wpo1y/uVFkoRzE0HwlJBHGr7x Z/ElZ0t/jGZ31lcvQDtXVlIRqXql/5Nfha2PaAEhaAfS8JY7VeAU0rr96hyRw3IcAauiRO ZTmMG/Mhz/yAm/uGXl6d9XM/YnfjOspxHNMU5VjCInVDsgQq7+iMBcmN7ik/3lRjeseUns hI/HpSMcG9R1XU/SGMvcDRgTrwiEG6xIZ/KWvAsGm1OwTDm12H3tp4hp7Wld6A== 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 4bKxcC3bgtz37Y; Sun, 15 Jun 2025 15:18:51 +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 55FFIpwx055333; Sun, 15 Jun 2025 15:18:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55FFIpkH055330; Sun, 15 Jun 2025 15:18:51 GMT (envelope-from git) Date: Sun, 15 Jun 2025 15:18:51 GMT Message-Id: <202506151518.55FFIpkH055330@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: 6a54f886bede - main - nuageinit: add support for sudo List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6a54f886bede6e6193ebc82ec5fca85679b7dc41 Auto-Submitted: auto-generated The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=6a54f886bede6e6193ebc82ec5fca85679b7dc41 commit 6a54f886bede6e6193ebc82ec5fca85679b7dc41 Author: Baptiste Daroussin AuthorDate: 2025-06-15 15:18:32 +0000 Commit: Baptiste Daroussin CommitDate: 2025-06-15 15:18:48 +0000 nuageinit: add support for sudo --- libexec/nuageinit/nuage.lua | 39 +++++++++++++++++++++++++++++++++++- libexec/nuageinit/nuageinit | 3 +++ libexec/nuageinit/tests/nuageinit.sh | 2 ++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/libexec/nuageinit/nuage.lua b/libexec/nuageinit/nuage.lua index 76f2d24ac178..deb441ee25ba 100644 --- a/libexec/nuageinit/nuage.lua +++ b/libexec/nuageinit/nuage.lua @@ -228,6 +228,42 @@ local function addsshkey(homedir, key) end end +local function addsudo(pwd) + local chmodsudoersd = false + local chmodsudoers = false + local root = os.getenv("NUAGE_FAKE_ROOTDIR") + local sudoers_dir = "/usr/local/etc/sudoers.d" + if root then + sudoers_dir= root .. sudoers_dir + end + local sudoers = sudoers_dir .. "/90-nuageinit-users" + local sudoers_attr = lfs.attributes(sudoers) + if sudoers_attr == nil then + chmodsudoers = true + local dirattrs = lfs.attributes(sudoers_dir) + if dirattrs == nil then + local r, err = mkdir_p(sudoers_dir) + if not r then + return nil, err .. " (creating " .. sudoers_dir .. ")" + end + chmodsudoersd = true + end + end + local f = io.open(sudoers, "a") + if not f then + warnmsg("impossible to open " .. sudoers) + return + end + f:write(pwd.name .. " " .. pwd.sudo .. "\n") + f:close() + if chmodsudoers then + sys_stat.chmod(sudoers, 416) + end + if chmodsudoersd then + sys_stat.chmod(sudoers, 480) + end +end + local function update_sshd_config(key, value) local sshd_config = "/etc/ssh/sshd_config" local root = os.getenv("NUAGE_FAKE_ROOTDIR") @@ -419,7 +455,8 @@ local n = { pkg_bootstrap = pkg_bootstrap, install_package = install_package, update_packages = update_packages, - upgrade_packages = upgrade_packages + upgrade_packages = upgrade_packages, + addsudo = addsudo } return n diff --git a/libexec/nuageinit/nuageinit b/libexec/nuageinit/nuageinit index c1026aa2afee..d8aa734cb122 100755 --- a/libexec/nuageinit/nuageinit +++ b/libexec/nuageinit/nuageinit @@ -290,6 +290,9 @@ if line == "#cloud-config" then nuage.addsshkey(homedir, v) end end + if u.sudo then + nuage.addsudo(u) + end else nuage.warn("invalid type : " .. type(u) .. " for users entry number " .. n) end diff --git a/libexec/nuageinit/tests/nuageinit.sh b/libexec/nuageinit/tests/nuageinit.sh index edcc80346b5d..fe799a2227f3 100644 --- a/libexec/nuageinit/tests/nuageinit.sh +++ b/libexec/nuageinit/tests/nuageinit.sh @@ -117,6 +117,7 @@ users: - name: foobar gecos: Foo B. Bar primary_group: foobar + sudo: ALL=(ALL) NOPASSWD:ALL groups: users passwd: $6$j212wezy$7H/1LT4f9/N3wpgNunhsIqtMj62OKiS3nyNwuizouQc3u7MbYCarYeAHWYPYb2FT.lbioDm2RrkJPb9BZMN1O/ EOF @@ -138,6 +139,7 @@ EOF sed -i "" "s/freebsd:.*:1001/freebsd:freebsd:1001/" "${PWD}"/etc/master.passwd atf_check -o file:expectedpasswd cat "${PWD}"/etc/master.passwd atf_check -o file:expectedgroup cat "${PWD}"/etc/group + atf_check -o inline:"foobar ALL=(ALL) NOPASSWD:ALL\n" cat ${PWD}/usr/local/etc/sudoers.d/90-nuageinit-users } nocloud_network_head()