From: John Mulligan Date: Thu, 6 Jan 2022 21:36:32 +0000 (-0500) Subject: cephadm: check if cephadm is root after cli is parsed X-Git-Tag: v16.2.8~186^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F44634%2Fhead;p=ceph.git cephadm: check if cephadm is root after cli is parsed 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 (cherry picked from commit 6f01977a68c3a2bba7bf2dfb7322728e7da96d0d) --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index f73ffc7f5e5..f21985066ef 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -8571,13 +8571,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:] @@ -8586,6 +8587,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?