Skip to content

Commit 8dc3f26

Browse files
authored
Merge pull request microsoft#51 from microsoft/eedorenko/auth-error-fix
Authentication error fix
2 parents 41ea9b7 + 64bb1b0 commit 8dc3f26

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

docs/getting_started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Add a command line step **Run Training Pipeline** with the following script:
127127
```bash
128128
docker run -v $(System.DefaultWorkingDirectory)/_ci-build/mlops-pipelines/ml_service/pipelines:/pipelines \
129129
-w=/pipelines -e MODEL_NAME=$MODEL_NAME -e EXPERIMENT_NAME=$EXPERIMENT_NAME \
130-
-e TENANT_ID=$TENANT_ID -e SP_APP_ID=$SP_APP_ID -e SP_APP_SECRET=$SP_APP_SECRET \
130+
-e TENANT_ID=$TENANT_ID -e SP_APP_ID=$SP_APP_ID -e SP_APP_SECRET=$(SP_APP_SECRET) \
131131
mcr.microsoft.com/mlops/python:latest python run_train_pipeline.py
132132
```
133133

environment_setup/docker-image-pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trigger:
1515

1616
variables:
1717
containerRegistry: $[coalesce(variables['acrServiceConnection'], 'acrconnection')]
18-
imageName: $[coalesce(variables['agentImageName'], 'public/mlops/mlopspython')]
18+
imageName: $[coalesce(variables['agentImageName'], 'public/mlops/python')]
1919

2020
steps:
2121
- task: Docker@2

ml_service/pipelines/run_train_pipeline.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
import os
33
import json
44
import requests
5-
from azureml.core.authentication import AzureCliAuthentication
5+
from azure.common.credentials import ServicePrincipalCredentials
66

77

8+
tenant_id = os.environ.get("TENANT_ID")
9+
app_id = os.environ.get("SP_APP_ID")
10+
app_secret = os.environ.get("SP_APP_SECRET")
11+
812
try:
913
with open("train_pipeline.json") as f:
1014
train_pipeline_json = json.load(f)
@@ -15,13 +19,20 @@
1519
experiment_name = os.environ.get("EXPERIMENT_NAME")
1620
model_name = os.environ.get("MODEL_NAME")
1721

18-
cli_auth = AzureCliAuthentication()
19-
token = cli_auth.get_authentication_header()
22+
credentials = ServicePrincipalCredentials(
23+
client_id=app_id,
24+
secret=app_secret,
25+
tenant=tenant_id
26+
)
27+
28+
token = credentials.token['access_token']
29+
print("token", token)
30+
auth_header = {"Authorization": "Bearer " + token}
2031

2132
rest_endpoint = train_pipeline_json["rest_endpoint"]
2233

2334
response = requests.post(
24-
rest_endpoint, headers=token,
35+
rest_endpoint, headers=auth_header,
2536
json={"ExperimentName": experiment_name,
2637
"ParameterAssignments": {"model_name": model_name}}
2738
)

0 commit comments

Comments
 (0)