[pve-devel] [PATCH 17/19] cloudinit: limit sshkey to 1024 bytes

Alexandre Derumier aderumier at odiso.com
Tue May 23 08:57:15 CEST 2017


From: Wolfgang Bumiller <w.bumiller at proxmox.com>

Also allowing multiple keys since with some key types and
lengths 1024 would fit quite a number of them...

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 3456449..c3f1327 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -522,7 +522,8 @@ my $confdesc_cloudinit = {
     },
     sshkey => {
 	optional => 1,
-	type => 'string',
+	type => 'string', format => 'urlencoded',
+	maxLength => 1024,
 	description => "cloud-init: ssh keys for root",
     },
     hostname => {
@@ -6677,12 +6678,19 @@ sub generate_cloudinit_userdata {
     $content .= "  - ifdown -a\n";
     $content .= "  - ifup -a\n";
 
-    if ($conf->{sshkey}) {
+    my $keys = $conf->{sshkey};
+    if ($keys) {
+	$keys = URI::Escape::uri_unescape($keys);
+	$keys = [map { chomp $_; $_ } split(/\n/, $keys)];
+	$keys = [grep { /\S/ } @$keys];
+
 	$content .= "users:\n";
 	$content .= "  - default\n";
 	$content .= "  - name: root\n";
 	$content .= "    ssh-authorized-keys:\n";
-	$content .= "      - $conf->{sshkey}\n";
+	foreach my $k (@$keys) {
+	    $content .= "      - $k\n";
+	}
     }
 
     $content .= "package_upgrade: true\n";
-- 
2.11.0




More information about the pve-devel mailing list