From 285a80a96a3b74569bc1ab994577347b78cabeac Mon Sep 17 00:00:00 2001 From: Melissa Li Date: Wed, 23 Mar 2022 11:38:37 -0400 Subject: [PATCH] cephadm: show error message if private registry credentials not provided Raise UnauthorizedRegistryError in `_pull_image` if user tries to pull from a private registry without authentication, handle error in `command_bootstrap`, `commond_adopt`, `command_pull` Fixes: https://tracker.ceph.com/issues/55015 Signed-off-by: Melissa Li (cherry picked from commit 4de0803ba893abf341ab634d1382208370de7c98) --- src/cephadm/cephadm | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index e0c44d89aac31..eb26555177f1e 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -302,6 +302,10 @@ class Error(Exception): class TimeoutExpired(Error): pass + +class UnauthorizedRegistryError(Error): + pass + ################################## @@ -4245,7 +4249,12 @@ def command_version(ctx): def command_pull(ctx): # type: (CephadmContext) -> int - _pull_image(ctx, ctx.image, ctx.insecure) + try: + _pull_image(ctx, ctx.image, ctx.insecure) + except UnauthorizedRegistryError: + err_str = 'Failed to pull container image. Check that host(s) are logged into the registry' + logger.debug(f'Pulling image for `command_pull` failed: {err_str}') + raise Error(err_str) return command_inspect_image(ctx) @@ -4273,6 +4282,9 @@ def _pull_image(ctx, image, insecure=False): if not ret: return + if 'unauthorized' in err: + raise UnauthorizedRegistryError() + if not any(pattern in err for pattern in ignorelist): raise Error('Failed command: %s' % cmd_str) @@ -5089,7 +5101,12 @@ def command_bootstrap(ctx): config = prepare_bootstrap_config(ctx, fsid, addr_arg, ctx.image) if not ctx.skip_pull: - _pull_image(ctx, ctx.image) + try: + _pull_image(ctx, ctx.image) + except UnauthorizedRegistryError: + err_str = 'Failed to pull container image. Check that correct registry credentials are provided in bootstrap by --registry-url, --registry-username, --registry-password, or supply --registry-json with credentials' + logger.debug(f'Pulling image for bootstrap on {hostname} failed: {err_str}') + raise Error(err_str) image_ver = CephContainer(ctx, ctx.image, 'ceph', ['--version']).run().strip() logger.info(f'Ceph version: {image_ver}') @@ -6083,7 +6100,12 @@ def command_adopt(ctx): # type: (CephadmContext) -> None if not ctx.skip_pull: - _pull_image(ctx, ctx.image) + try: + _pull_image(ctx, ctx.image) + except UnauthorizedRegistryError: + err_str = 'Failed to pull container image. Host may not be logged into container registry. Try `cephadm registry-login --registry-url --registry-username --registry-password ` or supply login info via a json file with `cephadm registry-login --registry-json `' + logger.debug(f'Pulling image for `command_adopt` failed: {err_str}') + raise Error(err_str) (daemon_type, daemon_id) = ctx.name.split('.', 1) -- 2.39.5