From nobody Tue Jun 10 07:20:26 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 4bGgDW1P1gz60GVd; Tue, 10 Jun 2025 07:20:27 +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 4bGgDV6xkBz3Npd; Tue, 10 Jun 2025 07:20:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1749540027; 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=WuHfZzcIQ1p8YTkeajNL3lUSd+gKoR7G/0qhmBhWRTA=; b=a18RnkDPwAZ3imchqeZqlSz84IYuaWSZF2PoOKRW0rvtpLb3bicdI4yO5KzHQUwK8tGghi Dwv8Y55ydXswhIe//G4TpwZM6Zcu2OVDcb7UtHC/4v7d27mqOGJWbHRR4Gc9T+w+r1/wdd cpNsSEUekrkqwsxWXhzuR/39wwsigtTXrybvalWSNQ2RJGKzE6dSZwduAyJyUxOGFOkf2F cVnzJY8L9npG6OCtlfHpC0O4iyVhjsg1jfAYAZyrS3sbY4CVRQbKNhN6qGPIFP2PNoJypD /PKr8PZozkOl5iTcBJnbg7K1tLHpPZca75lCMz/8qi1RyN489Dyy/n9DiKaYCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1749540027; 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=WuHfZzcIQ1p8YTkeajNL3lUSd+gKoR7G/0qhmBhWRTA=; b=Bw4OAg1W968IKGU2HxBNoLeR4Ss+My1kwg/dfHtxC7bMdlDMkCOkC6cou9O0RRO+1U7sN0 7XLDuG7SyU8ujM3CvWAu7/2WIQoRQKuYaEy89/nKncFZni8Vh9RexB30Yjjf8TjWbB2XVH 9sBzSPcQoxuT1CYT/O3rXIMZr/RIZxG5BKREI9JDo6r+JeC2RIfDjI/k/s9uB2qeLK6P5Z +ZgJpsvxdzZhlJ2AwPp/kHnRyW8zF+Q51nG5gTZkDGvcJnU0R3tiAXZ1FhNVpgL8nnj20f EdmQsK2T0Ue5wl1NH+T2sylKM7WeGgwgiY9oPn2iRdyNKZkGKBEolfDmtUpOkw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1749540027; a=rsa-sha256; cv=none; b=OUY+SrmhfWZTHNMBFeMIWl1vhNgjxTYMJYe+05/QlGy/IzHA3HZYNaPoSYpDj/GpQlJeCm E5Te0d0/B3KPv9C+79Pf/LPLBHbk4i904DuVXpouMFDx8VYTLdM46Zu+Bx8BSZx1mN0glc jlszb8GdAExo1e9knm2GzP7ysP9STeWPu9Rt79CB98YBNLzr2rMoT/jvYc1relCbsaqiwc w1hmPVjA06ohED2kCm9fhm61i7BWc5Ta64zDx8RU1D2nk487MTry52qTXhNvRb/XeyT8gH C2aRqbb8Oa0WmmHlxB20B2mazn8ZqXXsIOWU9oYTNNrjlgTYflbXmy2kGKHZNA== 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 4bGgDV6Y2PzX2L; Tue, 10 Jun 2025 07:20:26 +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 55A7KQNe045034; Tue, 10 Jun 2025 07:20:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55A7KQSG045031; Tue, 10 Jun 2025 07:20:26 GMT (envelope-from git) Date: Tue, 10 Jun 2025 07:20:26 GMT Message-Id: <202506100720.55A7KQSG045031@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: 09545628f0cd - main - nuageinit: fix using user_data as a script 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: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 09545628f0cd58406a47f302fb8584a5292d4b1a Auto-Submitted: auto-generated The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=09545628f0cd58406a47f302fb8584a5292d4b1a commit 09545628f0cd58406a47f302fb8584a5292d4b1a Author: Baptiste Daroussin AuthorDate: 2025-06-10 07:09:47 +0000 Commit: Baptiste Daroussin CommitDate: 2025-06-10 07:20:23 +0000 nuageinit: fix using user_data as a script In official cloudinit, when a user_data file starts with '#!' it should be execute late in the boot process. To respect this nuageinit now copy the user_data script into a /var/cache/nuageinit/user_data if found and a new "firsboot" rcscript anchored to the 'local' rc script is responsible to execute it if found. Note by doing this, we fix another issue we had with nuageinit, if the cloudinit provider provides the user_data scriptout with the executable permission, previous implementation was not working, like apparently what Digital Ocean is doing. PR: 287183 Reported by: olgeni@ --- libexec/nuageinit/nuageinit | 15 ++++++++++----- libexec/nuageinit/tests/nuageinit.sh | 30 ++++++++++++++++++++++++++++-- libexec/rc/rc.d/Makefile | 3 ++- libexec/rc/rc.d/nuageinit_user_data_script | 25 +++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 8 deletions(-) diff --git a/libexec/nuageinit/nuageinit b/libexec/nuageinit/nuageinit index dda3ae482859..f2f15f0d36f0 100755 --- a/libexec/nuageinit/nuageinit +++ b/libexec/nuageinit/nuageinit @@ -396,9 +396,14 @@ if line == "#cloud-config" then if obj.package_upgrade then nuage.upgrade_packages() end -else - local res, err = os.execute(path .. "/" .. ud) - if not res then - nuage.err("error executing user-data script: " .. err) - end +elseif line:sub(1, 2) == "#!" then + -- delay for execution at rc.local time -- + f = io.open(path .. "/" .. ud) + local content = f:read("*a") + f:close() + nuage.mkdir_p(root .. "/var/cache/nuageinit") + f = assert(io.open(root .. "/var/cache/nuageinit/user_data", "w")) + f:write(content) + f:close() + sys_stat.chmod(root .. "/var/cache/nuageinit/user_data", 493) end diff --git a/libexec/nuageinit/tests/nuageinit.sh b/libexec/nuageinit/tests/nuageinit.sh index 5fc811f1dcb5..be8b186d933b 100644 --- a/libexec/nuageinit/tests/nuageinit.sh +++ b/libexec/nuageinit/tests/nuageinit.sh @@ -27,6 +27,7 @@ atf_test_case config2_userdata_runcmd atf_test_case config2_userdata_packages atf_test_case config2_userdata_update_packages atf_test_case config2_userdata_upgrade_packages +atf_test_case config2_userdata_shebang setup_test_adduser() { @@ -73,7 +74,8 @@ nocloud_userdata_script_body() printf "instance-id: iid-local01\n" > "${PWD}"/media/nuageinit/meta-data printf "#!/bin/sh\necho yeah\n" > "${PWD}"/media/nuageinit/user-data chmod 755 "${PWD}"/media/nuageinit/user-data - atf_check -s exit:0 -o inline:"yeah\n" /usr/libexec/nuageinit "${PWD}"/media/nuageinit nocloud + atf_check -s exit:0 /usr/libexec/nuageinit "${PWD}"/media/nuageinit nocloud + atf_check -o inline:"#!/bin/sh\necho yeah\n" cat var/cache/nuageinit/user_data } nocloud_user_data_script_body() @@ -82,7 +84,8 @@ nocloud_user_data_script_body() printf "instance-id: iid-local01\n" > "${PWD}"/media/nuageinit/meta-data printf "#!/bin/sh\necho yeah\n" > "${PWD}"/media/nuageinit/user_data chmod 755 "${PWD}"/media/nuageinit/user_data - atf_check -s exit:0 -o inline:"yeah\n" /usr/libexec/nuageinit "${PWD}"/media/nuageinit nocloud + atf_check -s exit:0 /usr/libexec/nuageinit "${PWD}"/media/nuageinit nocloud + atf_check -o inline:"#!/bin/sh\necho yeah\n" cat var/cache/nuageinit/user_data } nocloud_userdata_cloudconfig_users_head() @@ -810,6 +813,28 @@ EOF atf_check -o inline:"pkg upgrade -y\n" /usr/libexec/nuageinit "${PWD}"/media/nuageinit config-2 } +config2_userdata_shebang_body() +{ + mkdir -p media/nuageinit + setup_test_adduser + printf "{}" > media/nuageinit/meta_data.json + cat > media/nuageinit/user_data < media/nuageinit/user_data <&1 | tee -a /var/log/nuageinit.log +} + +# Share the same config as nuageinit +load_rc_config nuageinit +run_rc_command "$1"