Skip to content

Commit 17d5ebd

Browse files
committed
Adding security note
1 parent 9990ced commit 17d5ebd

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

articles/synapse-analytics/machine-learning/tutorial-score-model-predict-spark-pool.md

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,15 @@ Make sure all prerequisites are in place before following these steps for using
8686
> [!NOTE]
8787
> Update tenant, client, subscription, resource group, AML workspace and linked service details in this script before running it.
8888
89-
- **Through service principal:** You can use service principal client ID and secret directly to authenticate to AML workspace. Service principal must have "Contributor" access to the AML workspace.
89+
- **(Recommended) Through linked service:** You can use linked service to authenticate to AML workspace. Linked service can use "service principal" or Synapse workspace's "Managed Service Identity (MSI)" for authentication. "Service principal" or "Managed Service Identity (MSI)" must have "Contributor" access to the AML workspace.
90+
91+
```python
92+
#AML workspace authentication using linked service
93+
from notebookutils.mssparkutils import azureML
94+
ws = azureML.getWorkspace("<linked_service_name>") # "<linked_service_name>" is the linked service name, not AML workspace name. Also, linked service supports MSI and service principal both
95+
```
96+
97+
- **Through service principal:** Though not recommended, you can use service principal client ID and secret directly to authenticate to AML workspace. Providing the service principal password directly poses some security risk, so we suggest using a linked service where possible. Service principal must have "Contributor" access to the AML workspace.
9098

9199
```python
92100
#AML workspace authentication using service principal
@@ -112,14 +120,6 @@ Make sure all prerequisites are in place before following these steps for using
112120
)
113121
```
114122

115-
- **Through linked service:** You can use linked service to authenticate to AML workspace. Linked service can use "service principal" or Synapse workspace's "Managed Service Identity (MSI)" for authentication. "Service principal" or "Managed Service Identity (MSI)" must have "Contributor" access to the AML workspace.
116-
117-
```python
118-
#AML workspace authentication using linked service
119-
from notebookutils.mssparkutils import azureML
120-
ws = azureML.getWorkspace("<linked_service_name>") # "<linked_service_name>" is the linked service name, not AML workspace name. Also, linked service supports MSI and service principal both
121-
```
122-
123123
4. **Enable PREDICT in spark session:** Set the spark configuration `spark.synapse.ml.predict.enabled` to `true` to enable the library.
124124

125125
```python
@@ -331,6 +331,7 @@ Make sure all prerequisites are in place before following these steps for using
331331

332332
from azureml.core import Workspace, Model
333333
from azureml.core.authentication import ServicePrincipalAuthentication
334+
from notebookutils.mssparkutils import azureML
334335

335336
AZURE_TENANT_ID = "xyz"
336337
AZURE_CLIENT_ID = "xyz"
@@ -340,18 +341,8 @@ Make sure all prerequisites are in place before following these steps for using
340341
AML_RESOURCE_GROUP = "xyz"
341342
AML_WORKSPACE_NAME = "xyz"
342343

343-
svc_pr = ServicePrincipalAuthentication(
344-
tenant_id=AZURE_TENANT_ID,
345-
service_principal_id=AZURE_CLIENT_ID,
346-
service_principal_password=AZURE_CLIENT_SECRET
347-
)
348-
349-
ws = Workspace(
350-
workspace_name = AML_WORKSPACE_NAME,
351-
subscription_id = AML_SUBSCRIPTION_ID,
352-
resource_group = AML_RESOURCE_GROUP,
353-
auth=svc_pr
354-
)
344+
#AML workspace authentication using linked service
345+
ws = azureML.getWorkspace("<linked_service_name>") # "<linked_service_name>" is the linked service name, not AML workspace name. Also, linked service supports MSI and service principal both
355346

356347
model = Model.register(
357348
model_path="./artifacts/output",

0 commit comments

Comments
 (0)