]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: set owner of created files to ceph
authorMilan Broz <mbroz@redhat.com>
Wed, 5 Aug 2015 12:49:57 +0000 (14:49 +0200)
committerSage Weil <sage@redhat.com>
Thu, 27 Aug 2015 00:34:15 +0000 (20:34 -0400)
Signed-off-by: Milan Broz <mbroz@redhat.com>
src/ceph-disk

index 85196f94c2359768d51ec59fbdbf3ce654ba80f2..20be6673ff3dfd5f567c06d6c496132c719a43cd 100755 (executable)
@@ -32,6 +32,8 @@ import tempfile
 import uuid
 import time
 import shlex
+import pwd
+import grp
 
 """
 Prepare:
@@ -710,6 +712,12 @@ def get_osd_id(path):
         check_osd_id(osd_id)
     return osd_id
 
+def get_ceph_user():
+    if pwd.getpwnam('ceph') and grp.getgrnam('ceph'):
+        return 'ceph'
+    else:
+        return 'root'
+
 def path_set_context(path):
     # restore selinux context to default policy values
     if which('restorecon'):
@@ -720,6 +728,15 @@ def path_set_context(path):
                 ],
            )
 
+    # if ceph user exists, set owner to ceph
+    if get_ceph_user() == 'ceph':
+        command(
+           [
+                'chown', '-R', 'ceph:ceph',
+                path,
+                 ],
+           )
+
 def _check_output(args=None, **kwargs):
     out, ret = command(args, **kwargs)
     if ret:
@@ -1806,6 +1823,8 @@ def mkfs(
             '--osd-journal', os.path.join(path, 'journal'),
             '--osd-uuid', fsid,
             '--keyring', os.path.join(path, 'keyring'),
+            '--setuser', get_ceph_user(),
+            '--setgroup', get_ceph_user(),
             ],
         )
     # TODO ceph-osd --mkfs removes the monmap file?