Skip to content

mgr/cephadm: check for hosts being logged into container registry - #73500

Open
adk3798 wants to merge 1 commit into
ceph:mainfrom
adk3798:cephadm-check-registry-login
Open

adk3798 wants to merge 1 commit into
ceph:mainfrom
adk3798:cephadm-check-registry-login

Conversation

@adk3798

@adk3798 adk3798 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

This patch changes a few things in order to handle cases where a host is no longer logged into a registry but nothing triggers cephadm to attempt to log it back in. The triggers for logins prior to this patch are

  • New registry login credentials are added (adds all hosts)
  • A host is newly added to the cluster (just that host)
  • The entire metadata for a host is invalidated (happens when a host's addr is changed or it is taken out of offline/maintenance status)
  • mgr failover (adds all hosts)

This patch now checks the login status during gather-facts if the module find login credentials available. If we check and are not logged in that host is added to the registry login queue.

This patch also now has us mark the existence of login credentials at mgr startup or when new credentials are provided. That should cover the only times we'd need to assuming nobody is manually changing the mgr/cephadm/registry_credentials mon db entry.

We also now kick the serve loop after storing new credentials in order to make the login happen quicker in cases where the serve loop was idle.

Signed-off-by: Adam King [email protected]

Resolves: https://tracker.ceph.com/issues/82680

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

This patch changes a few things in order to handle cases where
a host is no longer logged into a registry but nothing triggers
cephadm to attempt to log it back in. The triggers for logins
prior to this patch are

- New registry login credentials are added (adds all hosts)
- A host is newly added to the cluster (just that host)
- The entire metadata for a host is invalidated (happens when a host's
  addr is changed or it is taken out of offline/maintenance status)
- mgr failover (adds all hosts)

This patch now checks the login status during gather-facts if
the module find login credentials available. If we check and
are not logged in that host is added to the registry login
queue.

This patch also now has us mark the existence of login
credentials at mgr startup or when new credentials are provided.
That should cover the only times we'd need to assuming nobody
is manually changing the mgr/cephadm/registry_credentials mon
db entry.

We also now kick the serve loop after storing new credentials
in order to make the login happen quicker in cases where the
serve loop was idle.

Signed-off-by: Adam King <[email protected]>

Resolves: https://tracker.ceph.com/issues/82680

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The changes can crash agent metadata collection when the new context attribute is absent and block private-registry logins after bootstrap when cached credential state remains stale.

4 open issues
What changed in this PR

This PR adds registry-login checks to cephadm host-fact collection so hosts that lose authentication can be queued for login again.

Changes:

  • Adds a registry-check option to gather-facts and reports login status in host facts.
  • Caches credential availability and registry URLs, then queues hosts that report missing logins.
  • Wakes the serve loop after credentials are stored and adds queueing tests.
File Description
src/​pybind/​mgr/​cephadm/​tests/​test_facts.py Tests login queueing for false, true, and absent status.
src/​pybind/​mgr/​cephadm/​serve.py Passes registry URLs to fact collection and gates queued logins.
src/​pybind/​mgr/​cephadm/​module.py Caches credential state and wakes the serve loop after updates.
src/​pybind/​mgr/​cephadm/​inventory.py Queues hosts whose facts report missing registry logins.
src/​cephadm/​cephadmlib/​host_facts.py Adds registry-login status to host facts.
src/​cephadm/​cephadmlib/​container_engines.py Adds a container-engine login-status probe.
src/​cephadm/​cephadm.py Adds the registry-check argument to gather-facts.

Review effort: Balanced

@property
def logged_into_all_container_registries(self) -> bool:
"""Check if host is logged into all container registries if provided to gather-facts command"""
if not self.ctx.container_registries_to_check:
self.mgr.cache.metadata_up_to_date[host] = True

if self.mgr.cache.host_needs_registry_login(host) and self.mgr.get_store('registry_credentials'):
if self.mgr.registry_credentials_present and self.mgr.cache.host_needs_registry_login(host):
Comment on lines +196 to +199
engine = ctx.container_engine
cmd = [engine.path, 'login', '--get-login', url]
if isinstance(engine, Podman):
cmd.append('--authfile=/etc/ceph/podman-auth.json')
# on the off chance someone put something that isn't a json object
# here make sure the module doesn't crash while loading
try:
credentials_list = json.loads(registry_credentials).get('registry_credentials', [])
@rkachach

rkachach commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@adk3798 this is a review from Claude, could you plz double check?

Review of #73500

The approach is sound: gather-facts checks <engine> login --get-login <url> for each configured registry, and hosts that aren't logged in are queued for re-login. A few issues need fixing before merge.

Blockers

1. The cephadm agent crashes when it gathers facts.
CephadmAgent calls HostFacts(self.ctx).dump() (cephadm.py:2145). dump() reads every public property, so it now also reads the new logged_into_all_container_registries. That property uses self.ctx.container_registries_to_check, an option that only the gather-facts command defines. The agent command doesn't define it, and BaseConfig doesn't have it either. So CephadmContext.__getattr__ falls back to object.__getattribute__ and raises AttributeError. That call sits outside the agent's try, so the agent loop dies.

  • Fix: getattr(self.ctx, 'container_registries_to_check', None).
  • Add a unit test that calls HostFacts.dump() with agent arguments.

Should-fix

2. On Docker hosts the check always fails, so every facts refresh triggers a login.
docker login doesn't support --get-login, so the command exits non-zero, the check returns False, and the host is queued again. The result is a registry-login per host every facts_cache_timeout (10 min by default), and it never settles.

  • Fix: run the check only when the engine is Podman, and return True otherwise. Or read ~/.docker/config.json directly.

3. Clusters with old-format credentials never get the check.
migrate_4_5 stores {"url", "username", "password"} at the top level, and the cephadm binary's registry-login still accepts that format. The new parsing in __init__ does .get('registry_credentials', []). On that format it sets registry_credentials_present = True but leaves registry_credential_urls = []. Because _refresh_facts requires a non-empty list, the check is skipped with no warning.

  • Also, __init__ runs before migrations, so a cluster migrating now gets stale values until the next mgr restart.
  • Fix: one helper that turns either format into a list of URLs, used both in __init__ and in registry_login().

4. A failed check logs noise on every refresh.
check_registry_login calls call() with the default VERBOSE_ON_FAILURE, so a host that isn't logged in writes the error to cephadm.log on every gather-facts. Use CallVerbosity.QUIET, since a non-zero exit is the expected "not logged in" answer here.

5. Bad credentials now retry forever.
With wrong credentials or an unreachable registry, the host fails the check and gets queued again on every refresh. Before this patch it got one attempt. The interval keeps the load low, but this should be a deliberate choice, with a backoff or at least a note in the commit message.

6. The check only covers the case where the auth entry is missing.
--get-login reads the local auth file and doesn't contact the registry, so expired or rotated credentials still report as logged in. Please state in the commit message that this fix covers a deleted or missing /etc/ceph/podman-auth.json entry, not credentials that stop being valid.

Polish

  • registry_credentials_present duplicates the URL list. It's equivalent to bool(self.registry_credential_urls) once item 3 is fixed. Keeping one value removes the chance of the two disagreeing, which is what happens in item 3.
  • The __init__ error handling doesn't match its comment. The comment says it guards against a value that isn't a JSON object, but only JSONDecodeError is caught. A stored null or [] parses fine, then .get raises AttributeError and the module fails to load. Check isinstance(..., dict). The pass after logger.warning is also dead code.
  • Empty URLs aren't filtered. cred.get('url', '') can put '' into the list. That empty URL then gets checked, always fails, and the host is re-queued on every refresh. Filter out falsy URLs.
  • self.registry_credential_urls = [] has no type annotation. Annotate it as List[str].
  • Tests only cover the mgr-side queueing in update_host_facts. Please add coverage for:
    • parsing in __init__ (list format, old format, bad JSON);
    • the arguments _refresh_facts builds;
    • the binary-side property, including the agent path (item 1) and the Docker path (item 2).
  • Typo: "rgistry" in the test docstring.
  • The update_host_facts signature change is unrelated cleanup. Moving from a type comment to annotations is harmless, but it makes the diff harder to backport. Drop it or split it into its own commit.

Good as is

  • Kicking the serve loop after registry-login is correct and low-risk.
  • Hosts running the agent don't get the check. Their facts lack the key, so the default of True applies and nothing is queued. That's acceptable once item 1 is fixed, but it should be stated as a known gap.
  • No redeploy risk: nothing touches config or dependency hashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants