Skip to content

Commit 78ea133

Browse files
committed
Az cli v 2.74 support
1 parent 78499a9 commit 78ea133

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

Program.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@
4747
return Results.Ok(result);
4848
});
4949

50+
// az cli v2.74+: Can be consumed by "az login --identity" by specifying AZURE_POD_IDENTITY_AUTHORITY_HOST environment variable to this action URL
51+
// https://github.com/AzureAD/microsoft-authentication-library-for-python/blob/d49296c1b2a929a6ab11380e237daa89a5298512/msal/managed_identity.py#L473
52+
app.MapGet("/metadata/identity/oauth2/token", async (HttpContext context, string resource, CancellationToken cancellationToken) =>
53+
{
54+
var token = await tokenCredential.GetTokenAsync(new TokenRequestContext([resource]), cancellationToken);
55+
var result = new JsonObject()
56+
{
57+
["access_token"] = token.Token,
58+
["expires_in"] = (token.ExpiresOn - DateTimeOffset.UtcNow).TotalSeconds,
59+
["token_type"] = "Bearer",
60+
["resource"] = resource,
61+
};
62+
return Results.Ok(result);
63+
});
64+
5065
app.Run();
5166

5267
[JsonSourceGenerationOptions]

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ Then, we must add two environment variables to each service:
7070
With these two environment variables, any service that uses `DefaultAzureCredential` or `ManagedIdentityCredential` will now call the proxy when Azure credentials are needed. This is because one of `ManagedIdentityCredential`'s [source implementations](https://github.com/Azure/azure-sdk-for-net/blob/Azure.Identity_1.6.0/sdk/identity/Azure.Identity/src/AzureArcManagedIdentitySource.cs) explicitly looks for both of these environment variables if they are specified.
7171

7272
> [!NOTE]
73-
> If you are using using `az cli` in your service and your service wants to do `az login --identity` then specify `MSI_ENDPOINT`: the URL of the proxy endpoint (e.g., `http://azclicredsproxy:8080/token`) environment variable instead. `IDENTITY_ENDPOINT` and `IMDS_ENDPOINT` are not required for `az login --identity`.
73+
> If you are using `az cli` in your service and your service wants to do `az login --identity` then specify `MSI_ENDPOINT`: the URL of the proxy endpoint (e.g., `http://azclicredsproxy:8080/token`) environment variable instead. `IDENTITY_ENDPOINT` and `IMDS_ENDPOINT` are not required for `az login --identity`.
74+
> For `az cli` v2.74 and above:
75+
> Specify `AZURE_POD_IDENTITY_AUTHORITY_HOST`: the URL of the proxy endpoint (e.g., `http://azclicredsproxy:8080` with no trailing path like `/token`) environment variable instead.
7476

7577
With this proxy, Dockerfiles can remain untouched and production-ready. The proxy can easily be added to an existing `docker-compose.yml`, and the environment variables are also easy to add. Now, the containerized environment looks like this:
7678

0 commit comments

Comments
 (0)