]> git.proxmox.com Git - pve-storage.git/commitdiff
Ceph: add keyring parameter for external clusters
authorAaron Lauterer <a.lauterer@proxmox.com>
Thu, 26 Aug 2021 10:03:32 +0000 (12:03 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 26 Aug 2021 16:15:30 +0000 (18:15 +0200)
By adding the keyring for RBD storage or the secret for CephFS ones, it
is possible to add an external Ceph cluster with only one API call.

Previously the keyring / secret file needed to be placed in
/etc/pve/priv/ceph/$storeID.{keyring,secret} manually.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
PVE/API2/Storage/Config.pm
PVE/CLI/pvesm.pm
PVE/Storage/CephFSPlugin.pm
PVE/Storage/RBDPlugin.pm

index ea655c5805256264b6c8d6a41b792947bf460bc8..bf38df3f1926e0c98372b71d55a1710745f21e36 100755 (executable)
@@ -112,7 +112,7 @@ __PACKAGE__->register_method ({
        return &$api_storage_config($cfg, $param->{storage});
     }});
 
-my $sensitive_params = [qw(password encryption-key master-pubkey)];
+my $sensitive_params = [qw(password encryption-key master-pubkey keyring)];
 
 __PACKAGE__->register_method ({
     name => 'create',
index 668170aa011390ba16512277960a3c5b4f77b30e..190de914ccd1f049ed76445fd20ff257da3a1026 100755 (executable)
@@ -64,13 +64,21 @@ sub param_mapping {
        }
     };
 
+    my $keyring_map = {
+       name => 'keyring',
+       desc => 'file containing the keyring to authenticate in the Ceph cluster',
+       func => sub {
+           my ($value) = @_;
+           return PVE::Tools::file_get_contents($value);
+       },
+    };
 
     my $mapping = {
        'cifsscan' => [ $password_map ],
        'cifs' => [ $password_map ],
        'pbs' => [ $password_map ],
-       'create' => [ $password_map, $enc_key_map, $master_key_map ],
-       'update' => [ $password_map, $enc_key_map, $master_key_map ],
+       'create' => [ $password_map, $enc_key_map, $master_key_map, $keyring_map ],
+       'update' => [ $password_map, $enc_key_map, $master_key_map, $keyring_map ],
     };
     return $mapping->{$name};
 }
index 2aaa45083be54f944566667b8950cf7c342355db..3b9a791e1a61b0a27cabd4aac245bfdab064010d 100644 (file)
@@ -146,6 +146,7 @@ sub options {
        fuse => { optional => 1 },
        bwlimit => { optional => 1 },
        maxfiles => { optional => 1 },
+       keyring => { optional => 1 },
        'prune-backups' => { optional => 1 },
     };
 }
@@ -163,20 +164,29 @@ sub check_config {
 sub on_add_hook {
     my ($class, $storeid, $scfg, %param) = @_;
 
-    return if defined($scfg->{monhost}); # nothing to do if not pve managed ceph
+    my $secret = $param{keyring} if defined $param{keyring} // undef;
+    PVE::CephConfig::ceph_create_keyfile($scfg->{type}, $storeid, $secret);
 
-    PVE::CephConfig::ceph_create_keyfile($scfg->{type}, $storeid);
+    return;
+}
+
+sub on_update_hook {
+    my ($class, $storeid, $scfg, %param) = @_;
+
+    if (exists($param{keyring})) {
+       if (defined($param{keyring})) {
+           PVE::CephConfig::ceph_create_keyfile($scfg->{type}, $storeid, $param{keyring});
+       } else {
+           PVE::CephConfig::ceph_remove_keyfile($scfg->{type}, $storeid);
+       }
+    }
 
     return;
 }
 
 sub on_delete_hook {
     my ($class, $storeid, $scfg) = @_;
-
-    return if defined($scfg->{monhost}); # nothing to do if not pve managed ceph
-
     PVE::CephConfig::ceph_remove_keyfile($scfg->{type}, $storeid);
-
     return;
 }
 
index a8d1243c50e1a950fbbe6aa88ac4953d6005b34e..4bd43d5c0c115050ba027475a040f551065d66a5 100644 (file)
@@ -305,6 +305,10 @@ sub properties {
            description => "Always access rbd through krbd kernel module.",
            type => 'boolean',
        },
+       keyring => {
+           description => "Client keyring contents (for external clusters).",
+           type => 'string',
+       },
     };
 }
 
@@ -318,6 +322,7 @@ sub options {
        username => { optional => 1 },
        content => { optional => 1 },
        krbd => { optional => 1 },
+       keyring => { optional => 1 },
        bwlimit => { optional => 1 },
     };
 }
@@ -327,20 +332,29 @@ sub options {
 sub on_add_hook {
     my ($class, $storeid, $scfg, %param) = @_;
 
-    return if defined($scfg->{monhost}); # nothing to do if not pve managed ceph
+    my $secret = $param{keyring} if defined $param{keyring} // undef;
+    PVE::CephConfig::ceph_create_keyfile($scfg->{type}, $storeid, $secret);
 
-    PVE::CephConfig::ceph_create_keyfile($scfg->{type}, $storeid);
+    return;
+}
+
+sub on_update_hook {
+    my ($class, $storeid, $scfg, %param) = @_;
+
+    if (exists($param{keyring})) {
+       if (defined($param{keyring})) {
+           PVE::CephConfig::ceph_create_keyfile($scfg->{type}, $storeid, $param{keyring});
+       } else {
+           PVE::CephConfig::ceph_remove_keyfile($scfg->{type}, $storeid);
+       }
+    }
 
     return;
 }
 
 sub on_delete_hook {
     my ($class, $storeid, $scfg) = @_;
-
-    return if defined($scfg->{monhost}); # nothing to do if not pve managed ceph
-
     PVE::CephConfig::ceph_remove_keyfile($scfg->{type}, $storeid);
-
     return;
 }