Skip to content

Commit c33e4f7

Browse files
authoredMar 13, 2025
For ComputeInstance and AmlCompute update disableLocalAuth property based on ssh_public_access (Azure#39934)
* add disableLocalAuth for computeInstance * fix disableLocalAuthAuth issue for amlCompute * update compute instance * update recordings * temp changes * Revert "temp changes" This reverts commit 64e3c38. * update recordings * fix tests
1 parent 9c5f623 commit c33e4f7

File tree

9 files changed

+55
-21
lines changed

9 files changed

+55
-21
lines changed
 

‎sdk/ml/azure-ai-ml/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Features Added
44

55
### Bugs Fixed
6+
- Fix for compute Instance, disableLocalAuth property should be depend on ssh public access enabled.
67

78
## 1.26.0 (2025-03-11)
89

‎sdk/ml/azure-ai-ml/assets.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/ml/azure-ai-ml",
5-
"Tag": "python/ml/azure-ai-ml_a2c955e6e2"
5+
"Tag": "python/ml/azure-ai-ml_305b890d5b"
66
}

‎sdk/ml/azure-ai-ml/azure/ai/ml/entities/_compute/aml_compute.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def _to_rest_object(self) -> ComputeResource:
251251
),
252252
)
253253
remote_login_public_access = "Enabled"
254-
disableLocalAuth = not (self.ssh_public_access_enabled and self.ssh_settings is not None)
254+
disableLocalAuth = not (self.ssh_settings)
255255
if self.ssh_public_access_enabled is not None:
256256
remote_login_public_access = "Enabled" if self.ssh_public_access_enabled else "Disabled"
257257

‎sdk/ml/azure-ai-ml/azure/ai/ml/entities/_compute/compute_instance.py

+3
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,14 @@ def _to_rest_object(self) -> ComputeResource:
280280
subnet_resource = None
281281

282282
ssh_settings = None
283+
disable_local_auth = True
283284
if self.ssh_public_access_enabled is not None or self.ssh_settings is not None:
284285
ssh_settings = CiSShSettings()
285286
ssh_settings.ssh_public_access = "Enabled" if self.ssh_public_access_enabled else "Disabled"
286287
ssh_settings.admin_public_key = (
287288
self.ssh_settings.ssh_key_value if self.ssh_settings and self.ssh_settings.ssh_key_value else None
288289
)
290+
disable_local_auth = not self.ssh_public_access_enabled
289291

290292
personal_compute_instance_settings = None
291293
if self.create_on_behalf_of:
@@ -330,6 +332,7 @@ def _to_rest_object(self) -> ComputeResource:
330332
description=self.description,
331333
compute_type=self.type,
332334
properties=compute_instance_prop,
335+
disable_local_auth=disable_local_auth,
333336
)
334337
return ComputeResource(
335338
location=self.location,

‎sdk/ml/azure-ai-ml/tests/compute/e2etests/test_compute.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def test_aml_compute_create_and_delete(self, client: MLClient, rand_compute_name
3030
assert compute_resource_get.name == compute_name
3131
assert compute_resource_get.tier == "dedicated"
3232
assert compute_resource_get.location == compute.location
33+
assert compute_resource_get.ssh_public_access_enabled == True
34+
assert compute_resource_get.ssh_settings.admin_username == "azureuser"
3335

3436
compute_resource_get.idle_time_before_scale_down = 200
3537
compute_update_poller = client.compute.begin_update(compute_resource_get)
@@ -46,7 +48,6 @@ def test_aml_compute_create_and_delete(self, client: MLClient, rand_compute_name
4648
# so this is a preferred approach to assert
4749
assert isinstance(outcome, LROPoller)
4850

49-
@pytest.mark.skip(reason="not enough capacity")
5051
def test_compute_instance_create_and_delete(
5152
self, client: MLClient, rand_compute_name: Callable[[str], str]
5253
) -> None:
@@ -65,20 +66,11 @@ def test_compute_instance_create_and_delete(
6566
assert isinstance(compute_resource_list, ItemPaged)
6667
compute_resource_get = client.compute.get(name=compute_name)
6768
assert compute_resource_get.name == compute_name
68-
assert compute_resource_get.identity.type == "system_assigned"
6969
outcome = client.compute.begin_delete(name=compute_name)
7070
# the compute is getting deleted , but not waiting on the poller! so immediately returning
7171
# so this is a preferred approach to assert
7272
assert isinstance(outcome, LROPoller)
7373

74-
@pytest.mark.skipif(
75-
condition=not is_live(),
76-
reason=(
77-
"Test takes 5 minutes in automation. "
78-
"Already have unit tests verifying correct _restclient method is called. "
79-
"Can be validated in live build only."
80-
),
81-
)
8274
def test_compute_instance_stop_start_restart(
8375
self, client: MLClient, rand_compute_name: Callable[[str], str]
8476
) -> None:

‎sdk/ml/azure-ai-ml/tests/compute/unittests/test_compute_entity.py

+33-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def test_compute_from_yaml(self):
7575
assert rest_intermediate.location == compute.location
7676
assert rest_intermediate.tags is not None
7777
assert rest_intermediate.tags["test"] == "true"
78+
assert rest_intermediate.properties.disable_local_auth is False
79+
assert rest_intermediate.properties.properties.remote_login_port_public_access == "Enabled"
7880

7981
serializer = Serializer({"ComputeResource": ComputeResource})
8082
body = serializer.body(rest_intermediate, "ComputeResource")
@@ -98,6 +100,19 @@ def test_aml_compute_from_yaml_with_disable_public_access(self):
98100
assert rest_intermediate.properties.properties.enable_node_public_ip
99101
assert rest_intermediate.properties.disable_local_auth is True
100102
assert rest_intermediate.location == compute.location
103+
assert rest_intermediate.properties.properties.remote_login_port_public_access == "NotSpecified"
104+
105+
def test_aml_compute_from_yaml_with_creds_and_disable_public_access(self):
106+
compute: AmlCompute = load_compute("tests/test_configs/compute/compute-aml-no-identity.yaml")
107+
compute.ssh_public_access_enabled = False
108+
109+
rest_intermediate = compute._to_rest_object()
110+
111+
assert rest_intermediate.properties.compute_type == "AmlCompute"
112+
assert rest_intermediate.properties.properties.enable_node_public_ip
113+
assert rest_intermediate.properties.disable_local_auth is False
114+
assert rest_intermediate.location == compute.location
115+
assert rest_intermediate.properties.properties.remote_login_port_public_access == "Disabled"
101116

102117
def test_aml_compute_from_yaml_with_disable_public_access_when_no_sshSettings(self):
103118

@@ -112,6 +127,7 @@ def test_aml_compute_from_yaml_with_disable_public_access_when_no_sshSettings(se
112127
assert rest_intermediate.properties.compute_type == "AmlCompute"
113128
assert rest_intermediate.properties.properties.enable_node_public_ip
114129
assert rest_intermediate.properties.disable_local_auth is True
130+
assert rest_intermediate.properties.properties.remote_login_port_public_access == "Enabled"
115131
assert rest_intermediate.location == compute.location
116132

117133
def test_compute_vm_from_yaml(self):
@@ -126,6 +142,7 @@ def test_compute_vm_from_yaml(self):
126142
assert compute.ssh_settings.ssh_private_key_file == "tests/test_configs/compute/ssh_fake_key.txt"
127143

128144
rest_intermediate = compute._to_rest_object()
145+
assert rest_intermediate.properties.compute_type == "VirtualMachine"
129146
assert rest_intermediate.properties.resource_id == resource_id
130147
assert rest_intermediate.properties.properties.ssh_port == 8888
131148
assert rest_intermediate.properties.properties.administrator_account.password == "azureuserpassword"
@@ -183,6 +200,7 @@ def test_compute_instance_load_from_rest(self):
183200
compute_instance3: ComputeInstance = load_compute(
184201
source="tests/test_configs/compute/compute-ci-defaults-unit.yaml",
185202
)._to_rest_object()
203+
assert compute_instance3.properties.compute_type == "ComputeInstance"
186204
assert compute_instance3.properties.properties.enable_sso is True
187205
assert compute_instance3.properties.properties.enable_root_access is True
188206
assert compute_instance3.properties.properties.enable_os_patching is False
@@ -291,14 +309,28 @@ def test_compute_instance_uai_from_yaml(self):
291309
)
292310
assert compute_from_rest.ssh_public_access_enabled == False
293311

294-
def test_compute_instance_sai_from_yaml(self):
312+
def test_compute_instace_to_rest(self):
295313
compute: ComputeInstance = load_compute("tests/test_configs/compute/compute-ci.yaml")
314+
compute.ssh_public_access_enabled = True
315+
316+
compute_rest = compute._to_rest_object()
317+
318+
assert compute_rest.location == compute.location
319+
assert compute_rest.properties.properties.ssh_settings.ssh_public_access == "Enabled"
320+
assert compute_rest.properties.properties.ssh_settings.admin_public_key == compute.ssh_settings.ssh_key_value
321+
assert compute_rest.properties.description == compute.description
322+
assert compute_rest.properties.compute_type == "ComputeInstance"
323+
assert compute_rest.properties.disable_local_auth == False
324+
325+
def test_compute_instance_sai_from_yaml(self):
326+
compute: ComputeInstance = load_compute("tests/test_configs/compute/compute-ci-id-sys-assigned.yaml")
296327
assert compute.name == "banchci"
297328
assert compute.type == "computeinstance"
298329
assert compute.identity.type == "system_assigned"
299330

300331
compute_resource = compute._to_rest_object()
301332
assert compute_resource.identity.type == "SystemAssigned"
333+
assert compute_resource.properties.disable_local_auth == True
302334

303335
compute_from_rest = Compute._from_rest_object(compute_resource)
304336
assert compute_from_rest.type == "computeinstance"

‎sdk/ml/azure-ai-ml/tests/test_configs/compute/compute-aml-no-identity.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: banchaml
22
type: amlcompute
33
tier: dedicated
44
description: some_desc_aml
5-
size: Standard_DS2_v2
5+
size: Standard_DS3_v2
66
location: eastus
77
ssh_public_access_enabled: true
88
ssh_settings:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: banchci
2+
type: computeinstance
3+
description: some_desc_ci
4+
size: Standard_DS3_v2
5+
ssh_public_access_enabled: false
6+
ssh_settings:
7+
admin_username: azureuser
8+
ssh_key_value: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDWm/4TTHMZdzZVJcob2aFRWDmIyJLxk028AKh7K03RDgR8bz/Knd9DgB2V3sipjY9wYJ1U9YbsUoAt24+CWZFpnoB79J6vaoqwUb7c6nGkaNrWoGZKI+v26GOX8O2MUjjOyBuPEinJtQ432J4affHfeRI+1iDQXuwFUKhNbRVpxh2h9otXF+J1UvSUaPYggS7Iivyha/x8HJzFcNnIPrAZkPiT/Nb/Qk7FyoFTEw64cIl1ByvmF3ewSOeVXKDpb2d4vrSDTVmXFKRrWduhM3sHO5dckREKc+tSQ0M+SpfBqaBgRTAie4jFVSIiSHCvL2BRQXBMRiyPgNlpiJWTPLp/ administrator@MININT-7IP9G6S
9+
identity:
10+
type: system_assigned
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
name: banchci
22
type: computeinstance
33
description: some_desc_ci
4-
location: eastus
5-
6-
size: Standard_DS2_v2
7-
8-
ssh_public_access_enabled: False
4+
size: Standard_DS3_v2
5+
ssh_public_access_enabled: false
96
ssh_settings:
7+
admin_username: azureuser
108
ssh_key_value: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDWm/4TTHMZdzZVJcob2aFRWDmIyJLxk028AKh7K03RDgR8bz/Knd9DgB2V3sipjY9wYJ1U9YbsUoAt24+CWZFpnoB79J6vaoqwUb7c6nGkaNrWoGZKI+v26GOX8O2MUjjOyBuPEinJtQ432J4affHfeRI+1iDQXuwFUKhNbRVpxh2h9otXF+J1UvSUaPYggS7Iivyha/x8HJzFcNnIPrAZkPiT/Nb/Qk7FyoFTEw64cIl1ByvmF3ewSOeVXKDpb2d4vrSDTVmXFKRrWduhM3sHO5dckREKc+tSQ0M+SpfBqaBgRTAie4jFVSIiSHCvL2BRQXBMRiyPgNlpiJWTPLp/ administrator@MININT-7IP9G6S
11-
identity:
12-
type: system_assigned

0 commit comments

Comments
 (0)
Please sign in to comment.