Skip to content

feat(azure): Support x509 certificate SSH keys from IMDS#6912

Draft
peytonr18 wants to merge 11 commits into
canonical:mainfrom
peytonr18:probertson-imds-x509
Draft

feat(azure): Support x509 certificate SSH keys from IMDS#6912
peytonr18 wants to merge 11 commits into
canonical:mainfrom
peytonr18:probertson-imds-x509

Conversation

@peytonr18

@peytonr18 peytonr18 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Proposed Commit Message

feat(azure): Support x509 certificate SSH keys from IMDS

Azure IMDS may return SSH public keys in OpenSSH format or as x509
certificates. Non-OpenSSH keys previously forced a fallback to
Wireserver. _get_public_keys_from_imds() now converts x509 certificates
to OpenSSH format (via the certs module) and uses them directly.
Unsupported formats and conversion failures still fall back gracefully.

Changes

  • DataSourceAzure.py: _get_public_keys_from_imds() now handles keys
    per-item — OpenSSH keys used as-is, x509 certs converted, other
    formats raise ValueError (preserving Wireserver fallback).
  • tests/.../test_azure.py: added tests for single x509, mixed
    x509 + OpenSSH, and conversion-failure fallback.

Notes

Merge type

  • Squash merge using "Proposed Commit Message"

peytonr18 added 11 commits June 23, 2026 14:36
…sity

Added extract_x509_certificate() to validate certificates in bundles, integrated validation into parse_certificates(), and toned down debug logs to avoid sounding like failures.
Fold the regex-based certificate parsing into cloudinit.sources.azure.certs so
helpers no longer reimplement it, and wire OpenSSLManager.parse_certificates to
loop over the helper. Added a regression test that confirms CRLF-mixed bundles
still yield every fingerprint + key pair.
…all_certificates to avoid openssl dependency
…and iterate

them directly in parse_certificates, replacing the previous loop/find slicing flow.

Also clarify is_openssh_formatted behavior by explicitly rejecting embedded CRLF
and improving debug messages; update tests and
type hints to match the new extraction API.
Azure-generated SSH keys may contain \r\n sequences embedded in the
base64 key data (LP: #1910835). Previously, keys with embedded CRLF
were rejected outright by is_openssh_formatted(). Instead, sanitize
the keys by stripping \r\n before validation so they can be properly
written to authorized_keys.
- Use pytest.mark.parametrize, fixtures, and monkeypatch in tests
- Remove raw docstring prefix; clarify CRLF deprecation in docstring
- Remove redundant _key_is_openssh_formatted wrapper
- Simplify sanitize_openssh_key call site and log messages
- Reuse variables and constants instead of inline string literals
Azure IMDS may deliver SSH public keys in OpenSSH format or as x509
certificates. Previously any non-OpenSSH key caused
_get_public_keys_from_imds() to raise and fall back to Wireserver.

Inspect each IMDS key individually: keep OpenSSH-formatted keys,
convert x509 certificates to OpenSSH format via the certs module, and
raise ValueError for unsupported formats (preserving the Wireserver
fallback). Conversion failures (openssl/ssh-keygen) are caught and
re-raised as ValueError so a malformed certificate falls back
gracefully instead of crashing metadata crawl.

Adds unit tests for single x509, mixed x509 + OpenSSH, and
conversion-failure cases.
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.

1 participant