From 21fb80aaab0b333d997d8241e17cf9749a37e065 Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Fri, 4 Feb 2022 11:11:05 -0700 Subject: [PATCH] cephadm: chown the prometheus data dir during redeploy 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 --- src/cephadm/cephadm | 9 +++++++++ src/cephadm/tests/test_cephadm.py | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 8eaae926196..9a6d3deca6d 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -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) diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index 2f3f0158245..03e8585b31a 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -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): -- 2.39.5