Skip to content

Commit 661d7cc

Browse files
authored
Add AzureCliCredential support in Azure orchestrator (#3822)
1 parent aa6915c commit 661d7cc

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

docs/run_test/azure_auth.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Available Authentication Methods
2323
4. `Workload Identity Authentication <#workload-identity-authentication>`__
2424
5. `Token Authentication <#token-authentication>`__
2525
6. `Client Secret Authentication <#client-secret-authentication>`__
26+
7. `Azure CLI Authentication <#azure-cli-authentication>`__
2627

2728
Default Credentials
2829
-------------------
@@ -146,6 +147,26 @@ Example:
146147
tenant_id: <tenant id> # Required
147148
client_secret: <client secret> # Required
148149
150+
Azure CLI Authentication
151+
-----------------------
152+
This authentication uses the Azure CLI for authentication, which requires previously logging in to Azure via "az login". It will use the CLI's currently logged in identity.
153+
154+
Example:
155+
156+
.. code:: yaml
157+
158+
platform:
159+
- type: azure
160+
azure:
161+
credential:
162+
type: azcli
163+
tenant_id: <tenant id> # Optional
164+
allow_all_tenants: false | true # Optional. Default is `false`.
165+
166+
* **type**: `azcli` indicates Azure CLI authentication.
167+
* **tenant_id**: (Optional) Needed to specify a specific tenant for authentication.
168+
* **allow_all_tenants**: (Optional) Specifies whether to allow cross-tenant authorization. Default is `false`.
169+
149170
Schema Description
150171
--------------------
151172

@@ -158,5 +179,6 @@ The configuration follows this schema:
158179
- **secret**: Uses client secret authentication. Requires `client_secret`.
159180
- **workloadidentity**: Uses workload identity authentication.
160181
- **token**: Uses token-based authentication. Requires a valid `token`.
182+
- **azcli**: Uses Azure CLI authentication. Requires previously logging in via "az login" and uses the CLI's currently logged in identity.
161183

162184
**Schema Inheritance:** The `default` authentication method defines a base schema that all other authentication types inherit from. Fields such as `allow_all_tenants` are applicable to all authentication methods.

lisa/sut_orchestrator/azure/credential.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Any, Type, cast
55

66
from azure.identity import (
7+
AzureCliCredential,
78
CertificateCredential,
89
ClientAssertionCredential,
910
ClientSecretCredential,
@@ -28,6 +29,7 @@ class AzureCredentialType(str, Enum):
2829
ClientSecretCredential = "secret"
2930
WorkloadIdentityCredential = "workloadidentity"
3031
TokenCredential = "token"
32+
AzCliCredential = "azcli"
3133

3234

3335
@dataclass_json()
@@ -387,3 +389,41 @@ def __init__(
387389

388390
def get_credential(self) -> Any:
389391
return get_static_access_token(self._token)
392+
393+
394+
class AzureCliCredentialImpl(AzureCredential):
395+
"""
396+
Class to create AzureCliCredential based on runbook Schema. Uses Azure CLI
397+
for authentication which requires logging in to Azure via "az login" first.
398+
"""
399+
400+
@classmethod
401+
def type_name(cls) -> str:
402+
return AzureCredentialType.AzCliCredential
403+
404+
@classmethod
405+
def type_schema(cls) -> Type[schema.TypedSchema]:
406+
return AzureCredentialSchema
407+
408+
def __init__(
409+
self,
410+
runbook: AzureCredentialSchema,
411+
logger: Logger,
412+
cloud: Cloud = AZURE_PUBLIC_CLOUD,
413+
) -> None:
414+
super().__init__(runbook, logger=logger, cloud=cloud)
415+
416+
def get_credential(self) -> Any:
417+
"""
418+
return AzureCliCredential for authentication
419+
"""
420+
self._log.info("Authenticating using AzureCliCredential")
421+
422+
# Determine additionally_allowed_tenants based on allow_all_tenants setting
423+
additionally_allowed_tenants = ["*"] if self._allow_all_tenants else None
424+
425+
# Create AzureCliCredential with proper parameter types
426+
return AzureCliCredential(
427+
tenant_id=self._tenant_id,
428+
additionally_allowed_tenants=additionally_allowed_tenants,
429+
)

0 commit comments

Comments
 (0)