Skip to content

Commit 76714cc

Browse files
Merge pull request #393 from Blackmist/314429-connection
oauth info
2 parents c3b3a2c + f269a55 commit 76714cc

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

articles/machine-learning/how-to-connection.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,92 @@ ml_client.connections.create_or_update(workspace_connection=wps_connection)
153153

154154
---
155155

156+
## Create a Snowflake DB connection that uses OAuth
157+
158+
The information in this section describe how to create a Snowflake DB connection that uses OAuth to authenticate.
159+
160+
> [!IMPORTANT]
161+
> Before following the steps in this section, you must first [Configure Azure to issue OAuth tokens on behalf of the client](https://community.snowflake.com/s/article/Create-External-OAuth-Token-Using-Azure-AD-For-The-OAuth-Client-Itself). This configuration creates a service principal, which is required for the OAuth connection. You need the following information to create the connection:
162+
>
163+
> - Client ID: The ID of the service principal
164+
> - Client Secret: The secret of the service principal
165+
> - Tenant ID: The ID of the Microsoft Entra ID tenant
166+
167+
168+
# [Azure CLI](#tab/cli)
169+
170+
This YAML file creates a Snowflake DB connection that uses OAuth. Be sure to update the appropriate values:
171+
172+
```yaml
173+
# my_snowflakedb_connection.yaml
174+
name: snowflake_service_principal_connection
175+
type: snowflake
176+
# Add the Snowflake account, database, warehouse name, and role name here. If no role name is provided, it will default to PUBLIC.
177+
target: jdbc:snowflake://<myaccount>.snowflakecomputing.com/?db=<mydb>&warehouse=<mywarehouse>&scope=<scopeForServicePrincipal>
178+
credentials:
179+
type: service_principal
180+
client_id: <client-id> # The service principal's client id
181+
client_secret: <client-secret> # The service principal's client secret
182+
tenant_id: <tenant-id> # The Microsoft Entra ID tenant id
183+
```
184+
185+
Create the Azure Machine Learning connection in the CLI:
186+
187+
```azurecli
188+
az ml connection create --file my_snowflakedb_connection.yaml
189+
```
190+
191+
You can also override the information in the YAML file at the command line:
192+
193+
```azurecli
194+
az ml connection create --file my_snowflakedb_connection.yaml --set credentials.client_id="my-client-id" credentials.client_secret="my-client-secret" credentials.tenant_id="my-tenant-id"
195+
```
196+
197+
# [Python SDK](#tab/python)
198+
199+
With the Python SDK, you can create a connection by loading the connection information stored in the YAML file. You can optionally override the values:
200+
201+
```python
202+
from azure.ai.ml import MLClient, load_workspace_connection
203+
204+
ml_client = MLClient.from_config()
205+
206+
wps_connection = load_workspace_connection(source="./my_snowflakedb_connection.yaml")
207+
wps_connection.credentials_client_id="my-client-id"
208+
wps_connection.credentials.client_secret="my-client-secret"
209+
wps_connection.credentials.tenant_id="my-tenant-id"
210+
ml_client.connections.create_or_update(workspace_connection=wps_connection)
211+
212+
```
213+
214+
You can also directly specify the connection information in a Python script without relying on a YAML file:
215+
216+
```python
217+
from azure.ai.ml import MLClient
218+
from azure.ai.ml.entities import WorkspaceConnection
219+
from azure.ai.ml.entities import ServicePrincipalConfiguration
220+
221+
target= "jdbc:snowflake://<myaccount>.snowflakecomputing.com/?db=<mydb>&warehouse=<mywarehouse>&role=<myrole>"
222+
# add the Snowflake account, database, warehouse name and role name here. If no role name provided it will default to PUBLIC
223+
name= <my_snowflake_connection> # name of the connection
224+
auth = ServicePrincipalConfiguration(client_id="<my-client-id>", client_secret="<my-client-secret>", tenant_id="<my-tenant-id>")
225+
wps_connection = WorkspaceConnection(name= name,
226+
type="snowflake",
227+
target=target,
228+
credentials=auth
229+
)
230+
231+
ml_client.connections.create_or_update(workspace_connection=wps_connection)
232+
233+
```
234+
235+
# [Studio](#tab/azure-studio)
236+
237+
> [!NOTE]
238+
> Creation of a Snowflake DB connection using a service principal (for OAuth) is only available through the Azure CLI or Python SDK.
239+
240+
---
241+
156242
## Create an Azure SQL DB connection
157243

158244
# [Azure CLI](#tab/cli)

0 commit comments

Comments
 (0)