Skip to content

Commit 1f2d810

Browse files
authored
Add workload tenant id support (Azure#30862)
* Add workload tenant id support * update
1 parent a2519c2 commit 1f2d810

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

sdk/identity/azure-identity/azure/identity/_credentials/default.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class DefaultAzureCredential(ChainedTokenCredential):
7272
of the environment variable AZURE_CLIENT_ID, if any. If not specified, a system-assigned identity will be used.
7373
:keyword str workload_identity_client_id: The client ID of an identity assigned to the pod. Defaults to the value
7474
of the environment variable AZURE_CLIENT_ID, if any. If not specified, the pod's default identity will be used.
75+
:keyword str workload_identity_tenant_id: Preferred tenant for :class:`~azure.identity.WorkloadIdentityCredential`.
76+
Defaults to the value of environment variable AZURE_TENANT_ID, if any.
7577
:keyword str interactive_browser_client_id: The client ID to be used in interactive browser credential. If not
7678
specified, users will authenticate to an Azure development application.
7779
:keyword str shared_cache_username: Preferred username for :class:`~azure.identity.SharedTokenCacheCredential`.
@@ -95,7 +97,7 @@ class DefaultAzureCredential(ChainedTokenCredential):
9597
:caption: Create a DefaultAzureCredential.
9698
"""
9799

98-
def __init__(self, **kwargs: Any) -> None: # pylint: disable=too-many-statements
100+
def __init__(self, **kwargs: Any) -> None: # pylint: disable=too-many-statements, too-many-locals
99101
if "tenant_id" in kwargs:
100102
raise TypeError("'tenant_id' is not supported in DefaultAzureCredential.")
101103

@@ -122,6 +124,9 @@ def __init__(self, **kwargs: Any) -> None: # pylint: disable=too-many-statement
122124
workload_identity_client_id = kwargs.pop(
123125
"workload_identity_client_id", managed_identity_client_id
124126
)
127+
workload_identity_tenant_id = kwargs.pop(
128+
"workload_identity_tenant_id", os.environ.get(EnvironmentVariables.AZURE_TENANT_ID)
129+
)
125130
interactive_browser_client_id = kwargs.pop("interactive_browser_client_id", None)
126131

127132
shared_cache_username = kwargs.pop("shared_cache_username", os.environ.get(EnvironmentVariables.AZURE_USERNAME))
@@ -149,7 +154,7 @@ def __init__(self, **kwargs: Any) -> None: # pylint: disable=too-many-statement
149154
client_id = workload_identity_client_id
150155
credentials.append(WorkloadIdentityCredential(
151156
client_id=cast(str, client_id),
152-
tenant_id=os.environ[EnvironmentVariables.AZURE_TENANT_ID],
157+
tenant_id=workload_identity_tenant_id,
153158
file=os.environ[EnvironmentVariables.AZURE_FEDERATED_TOKEN_FILE],
154159
**kwargs))
155160
if not exclude_managed_identity_credential:

sdk/identity/azure-identity/azure/identity/aio/_credentials/default.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class DefaultAzureCredential(ChainedTokenCredential):
6666
of the environment variable AZURE_CLIENT_ID, if any. If not specified, a system-assigned identity will be used.
6767
:keyword str workload_identity_client_id: The client ID of an identity assigned to the pod. Defaults to the value
6868
of the environment variable AZURE_CLIENT_ID, if any. If not specified, the pod's default identity will be used.
69+
:keyword str workload_identity_tenant_id: Preferred tenant for :class:`~azure.identity.WorkloadIdentityCredential`.
70+
Defaults to the value of environment variable AZURE_TENANT_ID, if any.
6971
:keyword str shared_cache_username: Preferred username for :class:`~azure.identity.aio.SharedTokenCacheCredential`.
7072
Defaults to the value of environment variable AZURE_USERNAME, if any.
7173
:keyword str shared_cache_tenant_id: Preferred tenant for :class:`~azure.identity.aio.SharedTokenCacheCredential`.
@@ -115,6 +117,9 @@ def __init__(self, **kwargs: Any) -> None:
115117
workload_identity_client_id = kwargs.pop(
116118
"workload_identity_client_id", managed_identity_client_id
117119
)
120+
workload_identity_tenant_id = kwargs.pop(
121+
"workload_identity_tenant_id", os.environ.get(EnvironmentVariables.AZURE_TENANT_ID)
122+
)
118123

119124
vscode_tenant_id = kwargs.pop(
120125
"visual_studio_code_tenant_id", os.environ.get(EnvironmentVariables.AZURE_TENANT_ID)
@@ -139,7 +144,7 @@ def __init__(self, **kwargs: Any) -> None:
139144
client_id = workload_identity_client_id
140145
credentials.append(WorkloadIdentityCredential(
141146
client_id=cast(str, client_id),
142-
tenant_id=os.environ[EnvironmentVariables.AZURE_TENANT_ID],
147+
tenant_id=workload_identity_tenant_id,
143148
file=os.environ[EnvironmentVariables.AZURE_FEDERATED_TOKEN_FILE],
144149
**kwargs))
145150
if not exclude_managed_identity_credential:

sdk/search/azure-search-documents/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Features Added
66

7+
- Added `workload_identity_tenant_id` support in `DefaultAzureCredential`.
8+
79
### Breaking Changes
810

911
### Bugs Fixed

0 commit comments

Comments
 (0)