@@ -134,23 +134,6 @@ class ManagedIdentityClient(object):
134
134
135
135
It also provides token cache support.
136
136
137
- .. admonition:: Special case when your local development wants to use a managed identity on Azure VM.
138
-
139
- By setting the environment variable ``MSAL_MANAGED_IDENTITY_ENDPOINT``
140
- you override the default identity URL used in MSAL's Azure VM managed identity
141
- code path.
142
-
143
- This is useful during local development where it may be desirable to
144
- utilise the credentials assigned to an actual VM instance via SSH tunnelling.
145
-
146
- For example, if you create your SSH tunnel this way (assuming your VM is on ``192.0.2.1``)::
147
-
148
- ssh -L 8000:169.254.169.254:80 192.0.2.1
149
-
150
- Then your code could run locally using::
151
-
152
- env MSAL_MANAGED_IDENTITY_ENDPOINT=http://localhost:8000/metadata/identity/oauth2/token python your_script.py
153
-
154
137
.. note::
155
138
156
139
Cloud Shell support is NOT implemented in this class.
@@ -171,7 +154,7 @@ def __init__(
171
154
self ,
172
155
managed_identity : Union [
173
156
dict ,
174
- ManagedIdentity , # Could use Type[ManagedIdentity] but it is deprecatred in Python 3.9+
157
+ ManagedIdentity , # Could use Type[ManagedIdentity] but it is deprecated in Python 3.9+
175
158
SystemAssignedManagedIdentity ,
176
159
UserAssignedManagedIdentity ,
177
160
],
@@ -223,7 +206,7 @@ def __init__(
223
206
you may use an environment variable (such as MY_MANAGED_IDENTITY_CONFIG)
224
207
to store a json blob like
225
208
``{"ManagedIdentityIdType": "ClientId", "Id": "foo"}`` or
226
- ``{"ManagedIdentityIdType": "SystemAssignedManagedIdentity ", "Id": null}) ``.
209
+ ``{"ManagedIdentityIdType": "SystemAssigned ", "Id": null}``.
227
210
The following app can load managed identity configuration dynamically::
228
211
229
212
import json, os, msal, requests
@@ -363,10 +346,12 @@ def _scope_to_resource(scope): # This is an experimental reasonable-effort appr
363
346
def _get_arc_endpoint ():
364
347
if "IDENTITY_ENDPOINT" in os .environ and "IMDS_ENDPOINT" in os .environ :
365
348
return os .environ ["IDENTITY_ENDPOINT" ]
366
- if ( # Defined in https://msazure.visualstudio.com/One/_wiki/wikis/One.wiki/233012/VM-Extension-Authoring-for-Arc?anchor=determining-which-endpoint-to-use
367
- sys .platform == "linux" and os .path .exists ("/var/ opt/azcmagent/bin/himds" )
349
+ if ( # Defined in https://eng.ms/docs/cloud-ai-platform/azure-core/azure-management-and-platforms/control-plane-bburns/hybrid-resource-provider/azure-arc-for-servers/specs/extension_authoring
350
+ sys .platform == "linux" and os .path .exists ("/opt/azcmagent/bin/himds" )
368
351
or sys .platform == "win32" and os .path .exists (os .path .expandvars (
369
- r"%ProgramFiles%\AzureConnectedMachineAgent\himds.exe" ))
352
+ # Avoid Windows-only "%EnvVar%" syntax so that tests can be run on Linux
353
+ r"${ProgramFiles}\AzureConnectedMachineAgent\himds.exe"
354
+ ))
370
355
):
371
356
return "http://localhost:40342/metadata/identity/oauth2/token"
372
357
@@ -463,7 +448,7 @@ def _obtain_token_on_azure_vm(http_client, managed_identity, resource):
463
448
}
464
449
_adjust_param (params , managed_identity )
465
450
resp = http_client .get (
466
- os . getenv ( 'MSAL_MANAGED_IDENTITY_ENDPOINT' , ' http://169.254.169.254/metadata/identity/oauth2/token' ) ,
451
+ " http://169.254.169.254/metadata/identity/oauth2/token" ,
467
452
params = params ,
468
453
headers = {"Metadata" : "true" },
469
454
)
@@ -663,4 +648,3 @@ def _obtain_token_on_arc(http_client, endpoint, resource):
663
648
"error" : "invalid_request" ,
664
649
"error_description" : response .text ,
665
650
}
666
-
0 commit comments