]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: Add subvolume authorized_list command
authorKotresh HR <khiremat@redhat.com>
Mon, 23 Nov 2020 12:19:04 +0000 (17:49 +0530)
committerKotresh HR <khiremat@redhat.com>
Fri, 5 Mar 2021 06:50:31 +0000 (12:20 +0530)
Fixes: https://tracker.ceph.com/issues/44931
Signed-off-by: Kotresh HR <khiremat@redhat.com>
(cherry picked from commit 1abec3d0ca8c4fa405cdbf56c55f44f37aca9ca8)

src/pybind/mgr/volumes/fs/operations/versions/subvolume_v1.py
src/pybind/mgr/volumes/fs/volume.py
src/pybind/mgr/volumes/module.py

index d07dec198cd52b842d36e1bec2b84a84743ba1a3..6bb97ae6b19b9370c3bb880fce96858256251bd4 100644 (file)
@@ -6,6 +6,7 @@ import errno
 import logging
 import json
 from datetime import datetime
+from typing import List, Dict
 
 import cephfs
 
@@ -514,6 +515,27 @@ class SubvolumeV1(SubvolumeBase, SubvolumeTemplate):
                          for access_level in access_levels]
         deny_access(self.mgr, client_entity, want_mds_caps, want_osd_caps)
 
+    def authorized_list(self):
+        """
+        Expose a list of auth IDs that have access to a subvolume.
+
+        return: a list of (auth_id, access_level) tuples, where
+                the access_level can be 'r' , or 'rw'.
+                None if no auth ID is given access to the subvolume.
+        """
+        with self.auth_mdata_mgr.subvol_metadata_lock(self.group.groupname, self.subvolname):
+            meta = self.auth_mdata_mgr.subvol_metadata_get(self.group.groupname, self.subvolname)
+            auths = [] # type: List[Dict[str,str]]
+            if not meta or not meta['auths']:
+                return auths
+
+            for auth, auth_data in meta['auths'].items():
+                # Skip partial auth updates.
+                if not auth_data['dirty']:
+                    auths.append({auth: auth_data['access_level']})
+
+            return auths
+
     def _get_clone_source(self):
         try:
             clone_source = {
index 0924a9b61fe544d61d259bb10ddc99ab2c1eae59..1567001ba38e1da0ebf2e8d91074b7f2183df2dc 100644 (file)
@@ -241,6 +241,22 @@ class VolumeClient(object):
             ret = self.volume_exception_to_retval(ve)
         return ret
 
+    def authorized_list(self, **kwargs):
+        ret = 0, "", ""
+        volname     = kwargs['vol_name']
+        subvolname  = kwargs['sub_name']
+        groupname   = kwargs['group_name']
+
+        try:
+            with open_volume(self, volname) as fs_handle:
+                with open_group(fs_handle, self.volspec, groupname) as group:
+                    with open_subvol(self.mgr, fs_handle, self.volspec, group, subvolname, SubvolumeOpType.ALLOW_ACCESS) as subvolume:
+                        auths = subvolume.authorized_list()
+                        ret = 0, json.dumps(auths, indent=4, sort_keys=True), ""
+        except VolumeException as ve:
+            ret = self.volume_exception_to_retval(ve)
+        return ret
+
     def resize_subvolume(self, **kwargs):
         ret        = 0, "", ""
         volname    = kwargs['vol_name']
index 0ae663ced605f8124004b1742291934cd3b24f39..eff40b6d0728c228d290bc2dd24b1bb2b4cabffe 100644 (file)
@@ -137,6 +137,14 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
             'desc': "Deny a cephx auth ID access to a subvolume",
             'perm': 'rw'
         },
+        {
+            'cmd': 'fs subvolume authorized_list '
+                   'name=vol_name,type=CephString '
+                   'name=sub_name,type=CephString '
+                   'name=group_name,type=CephString,req=false ',
+            'desc': "List auth IDs that have access to a subvolume",
+            'perm': 'r'
+        },
         {
             'cmd': 'fs subvolumegroup getpath '
                    'name=vol_name,type=CephString '
@@ -534,6 +542,15 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
                                              auth_id=cmd['auth_id'],
                                              group_name=cmd.get('group_name', None))
 
+    @mgr_cmd_wrap
+    def _cmd_fs_subvolume_authorized_list(self, inbuf, cmd):
+        """
+        :return: a 3-tuple of return code(int), list of authids(json), error message (str)
+        """
+        return self.vc.authorized_list(vol_name=cmd['vol_name'],
+                                       sub_name=cmd['sub_name'],
+                                       group_name=cmd.get('group_name', None))
+
     @mgr_cmd_wrap
     def _cmd_fs_subvolume_ls(self, inbuf, cmd):
         return self.vc.list_subvolumes(vol_name=cmd['vol_name'],