git: 8f378c83c6b8 - main - nuageinit: support allow_public_ssh_keys

Baptiste Daroussin <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src,gmane.os.freebsd.current.scm
Message-ID <[email protected]>
The branch main has been updated by bapt:

URL: https://cgit.FreeBSD.org/src/commit/?id=8f378c83c6b8b052433834ca0b53677459dc0e85

commit 8f378c83c6b8b052433834ca0b53677459dc0e85
Author:     Baptiste Daroussin <[email protected]>
AuthorDate: 2026-08-11 10:00:56 +0000
Commit:     Baptiste Daroussin <[email protected]>
CommitDate: 2026-08-11 11:17:09 +0000

    nuageinit: support allow_public_ssh_keys
    
    Skip importing datasource public keys when set to false.
---
 libexec/nuageinit/nuageinit          |  6 ++++--
 libexec/nuageinit/nuageinit.7        | 10 +++++++++
 libexec/nuageinit/tests/nuageinit.sh | 41 ++++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/libexec/nuageinit/nuageinit b/libexec/nuageinit/nuageinit
index 536739c8a0bf..31daff5c71b9 100755
--- a/libexec/nuageinit/nuageinit
+++ b/libexec/nuageinit/nuageinit
@@ -18,7 +18,8 @@ local citype = arg[2]
 
 local function default_user(obj, metadata)
 	local ssh_authorized_keys = {}
-	if type(metadata.public_keys) == "table" then
+	if (not obj or obj.allow_public_ssh_keys ~= false) and
+	    type(metadata.public_keys) == "table" then
 		for _, k in pairs(metadata.public_keys) do
 			table.insert(ssh_authorized_keys, k)
 		end
@@ -604,7 +605,8 @@ local function disable_root(obj, metadata)
 		opts = opts:gsub("%$DISABLE_USER", "root")
 	end
 	local keys = {}
-	if type(metadata.public_keys) == "table" then
+	if obj.allow_public_ssh_keys ~= false and
+	    type(metadata.public_keys) == "table" then
 		for _, k in pairs(metadata.public_keys) do
 			table.insert(keys, k)
 		end
diff --git a/libexec/nuageinit/nuageinit.7 b/libexec/nuageinit/nuageinit.7
index 7e6c9154f799..6a72d322cca4 100644
--- a/libexec/nuageinit/nuageinit.7
+++ b/libexec/nuageinit/nuageinit.7
@@ -323,6 +323,16 @@ being the actual content of the files in
 Append each entry of the array to
 .Nm
 default user which will be created.
+.It Ic allow_public_ssh_keys
+Boolean which determines if the public SSH keys from the datasource
+metadata are imported to the default user and root.
+If set to
+.Ar false ,
+only the keys specified in
+.Ic ssh_authorized_keys
+are used.
+Defaults to
+.Ar true .
 .It Ic ssh_pwauth
 boolean which determines the value of the
 .Qq Ic PasswordAuthentication
diff --git a/libexec/nuageinit/tests/nuageinit.sh b/libexec/nuageinit/tests/nuageinit.sh
index 4803ddf941ab..bfc7e9f13c88 100644
--- a/libexec/nuageinit/tests/nuageinit.sh
+++ b/libexec/nuageinit/tests/nuageinit.sh
@@ -385,6 +385,46 @@ EOF
 	atf_check -o inline:"ssh-ed25519 my_key_id tdb@host\n" cat home/freebsd/.ssh/authorized_keys
 }
 
+config2_pubkeys_allow_public_ssh_keys_head()
+{
+	atf_set "require.user" root
+}
+config2_pubkeys_allow_public_ssh_keys_body()
+{
+	here=$(pwd)
+	export NUAGE_FAKE_ROOTDIR=$(pwd)
+	if [ $(id -u) -ne 0 ]; then
+		atf_skip "root required"
+	fi
+	mkdir -p media/nuageinit
+	cat > media/nuageinit/meta_data.json << EOF
+{
+    "uuid": "uuid_for_this_instance",
+    "public_keys": {
+        "tdb": "ssh-ed25519 my_key_id tdb@host"
+    }
+}
+EOF
+	cat > media/nuageinit/user_data << EOF
+#cloud-config
+allow_public_ssh_keys: false
+EOF
+	mkdir -p etc
+	mkdir -p root
+	cat > etc/master.passwd << EOF
+root:*:0:0::0:0:Charlie &:/root:/bin/csh
+sys:*:1:0::0:0:Sys:/home/sys:/bin/csh
+EOF
+	pwd_mkdb -d etc ${here}/etc/master.passwd
+	cat > etc/group << EOF
+wheel:*:0:root
+users:*:1:
+EOF
+	atf_check /usr/libexec/nuageinit ${here}/media/nuageinit config-2
+	# no public key should be imported
+	atf_check -s exit:1 test -e home/freebsd/.ssh/authorized_keys
+}
+
 config2_network_body()
 {
 	mkdir -p media/nuageinit
@@ -1509,6 +1549,7 @@ atf_init_test_cases()
 	atf_add_test_case config2_pubkeys
 	atf_add_test_case config2_pubkeys_user_data
 	atf_add_test_case config2_pubkeys_meta_data
+	atf_add_test_case config2_pubkeys_allow_public_ssh_keys
 	atf_add_test_case config2_network
 	atf_add_test_case config2_network_static_v4
 	atf_add_test_case config2_network_dns
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.