Skip to content

Commit 75b4da9

Browse files
Azure sdk support for network acls (Azure#38511)
* refactor code * refactor code * Adding IP based access control to SDK * Added test and change logs * Examples to choose one of three Public network access settings * resolved circular dependency * resolved circular dependency * Added Ip based access control support to hub workspace * updated changelog file * removed ipallowlist dependencey * resolved ManagedServiceIdentity version icompatibility issue * fixed breaking test * reformatted code * reformatted code * removed doc example * code refactor * Fixed Generate API Stubs issue * Fixed Generate API Stubs issue * refactor code * add doc string * add doc string * add doc string * add doc string * add doc string * add doc string
1 parent 2faf4cd commit 75b4da9

File tree

12 files changed

+280
-91
lines changed

12 files changed

+280
-91
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## 1.23.0 (unreleased)
33

44
### Features Added
5+
- Added support for IP-based access control to default and hub workspaces.
56
- Add support for additional include in spark component.
67

78
### Bugs Fixed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# ---------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# ---------------------------------------------------------
4+
5+
from marshmallow import ValidationError, fields, post_load, validates_schema
6+
7+
from azure.ai.ml._schema.core.schema import PathAwareSchema
8+
from azure.ai.ml.entities._workspace.network_acls import DefaultActionType, IPRule, NetworkAcls
9+
10+
11+
class IPRuleSchema(PathAwareSchema):
12+
"""Schema for IPRule."""
13+
14+
value = fields.Str(required=True)
15+
16+
@post_load
17+
def make(self, data, **kwargs): # pylint: disable=unused-argument
18+
"""Create an IPRule object from the marshmallow schema.
19+
20+
:param data: The data from which the IPRule is being loaded.
21+
:type data: OrderedDict[str, Any]
22+
:returns: An IPRule object.
23+
:rtype: azure.ai.ml.entities._workspace.network_acls.NetworkAcls.IPRule
24+
"""
25+
return IPRule(**data)
26+
27+
28+
class NetworkAclsSchema(PathAwareSchema):
29+
"""Schema for NetworkAcls.
30+
31+
:param default_action: Specifies the default action when no IP rules are matched.
32+
:type default_action: str
33+
:param ip_rules: Rules governing the accessibility of a resource from a specific IP address or IP range.
34+
:type ip_rules: Optional[List[IPRule]]
35+
"""
36+
37+
default_action = fields.Str(required=True)
38+
ip_rules = fields.List(fields.Nested(IPRuleSchema), allow_none=True)
39+
40+
@post_load
41+
def make(self, data, **kwargs): # pylint: disable=unused-argument
42+
"""Create a NetworkAcls object from the marshmallow schema.
43+
44+
:param data: The data from which the NetworkAcls is being loaded.
45+
:type data: OrderedDict[str, Any]
46+
:returns: A NetworkAcls object.
47+
:rtype: azure.ai.ml.entities._workspace.network_acls.NetworkAcls
48+
"""
49+
return NetworkAcls(**data)
50+
51+
@validates_schema
52+
def validate_schema(self, data, **kwargs): # pylint: disable=unused-argument
53+
"""Validate the NetworkAcls schema.
54+
55+
:param data: The data to validate.
56+
:type data: OrderedDict[str, Any]
57+
:raises ValidationError: If the schema is invalid.
58+
"""
59+
if data["default_action"] not in set([DefaultActionType.DENY, DefaultActionType.ALLOW]):
60+
raise ValidationError("Invalid value for default_action. Must be 'Deny' or 'Allow'.")
61+
62+
if data["default_action"] == DefaultActionType.DENY and not data.get("ip_rules"):
63+
raise ValidationError("ip_rules must be provided when default_action is 'Deny'.")

sdk/ml/azure-ai-ml/azure/ai/ml/_schema/workspace/workspace.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from azure.ai.ml._schema.core.schema import PathAwareSchema
1010
from azure.ai.ml._schema.workspace.customer_managed_key import CustomerManagedKeySchema
1111
from azure.ai.ml._schema.workspace.identity import IdentitySchema
12+
from azure.ai.ml._schema.workspace.network_acls import NetworkAclsSchema
1213
from azure.ai.ml._schema.workspace.networking import ManagedNetworkSchema
1314
from azure.ai.ml._schema.workspace.serverless_compute import ServerlessComputeSettingsSchema
1415
from azure.ai.ml._utils.utils import snake_to_pascal
@@ -36,6 +37,7 @@ class WorkspaceSchema(PathAwareSchema):
3637
allowed_values=[PublicNetworkAccess.DISABLED, PublicNetworkAccess.ENABLED],
3738
casing_transform=snake_to_pascal,
3839
)
40+
network_acls = NestedField(NetworkAclsSchema)
3941
system_datastores_auth_mode = fields.Str()
4042
identity = NestedField(IdentitySchema)
4143
primary_user_assigned_identity = fields.Str()

sdk/ml/azure-ai-ml/azure/ai/ml/entities/__init__.py

Lines changed: 31 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@
3838
from ._assets.asset import Asset
3939
from ._assets.environment import BuildContext, Environment
4040
from ._assets.intellectual_property import IntellectualProperty
41-
from ._assets.workspace_asset_reference import (
42-
WorkspaceAssetReference as WorkspaceModelReference,
43-
)
41+
from ._assets.workspace_asset_reference import WorkspaceAssetReference as WorkspaceModelReference
4442
from ._autogen_entities.models import (
4543
AzureOpenAIDeployment,
44+
MarketplacePlan,
4645
MarketplaceSubscription,
4746
ServerlessEndpoint,
48-
MarketplacePlan,
4947
)
5048
from ._builders import Command, Parallel, Pipeline, Spark, Sweep
5149
from ._component.command_component import CommandComponent
@@ -54,41 +52,21 @@
5452
from ._component.pipeline_component import PipelineComponent
5553
from ._component.spark_component import SparkComponent
5654
from ._compute._aml_compute_node_info import AmlComputeNodeInfo
57-
from ._compute._custom_applications import (
58-
CustomApplications,
59-
EndpointsSettings,
60-
ImageSettings,
61-
VolumeSettings,
62-
)
55+
from ._compute._custom_applications import CustomApplications, EndpointsSettings, ImageSettings, VolumeSettings
6356
from ._compute._image_metadata import ImageMetadata
64-
from ._compute._schedule import (
65-
ComputePowerAction,
66-
ComputeSchedules,
67-
ComputeStartStopSchedule,
68-
ScheduleState,
69-
)
57+
from ._compute._schedule import ComputePowerAction, ComputeSchedules, ComputeStartStopSchedule, ScheduleState
7058
from ._compute._setup_scripts import ScriptReference, SetupScripts
7159
from ._compute._usage import Usage, UsageName
7260
from ._compute._vm_size import VmSize
7361
from ._compute.aml_compute import AmlCompute, AmlComputeSshSettings
7462
from ._compute.compute import Compute, NetworkSettings
75-
from ._compute.compute_instance import (
76-
AssignedUserConfiguration,
77-
ComputeInstance,
78-
ComputeInstanceSshSettings,
79-
)
63+
from ._compute.compute_instance import AssignedUserConfiguration, ComputeInstance, ComputeInstanceSshSettings
8064
from ._compute.kubernetes_compute import KubernetesCompute
81-
from ._compute.synapsespark_compute import (
82-
AutoPauseSettings,
83-
AutoScaleSettings,
84-
SynapseSparkCompute,
85-
)
65+
from ._compute.synapsespark_compute import AutoPauseSettings, AutoScaleSettings, SynapseSparkCompute
8666
from ._compute.unsupported_compute import UnsupportedCompute
87-
from ._compute.virtual_machine_compute import (
88-
VirtualMachineCompute,
89-
VirtualMachineSshSettings,
90-
)
67+
from ._compute.virtual_machine_compute import VirtualMachineCompute, VirtualMachineSshSettings
9168
from ._credentials import (
69+
AadCredentialConfiguration,
9270
AccessKeyConfiguration,
9371
AccountKeyConfiguration,
9472
AmlTokenConfiguration,
@@ -97,7 +75,6 @@
9775
IdentityConfiguration,
9876
ManagedIdentityConfiguration,
9977
NoneCredentialConfiguration,
100-
AadCredentialConfiguration,
10178
PatTokenConfiguration,
10279
SasTokenConfiguration,
10380
ServicePrincipalConfiguration,
@@ -107,11 +84,7 @@
10784
from ._data_import.data_import import DataImport
10885
from ._data_import.schedule import ImportDataSchedule
10986
from ._datastore.adls_gen1 import AzureDataLakeGen1Datastore
110-
from ._datastore.azure_storage import (
111-
AzureBlobDatastore,
112-
AzureDataLakeGen2Datastore,
113-
AzureFileDatastore,
114-
)
87+
from ._datastore.azure_storage import AzureBlobDatastore, AzureDataLakeGen2Datastore, AzureFileDatastore
11588
from ._datastore.datastore import Datastore
11689
from ._datastore.one_lake import OneLakeArtifact, OneLakeDatastore
11790
from ._deployment.batch_deployment import BatchDeployment
@@ -121,11 +94,7 @@
12194
from ._deployment.data_asset import DataAsset
12295
from ._deployment.data_collector import DataCollector
12396
from ._deployment.deployment_collection import DeploymentCollection
124-
from ._deployment.deployment_settings import (
125-
BatchRetrySettings,
126-
OnlineRequestSettings,
127-
ProbeSettings,
128-
)
97+
from ._deployment.deployment_settings import BatchRetrySettings, OnlineRequestSettings, ProbeSettings
12998
from ._deployment.model_batch_deployment import ModelBatchDeployment
13099
from ._deployment.model_batch_deployment_settings import ModelBatchDeploymentSettings
131100
from ._deployment.online_deployment import (
@@ -134,22 +103,16 @@
134103
ManagedOnlineDeployment,
135104
OnlineDeployment,
136105
)
137-
from ._deployment.pipeline_component_batch_deployment import (
138-
PipelineComponentBatchDeployment,
139-
)
106+
from ._deployment.pipeline_component_batch_deployment import PipelineComponentBatchDeployment
140107
from ._deployment.request_logging import RequestLogging
141108
from ._deployment.resource_requirements_settings import ResourceRequirementsSettings
142-
from ._deployment.scale_settings import (
143-
DefaultScaleSettings,
144-
OnlineScaleSettings,
145-
TargetUtilizationScaleSettings,
146-
)
109+
from ._deployment.scale_settings import DefaultScaleSettings, OnlineScaleSettings, TargetUtilizationScaleSettings
147110
from ._endpoint.batch_endpoint import BatchEndpoint
148111
from ._endpoint.endpoint import Endpoint
149112
from ._endpoint.online_endpoint import (
113+
EndpointAadToken,
150114
EndpointAuthKeys,
151115
EndpointAuthToken,
152-
EndpointAadToken,
153116
KubernetesOnlineEndpoint,
154117
ManagedOnlineEndpoint,
155118
OnlineEndpoint,
@@ -158,41 +121,26 @@
158121
from ._feature_set.feature import Feature
159122
from ._feature_set.feature_set_backfill_metadata import FeatureSetBackfillMetadata
160123
from ._feature_set.feature_set_backfill_request import FeatureSetBackfillRequest
161-
from ._feature_set.feature_set_materialization_metadata import (
162-
FeatureSetMaterializationMetadata,
163-
)
124+
from ._feature_set.feature_set_materialization_metadata import FeatureSetMaterializationMetadata
164125
from ._feature_set.feature_set_specification import FeatureSetSpecification
165126
from ._feature_set.feature_window import FeatureWindow
166-
from ._feature_set.materialization_compute_resource import (
167-
MaterializationComputeResource,
168-
)
127+
from ._feature_set.materialization_compute_resource import MaterializationComputeResource
169128
from ._feature_set.materialization_settings import MaterializationSettings
170129
from ._feature_set.materialization_type import MaterializationType
171130
from ._feature_store.feature_store import FeatureStore
172131
from ._feature_store.materialization_store import MaterializationStore
173132
from ._feature_store_entity.data_column import DataColumn
174133
from ._feature_store_entity.data_column_type import DataColumnType
175134
from ._feature_store_entity.feature_store_entity import FeatureStoreEntity
176-
from ._indexes import (
177-
AzureAISearchConfig,
178-
IndexDataSource,
179-
GitSource,
180-
LocalSource,
181-
)
135+
from ._indexes import AzureAISearchConfig, GitSource, IndexDataSource, LocalSource
182136
from ._indexes import ModelConfiguration as IndexModelConfiguration
183137
from ._job.command_job import CommandJob
184138
from ._job.compute_configuration import ComputeConfiguration
185139
from ._job.input_port import InputPort
186140
from ._job.job import Job
187141
from ._job.job_limits import CommandJobLimits
188142
from ._job.job_resource_configuration import JobResourceConfiguration
189-
from ._job.job_service import (
190-
JobService,
191-
JupyterLabJobService,
192-
SshJobService,
193-
TensorBoardJobService,
194-
VsCodeJobService,
195-
)
143+
from ._job.job_service import JobService, JupyterLabJobService, SshJobService, TensorBoardJobService, VsCodeJobService
196144
from ._job.parallel.parallel_task import ParallelTask
197145
from ._job.parallel.retry_settings import RetrySettings
198146
from ._job.parameterized_command import ParameterizedCommand
@@ -208,12 +156,7 @@
208156
from ._monitoring.alert_notification import AlertNotification
209157
from ._monitoring.compute import ServerlessSparkCompute
210158
from ._monitoring.definition import MonitorDefinition
211-
from ._monitoring.input_data import (
212-
FixedInputData,
213-
MonitorInputData,
214-
StaticInputData,
215-
TrailingInputData,
216-
)
159+
from ._monitoring.input_data import FixedInputData, MonitorInputData, StaticInputData, TrailingInputData
217160
from ._monitoring.schedule import MonitorSchedule
218161
from ._monitoring.signals import (
219162
BaselineDataRange,
@@ -261,22 +204,24 @@
261204
from ._schedule.trigger import CronTrigger, RecurrencePattern, RecurrenceTrigger
262205
from ._system_data import SystemData
263206
from ._validation import ValidationResult
207+
from ._workspace._ai_workspaces.hub import Hub
208+
from ._workspace._ai_workspaces.project import Project
264209
from ._workspace.compute_runtime import ComputeRuntime
265-
from ._workspace.connections.workspace_connection import WorkspaceConnection
266210
from ._workspace.connections.connection_subtypes import (
267-
AzureBlobStoreConnection,
268-
MicrosoftOneLakeConnection,
269-
AzureOpenAIConnection,
270-
AzureAIServicesConnection,
211+
APIKeyConnection,
271212
AzureAISearchConnection,
213+
AzureAIServicesConnection,
214+
AzureBlobStoreConnection,
272215
AzureContentSafetyConnection,
216+
AzureOpenAIConnection,
273217
AzureSpeechServicesConnection,
274-
APIKeyConnection,
218+
MicrosoftOneLakeConnection,
275219
OpenAIConnection,
276220
SerpConnection,
277221
ServerlessConnection,
278222
)
279223
from ._workspace.connections.one_lake_artifacts import OneLakeConnectionArtifact
224+
from ._workspace.connections.workspace_connection import WorkspaceConnection
280225
from ._workspace.customer_managed_key import CustomerManagedKey
281226
from ._workspace.diagnose import (
282227
DiagnoseRequestProperties,
@@ -286,6 +231,7 @@
286231
DiagnoseWorkspaceParameters,
287232
)
288233
from ._workspace.feature_store_settings import FeatureStoreSettings
234+
from ._workspace.network_acls import DefaultActionType, IPRule, NetworkAcls
289235
from ._workspace.networking import (
290236
FqdnDestination,
291237
IsolationMode,
@@ -298,13 +244,7 @@
298244
from ._workspace.private_endpoint import EndpointConnection, PrivateEndpoint
299245
from ._workspace.serverless_compute import ServerlessComputeSettings
300246
from ._workspace.workspace import Workspace
301-
from ._workspace._ai_workspaces.hub import Hub
302-
from ._workspace._ai_workspaces.project import Project
303-
from ._workspace.workspace_keys import (
304-
ContainerRegistryCredential,
305-
NotebookAccessKeys,
306-
WorkspaceKeys,
307-
)
247+
from ._workspace.workspace_keys import ContainerRegistryCredential, NotebookAccessKeys, WorkspaceKeys
308248

309249
__all__ = [
310250
"Resource",
@@ -357,6 +297,9 @@
357297
"Model",
358298
"ModelBatchDeployment",
359299
"ModelBatchDeploymentSettings",
300+
"IPRule",
301+
"DefaultActionType",
302+
"NetworkAcls",
360303
"Workspace",
361304
"WorkspaceKeys",
362305
"WorkspaceConnection",

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_workspace/_ai_workspaces/hub.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
from azure.ai.ml._schema.workspace import HubSchema
1111
from azure.ai.ml._utils._experimental import experimental
1212
from azure.ai.ml.constants._common import WorkspaceKind
13-
from azure.ai.ml.entities import CustomerManagedKey, Workspace
1413
from azure.ai.ml.entities._credentials import IdentityConfiguration
14+
from azure.ai.ml.entities._workspace.customer_managed_key import CustomerManagedKey
15+
from azure.ai.ml.entities._workspace.network_acls import NetworkAcls
1516
from azure.ai.ml.entities._workspace.networking import ManagedNetwork
17+
from azure.ai.ml.entities._workspace.workspace import Workspace
1618

1719

1820
@experimental
@@ -54,6 +56,8 @@ class Hub(Workspace):
5456
:param public_network_access: Whether to allow public endpoint connectivity.
5557
when a workspace is private link enabled.
5658
:type public_network_access: str
59+
:param network_acls: The network access control list (ACL) settings of the workspace.
60+
:type network_acls: ~azure.ai.ml.entities.NetworkAcls
5761
:param identity: The hub's Managed Identity (user assigned, or system assigned).
5862
:type identity: ~azure.ai.ml.entities.IdentityConfiguration
5963
:param primary_user_assigned_identity: The hub's primary user assigned identity.
@@ -92,6 +96,7 @@ def __init__(
9296
container_registry: Optional[str] = None,
9397
customer_managed_key: Optional[CustomerManagedKey] = None,
9498
public_network_access: Optional[str] = None,
99+
network_acls: Optional[NetworkAcls] = None,
95100
identity: Optional[IdentityConfiguration] = None,
96101
primary_user_assigned_identity: Optional[str] = None,
97102
enable_data_isolation: bool = False,
@@ -115,6 +120,7 @@ def __init__(
115120
resource_group=resource_group,
116121
customer_managed_key=customer_managed_key,
117122
public_network_access=public_network_access,
123+
network_acls=network_acls,
118124
identity=identity,
119125
primary_user_assigned_identity=primary_user_assigned_identity,
120126
managed_network=managed_network,
@@ -152,6 +158,7 @@ def _from_rest_object(cls, rest_obj: RestWorkspace, v2_service_context: Optional
152158
managed_network=workspace_object.managed_network,
153159
customer_managed_key=workspace_object.customer_managed_key,
154160
public_network_access=workspace_object.public_network_access,
161+
network_acls=workspace_object.network_acls,
155162
identity=workspace_object.identity,
156163
primary_user_assigned_identity=workspace_object.primary_user_assigned_identity,
157164
storage_account=rest_obj.storage_account,

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_workspace/_ai_workspaces/project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
from typing import Any, Dict, Optional
77

8-
from azure.ai.ml._utils._experimental import experimental
98
from azure.ai.ml._schema.workspace import ProjectSchema
9+
from azure.ai.ml._utils._experimental import experimental
1010
from azure.ai.ml.constants._common import WorkspaceKind
11-
from azure.ai.ml.entities import Workspace
11+
from azure.ai.ml.entities._workspace.workspace import Workspace
1212

1313

1414
# Effectively a lightweight wrapper around a v2 SDK workspace

0 commit comments

Comments
 (0)