Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
d0fcdff
Update changelog (#35929)
xiangyan99 Jun 5, 2024
8c581a2
Autoinstrumentation rework (#35890)
jeremydvoss Jun 5, 2024
72919a9
switch to majority entra auth for tests (#35581)
kristapratico Jun 6, 2024
428ccf2
add a new parameter allow_roleassignment_on_rg to allow/disallow role…
wenjie1070116 Jun 6, 2024
61138a7
Increment package version after release of azure-core (#35950)
azure-sdk Jun 6, 2024
e6f98bc
[Event Hubs] Update URI used for consumer auth to include consumer gr…
swathipil Jun 6, 2024
697a9bf
Allow configuration of metric Views in distro (#35932)
lzchen Jun 6, 2024
bf4ee7f
[EventHub] Update README for enable logging section (#35955)
swathipil Jun 6, 2024
215bb40
[Storage] [STG 94] Merge STG 94 into `main` branch (#35888)
weirongw23-msft Jun 6, 2024
6e6648a
Sync eng/common directory with azure-sdk-tools for PR 8377 (#35915)
azure-sdk Jun 6, 2024
a73ca09
Distro release 1.6.0 (#35935)
jeremydvoss Jun 6, 2024
ae48eea
Python client for Model-as-a-Service (MaaS) / Model-as-a-Platform (Ma…
dargilco Jun 7, 2024
610da5d
[AutoRelease] t2-datafactory-2024-06-03-75602(can only be merged by S…
azure-sdk Jun 7, 2024
5b30781
Use DOTNET_ROLL_FORWARD: 'Major' for test-proxy (#35956)
azure-sdk Jun 7, 2024
acd606f
Pin pester version to 5.5.0 (#35967)
azure-sdk Jun 7, 2024
6bb9e47
Some minor updates to package & samples README.md files (#35971)
dargilco Jun 7, 2024
0b99ee1
add aoai assistants streaming/v2 tests (#35443)
kristapratico Jun 7, 2024
9b98575
[Identity] Allow use of client assertion in OBO cred (#35812)
pvaneck Jun 7, 2024
984542f
[Identity] Disable live service principal tests (#35958)
pvaneck Jun 7, 2024
a7cb46a
set storage account access to identity-based for feature store creati…
runhli Jun 7, 2024
9b6427c
Change Workspace related PR reviewer (#35921)
debuggerXi Jun 10, 2024
8abbc26
[EG] GA Namespaces (#35831)
l0lawrence Jun 10, 2024
f24b567
Increment package version after release of azure-monitor-opentelemetr…
azure-sdk Jun 10, 2024
c9b1e27
update test for new structure of custom blocklist (#36001)
kristapratico Jun 10, 2024
ec8190c
Update github-event-processor to 1.0.0-dev.20240610.2 (#36000)
azure-sdk Jun 10, 2024
81de947
[Identity] Minor doc updates (#35974)
pvaneck Jun 10, 2024
2ac0060
allow for futher embedded snippets (#36004)
l0lawrence Jun 10, 2024
40cf085
[Monitor Query + Ingestions] Update changelogs (#35942)
pvaneck Jun 10, 2024
cb065ac
[Identity] Managed identity bug fix (#36010)
pvaneck Jun 10, 2024
fe0e014
Added release dates (#36006)
vincenttran-msft Jun 10, 2024
5b55203
Remove MayankKumar91 (#35911)
lmazuel Jun 10, 2024
adbac73
Increment package version after release of azure-identity (#36015)
azure-sdk Jun 10, 2024
10c3c79
Always run analyze weekly (#35968)
kristapratico Jun 11, 2024
433b99a
move samples (#35966)
l0lawrence Jun 11, 2024
4356326
[Key Vault] Change location for weekly China cloud tests (#36018)
mccoyp Jun 11, 2024
5fd14fe
Fix Sphinx on azure-storage-blob-changefeed (#35975)
Jun 11, 2024
dff6744
update release date (#36028)
l0lawrence Jun 11, 2024
b052da8
azure-mgmt-core shouldn't use mgmt docs build (#35936)
kristapratico Jun 11, 2024
d97ff44
Identity credential unavailable error non json imds (#36016)
xiangyan99 Jun 11, 2024
e08b3b0
Update azure-ai-inference client library to support sending images as…
dargilco Jun 11, 2024
cf49b4e
Export InputTypes from constants (#35848)
emepetres Jun 11, 2024
a79c5ab
[EG] Eventgrid Release (#36030)
l0lawrence Jun 11, 2024
47fdf5d
Fix Sphinx on azure-storage-blob (#36014)
Jun 11, 2024
1552259
[Identity] Update AzurePipelinesCredential (#35858)
pvaneck Jun 11, 2024
01fa69c
upgrade autorest.python to `6.13.19` (#36024)
msyyc Jun 12, 2024
215eb63
Increment version for monitor releases (#36036)
azure-sdk Jun 12, 2024
bfd541b
compatible with new date format (#36049)
msyyc Jun 12, 2024
5b61bd4
[AutoRelease] t2-cdn-2024-06-12-45722(can only be merged by SDK owner…
azure-sdk Jun 12, 2024
614a928
[EG] link + patch update (#36045)
l0lawrence Jun 12, 2024
80ecdfb
async with (#36060)
l0lawrence Jun 12, 2024
2aba54e
Incremental (#36040)
vincenttran-msft Jun 12, 2024
379cfd3
typo (#36062)
l0lawrence Jun 12, 2024
c5e1659
Fix prepare-pipelines line wrapping (#36061)
azure-sdk Jun 12, 2024
fda24bd
[bct] Initial refactoring breaking changes tool (#36005)
catalinaperalta Jun 12, 2024
a642e74
Update swagger_to_sdk_config_dpg.json (#36068)
msyyc Jun 13, 2024
3ce8196
Increment package version after release of azure-eventgrid (#36063)
azure-sdk Jun 13, 2024
66d5de4
Sync eng/common directory with azure-sdk-tools for PR 8388 (#35970)
azure-sdk Jun 13, 2024
15bcb99
report number of breaking changes (#36067)
catalinaperalta Jun 13, 2024
0f27374
update codeowner (#36074)
xiangyan99 Jun 13, 2024
d7bfdb0
update strict-sphinx to v7 (#36075)
kristapratico Jun 13, 2024
df9c8c7
Update spelling dependencies (#36084)
azure-sdk Jun 14, 2024
3e7dff6
[DevCenter] Update release date (#36083)
drielenr Jun 14, 2024
147746b
[Identity] Add TSG section for AzurePipelinesCredential (#36048)
pvaneck Jun 14, 2024
c19f701
Support sending image data as part of a user message, using a new Ima…
dargilco Jun 14, 2024
ee65563
update (#36051)
msyyc Jun 14, 2024
892881a
Increment package version after release of azure-ai-inference (#36091)
azure-sdk Jun 14, 2024
c6383aa
address API review comments (#36058)
Adarsh-Ramanathan Jun 14, 2024
811dc0e
Update CodeownersLinter version to 1.0.0-dev.20240614.4 (#36093)
azure-sdk Jun 14, 2024
fe435b7
[AutoRelease] t2-mobilenetwork-2024-06-05-65505(can only be merged by…
azure-sdk Jun 17, 2024
a566320
[AutoRelease] t2-storagemover-2024-06-11-87054(can only be merged by …
azure-sdk Jun 17, 2024
698cd95
code and test (#35959)
azure-sdk Jun 17, 2024
40a2625
[AutoRelease] t2-web-2024-06-07-57417(can only be merged by SDK owner…
azure-sdk Jun 17, 2024
3c833e1
Update breaking_changes_allowlist.py (#36104)
msyyc Jun 17, 2024
323fdc7
appconfig mi test (#35842)
xiangyan99 Jun 17, 2024
c51ac91
Bugfix: None was being appended to output path for batch-endpoint inv…
nagkumar91 Jun 17, 2024
cd1725e
Sync eng/common directory with azure-sdk-tools for PR 8457 (#36113)
azure-sdk Jun 17, 2024
d791bc6
Merge branch 'main' into 1.17.0-core-main-merge
MilesHolland Jun 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Identity] Managed identity bug fix (#36010)
Signed-off-by: Paul Van Eck <[email protected]>
  • Loading branch information
pvaneck authored Jun 10, 2024
commit cb065acd7d0f957327dc4f02d1646d4e51a94178
12 changes: 11 additions & 1 deletion sdk/identity/azure-identity/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# Release History

## 1.17.0 (2024-06-11)
## 1.17.0b2 (2024-06-11)

### Features Added

- `OnBehalfOfCredential` now supports client assertion callbacks through the `client_assertion_func` keyword argument. This enables authenticating with client assertions such as federated credentials. ([#35812](https://github.com/Azure/azure-sdk-for-python/pull/35812))

### Bugs Fixed

- Managed identity bug fixes

## 1.16.1 (2024-06-11)

### Bugs Fixed

- Managed identity bug fixes

## 1.17.0b1 (2024-05-13)

### Features Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# ------------------------------------
import functools
import os
import sys
from typing import Any, Dict, Optional

from azure.core.exceptions import ClientAuthenticationError
Expand All @@ -24,7 +25,7 @@ def get_client(self, **kwargs: Any) -> Optional[ManagedIdentityClient]:
return ManagedIdentityClient(
_per_retry_policies=[ArcChallengeAuthPolicy()],
request_factory=functools.partial(_get_request, url),
**kwargs
**kwargs,
)
return None

Expand Down Expand Up @@ -70,6 +71,12 @@ def _get_secret_key(response: PipelineResponse) -> str:
raise ClientAuthenticationError(
message="Did not receive a correct value from WWW-Authenticate header: {}".format(header)
) from ex

try:
_validate_key_file(key_file)
except ValueError as ex:
raise ClientAuthenticationError(message="The key file path is invalid: {}".format(ex)) from ex

with open(key_file, "r", encoding="utf-8") as file:
try:
return file.read()
Expand All @@ -80,6 +87,53 @@ def _get_secret_key(response: PipelineResponse) -> str:
) from error


def _get_key_file_path() -> str:
"""Returns the expected path for the Azure Arc MSI key file based on the current platform.

Only Linux and Windows are supported.

:return: The expected path.
:rtype: str
:raises ValueError: If the current platform is not supported.
"""
if sys.platform.startswith("linux"):
return "/var/opt/azcmagent/tokens"
if sys.platform.startswith("win"):
program_data_path = os.environ.get("PROGRAMDATA")
if not program_data_path:
raise ValueError("PROGRAMDATA environment variable is not set or is empty.")
return os.path.join(f"{program_data_path}", "AzureConnectedMachineAgent", "Tokens")
raise ValueError(f"Azure Arc MSI is not supported on this platform {sys.platform}")


def _validate_key_file(file_path: str) -> None:
"""Validates that a given Azure Arc MSI file path is valid for use.

A valid file will:
1. Be in the expected path for the current platform.
2. Have a `.key` extension.
3. Be at most 4096 bytes in size.

:param str file_path: The path to the key file.
:raises ClientAuthenticationError: If the file path is invalid.
"""
if not file_path:
raise ValueError("The file path must not be empty.")

if not os.path.exists(file_path):
raise ValueError(f"The file path does not exist: {file_path}")

expected_directory = _get_key_file_path()
if not os.path.dirname(file_path) == expected_directory:
raise ValueError(f"Unexpected file path from HIMDS service: {file_path}")

if not file_path.endswith(".key"):
raise ValueError("The file path must have a '.key' extension.")

if os.path.getsize(file_path) > 4096:
raise ValueError("The file size must be less than or equal to 4096 bytes.")


class ArcChallengeAuthPolicy(HTTPPolicy):
"""Policy for handling Azure Arc's challenge authentication"""

Expand Down
2 changes: 1 addition & 1 deletion sdk/identity/azure-identity/azure/identity/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
VERSION = "1.17.0"
VERSION = "1.17.0b2"
2 changes: 1 addition & 1 deletion sdk/identity/azure-identity/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
url="https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity",
keywords="azure, azure sdk",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
Expand Down
132 changes: 124 additions & 8 deletions sdk/identity/azure-identity/tests/test_managed_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the MIT License.
# ------------------------------------
import os
import sys
import time

try:
Expand Down Expand Up @@ -883,9 +884,10 @@ def test_azure_arc(tmpdir):
"os.environ",
{EnvironmentVariables.IDENTITY_ENDPOINT: identity_endpoint, EnvironmentVariables.IMDS_ENDPOINT: imds_endpoint},
):
token = ManagedIdentityCredential(transport=transport).get_token(scope)
assert token.token == access_token
assert token.expires_on == expires_on
with mock.patch("azure.identity._credentials.azure_arc._validate_key_file", lambda x: None):
token = ManagedIdentityCredential(transport=transport).get_token(scope)
assert token.token == access_token
assert token.expires_on == expires_on


def test_azure_arc_tenant_id(tmpdir):
Expand Down Expand Up @@ -936,9 +938,10 @@ def test_azure_arc_tenant_id(tmpdir):
"os.environ",
{EnvironmentVariables.IDENTITY_ENDPOINT: identity_endpoint, EnvironmentVariables.IMDS_ENDPOINT: imds_endpoint},
):
token = ManagedIdentityCredential(transport=transport).get_token(scope, tenant_id="tenant_id")
assert token.token == access_token
assert token.expires_on == expires_on
with mock.patch("azure.identity._credentials.azure_arc._validate_key_file", lambda x: None):
token = ManagedIdentityCredential(transport=transport).get_token(scope, tenant_id="tenant_id")
assert token.token == access_token
assert token.expires_on == expires_on


def test_azure_arc_client_id():
Expand All @@ -950,10 +953,123 @@ def test_azure_arc_client_id():
EnvironmentVariables.IMDS_ENDPOINT: "http://localhost:42",
},
):
credential = ManagedIdentityCredential(client_id="some-guid")
with mock.patch("azure.identity._credentials.azure_arc._validate_key_file", lambda x: None):
credential = ManagedIdentityCredential(client_id="some-guid")

with pytest.raises(ClientAuthenticationError):
with pytest.raises(ClientAuthenticationError) as ex:
credential.get_token("scope")
assert "not supported" in str(ex.value)


def test_azure_arc_key_too_large(tmp_path):

api_version = "2019-11-01"
identity_endpoint = "http://localhost:42/token"
imds_endpoint = "http://localhost:42"
scope = "scope"
secret_key = "X" * 4097

key_file = tmp_path / "key_file.key"
key_file.write_text(secret_key)
assert key_file.read_text() == secret_key

transport = validating_transport(
requests=[
Request(
base_url=identity_endpoint,
method="GET",
required_headers={"Metadata": "true"},
required_params={"api-version": api_version, "resource": scope},
),
],
responses=[
mock_response(status_code=401, headers={"WWW-Authenticate": "Basic realm={}".format(key_file)}),
],
)

with mock.patch(
"os.environ",
{EnvironmentVariables.IDENTITY_ENDPOINT: identity_endpoint, EnvironmentVariables.IMDS_ENDPOINT: imds_endpoint},
):
with mock.patch("azure.identity._credentials.azure_arc._get_key_file_path", lambda: str(tmp_path)):
with pytest.raises(ClientAuthenticationError) as ex:
ManagedIdentityCredential(transport=transport).get_token(scope)
assert "file size" in str(ex.value)


def test_azure_arc_key_not_exist(tmp_path):

api_version = "2019-11-01"
identity_endpoint = "http://localhost:42/token"
imds_endpoint = "http://localhost:42"
scope = "scope"

transport = validating_transport(
requests=[
Request(
base_url=identity_endpoint,
method="GET",
required_headers={"Metadata": "true"},
required_params={"api-version": api_version, "resource": scope},
),
],
responses=[
mock_response(status_code=401, headers={"WWW-Authenticate": "Basic realm=/path/to/key_file"}),
],
)

with mock.patch(
"os.environ",
{EnvironmentVariables.IDENTITY_ENDPOINT: identity_endpoint, EnvironmentVariables.IMDS_ENDPOINT: imds_endpoint},
):
with pytest.raises(ClientAuthenticationError) as ex:
ManagedIdentityCredential(transport=transport).get_token(scope)
assert "not exist" in str(ex.value)


def test_azure_arc_key_invalid(tmp_path):

api_version = "2019-11-01"
identity_endpoint = "http://localhost:42/token"
imds_endpoint = "http://localhost:42"
scope = "scope"
key_file = tmp_path / "key_file.txt"
key_file.write_text("secret")

transport = validating_transport(
requests=[
Request(
base_url=identity_endpoint,
method="GET",
required_headers={"Metadata": "true"},
required_params={"api-version": api_version, "resource": scope},
),
Request(
base_url=identity_endpoint,
method="GET",
required_headers={"Metadata": "true"},
required_params={"api-version": api_version, "resource": scope},
),
],
responses=[
mock_response(status_code=401, headers={"WWW-Authenticate": "Basic realm={}".format(key_file)}),
mock_response(status_code=401, headers={"WWW-Authenticate": "Basic realm={}".format(key_file)}),
],
)

with mock.patch(
"os.environ",
{EnvironmentVariables.IDENTITY_ENDPOINT: identity_endpoint, EnvironmentVariables.IMDS_ENDPOINT: imds_endpoint},
):
with mock.patch("azure.identity._credentials.azure_arc._get_key_file_path", lambda: "/foo"):
with pytest.raises(ClientAuthenticationError) as ex:
ManagedIdentityCredential(transport=transport).get_token(scope)
assert "Unexpected file path" in str(ex.value)

with mock.patch("azure.identity._credentials.azure_arc._get_key_file_path", lambda: str(tmp_path)):
with pytest.raises(ClientAuthenticationError) as ex:
ManagedIdentityCredential(transport=transport).get_token(scope)
assert "extension" in str(ex.value)


def test_token_exchange(tmpdir):
Expand Down
Loading