mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-28 11:25:21 +01:00
nuageinit: support allow_public_ssh_keys
Skip importing datasource public keys when set to false.
This commit is contained in:
1 parent
cd06bf5205
commit
8f378c83c6
3 files changed
+55
-2
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user