Skip to content

fix: use default keys when sshd_config is unreadable - #7309

Open
MSedgeMC wants to merge 1 commit into
canonical:mainfrom
MSedgeMC:fix/authorized-keys-fallback
Open

MSedgeMC wants to merge 1 commit into
canonical:mainfrom
MSedgeMC:fix/authorized-keys-fallback

Conversation

@MSedgeMC

@MSedgeMC MSedgeMC commented Dec 5, 2026

Copy link
Copy Markdown

Summary

  • initialize the default AuthorizedKeysFile path, StrictModes value, and rendered fallback path before parsing sshd_config
  • preserve successful-parse behavior and the existing fallback log message
  • add a regression test for PermissionError while reading sshd_config

Fixes #7229

Validation

Run with Python 3.13.5 in a project-local virtual environment:

  • .venv/bin/python -m pytest -q tests/unittests/test_ssh_util.py::test_extract_authorized_keys_with_unreadable_sshd_config — 1 passed
  • .venv/bin/python -m pytest -q tests/unittests/test_ssh_util.py — 153 passed
  • .venv/bin/python -m pytest -q tests/unittests — 5946 passed, 5 skipped, 13 xfailed
  • .venv/bin/python -m ruff check cloudinit/ssh_util.py tests/unittests/test_ssh_util.py — passed
  • .venv/bin/python -m black --check cloudinit/ssh_util.py tests/unittests/test_ssh_util.py — 2 files unchanged
  • .venv/bin/python -m isort --check-only --diff cloudinit/ssh_util.py tests/unittests/test_ssh_util.py — passed

Validation is unit-level only. The regression simulates the read failure by mocking parse_ssh_config_map() to raise PermissionError; user, path-checking, and key-file helpers are also mocked. No live sshd or cloud-platform integration was exercised.

Initialize the default authorized keys path and StrictModes before parsing so the OSError fallback no longer indexes an empty list or uses unbound variables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ssh_util: extract_authorized_keys raises IndexError when sshd_config cannot be read

1 participant