Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(azure): Fix imds-based ssh_pwauth #6002

Merged
merged 4 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cloudinit/sources/DataSourceAzure.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,14 +758,12 @@ def crawl_metadata(self):
if imds_hostname:
LOG.debug("Hostname retrieved from IMDS: %s", imds_hostname)
crawled_data["metadata"]["local-hostname"] = imds_hostname
if imds_disable_password:
if imds_disable_password is not None:
LOG.debug(
"Disable password retrieved from IMDS: %s",
imds_disable_password,
)
crawled_data["metadata"][
"disable_password"
] = imds_disable_password
crawled_data["cfg"]["ssh_pwauth"] = not imds_disable_password

if self.seed == "IMDS" and not crawled_data["files"]:
try:
Expand Down
22 changes: 20 additions & 2 deletions tests/unittests/sources/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,7 @@ def test_username_from_imds(self):
dsrc.cfg["system_info"]["default_user"]["name"], "username1"
)

def test_disable_password_from_imds(self):
def test_disable_password_from_imds_true(self):
sys_cfg = {"datasource": {"Azure": {"apply_network_config": True}}}
data = {
"ovfcontent": construct_ovf_env(),
Expand All @@ -2289,7 +2289,25 @@ def test_disable_password_from_imds(self):
self.m_fetch.return_value = imds_data_with_os_profile
dsrc = self._get_ds(data)
dsrc.get_data()
self.assertTrue(dsrc.metadata["disable_password"])
self.assertFalse(dsrc.cfg["ssh_pwauth"])

def test_disable_password_from_imds_false(self):
sys_cfg = {"datasource": {"Azure": {"apply_network_config": True}}}
data = {
"ovfcontent": construct_ovf_env(),
"sys_cfg": sys_cfg,
"write_ovf_to_seed_dir": False,
}
imds_data_with_os_profile = copy.deepcopy(NETWORK_METADATA)
imds_data_with_os_profile["compute"]["osProfile"] = dict(
adminUsername="username1",
computerName="hostname1",
disablePasswordAuthentication="false",
)
self.m_fetch.return_value = imds_data_with_os_profile
dsrc = self._get_ds(data)
dsrc.get_data()
self.assertTrue(dsrc.cfg["ssh_pwauth"])

def test_userdata_from_imds(self):
sys_cfg = {"datasource": {"Azure": {"apply_network_config": True}}}
Expand Down