Skip to content

Commit 57d0005

Browse files
authored
Merge branch 'dev' into dharshanb/brokerSupportLinux
2 parents 6f52d28 + 7b31756 commit 57d0005

File tree

6 files changed

+86
-27
lines changed

6 files changed

+86
-27
lines changed

azure-pipelines.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Derived from the default YAML generated by Azure DevOps for a Python package
2+
# Create and test a Python package on multiple Python versions.
3+
# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more:
4+
# https://docs.microsoft.com/azure/devops/pipelines/languages/python
5+
6+
trigger:
7+
- dev
8+
- azure-pipelines
9+
10+
pool:
11+
vmImage: ubuntu-latest
12+
strategy:
13+
matrix:
14+
Python39:
15+
python.version: '3.9'
16+
Python310:
17+
python.version: '3.10'
18+
Python311:
19+
python.version: '3.11'
20+
Python312:
21+
python.version: '3.12'
22+
23+
steps:
24+
- task: UsePythonVersion@0
25+
inputs:
26+
versionSpec: '$(python.version)'
27+
displayName: 'Use Python $(python.version)'
28+
29+
- script: |
30+
python -m pip install --upgrade pip
31+
pip install -r requirements.txt
32+
displayName: 'Install dependencies'
33+
34+
- script: |
35+
pip install pytest pytest-azurepipelines
36+
pytest
37+
displayName: 'pytest'

docker_run.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/bash
2+
3+
# Error out if there is less than 1 argument
4+
if [ "$#" -lt 1 ]; then
5+
echo "Usage: $0 <Python_image> [command]"
6+
echo "Example: $0 python:3.14.0a2-slim bash"
7+
exit 1
8+
fi
9+
10+
# We will get a standard Python image from the input,
11+
# so that we don't need to hard code one in a Dockerfile
12+
IMAGE_NAME=$1
13+
14+
echo "=== Starting $IMAGE_NAME (especially those which have no AppImage yet) ==="
15+
echo "After seeing the bash prompt, run the following to test:"
16+
echo " apt update && apt install -y gcc libffi-dev # Needed in Python 3.14.0a2-slim"
17+
echo " pip install -e ."
18+
echo " pytest --capture=no -s tests/chosen_test_file.py"
19+
docker run --rm -it \
20+
--privileged \
21+
-w /home -v $PWD:/home \
22+
$IMAGE_NAME \
23+
$2
24+

msal/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
# The __init__.py will import this. Not the other way around.
25-
__version__ = "1.31.0" # When releasing, also check and bump our dependencies's versions if needed
25+
__version__ = "1.31.1" # When releasing, also check and bump our dependencies's versions if needed
2626

2727
logger = logging.getLogger(__name__)
2828
_AUTHORITY_TYPE_CLOUDSHELL = "CLOUDSHELL"

msal/managed_identity.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -134,23 +134,6 @@ class ManagedIdentityClient(object):
134134
135135
It also provides token cache support.
136136
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-
154137
.. note::
155138
156139
Cloud Shell support is NOT implemented in this class.
@@ -171,7 +154,7 @@ def __init__(
171154
self,
172155
managed_identity: Union[
173156
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+
175158
SystemAssignedManagedIdentity,
176159
UserAssignedManagedIdentity,
177160
],
@@ -223,7 +206,7 @@ def __init__(
223206
you may use an environment variable (such as MY_MANAGED_IDENTITY_CONFIG)
224207
to store a json blob like
225208
``{"ManagedIdentityIdType": "ClientId", "Id": "foo"}`` or
226-
``{"ManagedIdentityIdType": "SystemAssignedManagedIdentity", "Id": null})``.
209+
``{"ManagedIdentityIdType": "SystemAssigned", "Id": null}``.
227210
The following app can load managed identity configuration dynamically::
228211
229212
import json, os, msal, requests
@@ -363,10 +346,12 @@ def _scope_to_resource(scope): # This is an experimental reasonable-effort appr
363346
def _get_arc_endpoint():
364347
if "IDENTITY_ENDPOINT" in os.environ and "IMDS_ENDPOINT" in os.environ:
365348
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")
368351
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+
))
370355
):
371356
return "http://localhost:40342/metadata/identity/oauth2/token"
372357

@@ -463,7 +448,7 @@ def _obtain_token_on_azure_vm(http_client, managed_identity, resource):
463448
}
464449
_adjust_param(params, managed_identity)
465450
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",
467452
params=params,
468453
headers={"Metadata": "true"},
469454
)
@@ -663,4 +648,3 @@ def _obtain_token_on_arc(http_client, endpoint, resource):
663648
"error": "invalid_request",
664649
"error_description": response.text,
665650
}
666-

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ install_requires =
5252
# And we will use the cryptography (X+3).0.0 as the upper bound,
5353
# based on their latest deprecation policy
5454
# https://cryptography.io/en/latest/api-stability/#deprecation
55-
cryptography>=2.5,<46
55+
cryptography>=2.5,<47
5656

5757

5858
[options.extras_require]

tests/test_mi.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,23 @@ def test_machine_learning(self):
347347
"IDENTITY_ENDPOINT": "http://localhost",
348348
"IMDS_ENDPOINT": "http://localhost",
349349
})
350-
def test_arc(self):
350+
def test_arc_by_env_var(self):
351351
self.assertEqual(get_managed_identity_source(), AZURE_ARC)
352352

353+
@patch("msal.managed_identity.os.path.exists", return_value=True)
354+
@patch("msal.managed_identity.sys.platform", new="linux")
355+
def test_arc_by_file_existence_on_linux(self, mocked_exists):
356+
self.assertEqual(get_managed_identity_source(), AZURE_ARC)
357+
mocked_exists.assert_called_with("/opt/azcmagent/bin/himds")
358+
359+
@patch("msal.managed_identity.os.path.exists", return_value=True)
360+
@patch("msal.managed_identity.sys.platform", new="win32")
361+
@patch.dict(os.environ, {"ProgramFiles": "C:\Program Files"})
362+
def test_arc_by_file_existence_on_windows(self, mocked_exists):
363+
self.assertEqual(get_managed_identity_source(), AZURE_ARC)
364+
mocked_exists.assert_called_with(
365+
r"C:\Program Files\AzureConnectedMachineAgent\himds.exe")
366+
353367
@patch.dict(os.environ, {
354368
"AZUREPS_HOST_ENVIRONMENT": "cloud-shell-foo",
355369
})

0 commit comments

Comments
 (0)