Skip to content

Commit

Permalink
feat(azure): Fix imds-based ssh_pwauth (#6002)
Browse files Browse the repository at this point in the history
To enable/disable password authentication is only possible in the OVF code path.
If OVF is unavailable, we fall back to IMDS and we want to have the same logic.
  • Loading branch information
KsenijaS authored Feb 20, 2025
1 parent 1fbdb3e commit 39937db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
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

0 comments on commit 39937db

Please sign in to comment.