]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: chown the prometheus data dir during redeploy
authorMichael Fritch <mfritch@suse.com>
Fri, 4 Feb 2022 18:11:05 +0000 (11:11 -0700)
committerMichael Fritch <mfritch@suse.com>
Mon, 7 Feb 2022 17:02:29 +0000 (10:02 -0700)
some builds of prometheus run with a uid 65534 (nobody) where other
builds of prometheus run with a uid of 0 (root)

Fixes: https://tracker.ceph.com/issues/54159
Signed-off-by: Michael Fritch <mfritch@suse.com>
src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index 8eaae9261965bcf54088e19a6aa2a822f307d121..9a6d3deca6d01cd482ef9587f9862b088615bf85 100755 (executable)
@@ -2098,6 +2098,13 @@ def move_files(ctx, src, dst, uid=None, gid=None):
             os.chown(dst_file, uid, gid)
 
 
+def recursive_chown(path: str, uid: int, gid: int) -> None:
+    for dirpath, dirnames, filenames in os.walk(path):
+        os.chown(dirpath, uid, gid)
+        for filename in filenames:
+            os.chown(os.path.join(dirpath, filename), uid, gid)
+
+
 # copied from distutils
 def find_executable(executable: str, path: Optional[str] = None) -> Optional[str]:
     """Tries to find 'executable' in the directories listed in 'path'.
@@ -2403,6 +2410,8 @@ def create_daemon_dirs(ctx, fsid, daemon_type, daemon_id, uid, gid,
             makedirs(os.path.join(data_dir_root, config_dir), uid, gid, 0o755)
             makedirs(os.path.join(data_dir_root, config_dir, 'alerting'), uid, gid, 0o755)
             makedirs(os.path.join(data_dir_root, 'data'), uid, gid, 0o755)
+            recursive_chown(os.path.join(data_dir_root, 'etc'), uid, gid)
+            recursive_chown(os.path.join(data_dir_root, 'data'), uid, gid)
         elif daemon_type == 'grafana':
             data_dir_root = get_data_dir(fsid, ctx.data_dir,
                                          daemon_type, daemon_id)
index 2f3f0158245f4fc910f254a16deca1ae784895b6..03e8585b31a87a911472ead9e10d75b8ee92c22e 100644 (file)
@@ -802,6 +802,22 @@ class TestMonitoring(object):
             with open(file) as f:
                 assert f.read() == content
 
+        # assert uid/gid after redeploy
+        new_uid = uid+1
+        new_gid = gid+1
+        cd.create_daemon_dirs(ctx,
+                              fsid,
+                              daemon_type,
+                              daemon_id,
+                              new_uid,
+                              new_gid,
+                              config=None,
+                              keyring=None)
+        for file,content in expected.items():
+            file = os.path.join(prefix, file)
+            assert os.stat(file).st_uid == new_uid
+            assert os.stat(file).st_gid == new_gid
+
 
 class TestBootstrap(object):