]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: check if cephadm is root after cli is parsed 44498/head
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 6 Jan 2022 21:36:32 +0000 (16:36 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Fri, 7 Jan 2022 15:43:51 +0000 (10:43 -0500)
Fixes: https://tracker.ceph.com/issues/53572
Perform a check if cephadm is root after the CLI arguments are parsed
but before logging is configured. This allows a user to get help on
cephadm without requiring to be root or use sudo, etc.
The root check must be done before logging is configured because the
logging set up function creates dirs and files in system dirs.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadm

index 2ea74ef1c0124f49e268efdba379e687cd2619ce..0600e7bae2a387085443130c4f20621b6d9262cd 100755 (executable)
@@ -8512,13 +8512,14 @@ def cephadm_init_logging(ctx: CephadmContext, args: List[str]) -> None:
     logger.debug('%s\ncephadm %s' % ('-' * 80, args))
 
 
-def main() -> None:
-
-    # root?
+def cephadm_require_root() -> None:
+    """Exit if the process is not running as root."""
     if os.geteuid() != 0:
         sys.stderr.write('ERROR: cephadm should be run as root\n')
         sys.exit(1)
 
+
+def main() -> None:
     av: List[str] = []
     av = sys.argv[1:]
 
@@ -8527,6 +8528,7 @@ def main() -> None:
         sys.stderr.write('No command specified; pass -h or --help for usage\n')
         sys.exit(1)
 
+    cephadm_require_root()
     cephadm_init_logging(ctx, av)
     try:
         # podman or docker?