Skip to content

Commit ec4abba

Browse files
authored
[Identity] Add support for Bridge to Kubernetes to ManagedIdentityCredential (Azure#15856)
* [Identity] Add support for Bridge to Kubernetes to ManagedIdentityCredential * one very simple test * forgot this line
1 parent 8919e6a commit ec4abba

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

sdk/identity/identity/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- `AuthenticationRequiredError` (introduced in 2.0.0-beta.1) now has the same impact on `ChainedTokenCredential` as the `CredentialUnavailableError` which is to allow the next credential in the chain to be tried.
3838
- `ManagedIdentityCredential` now retries with exponential back-off when a request for a token fails with a 404 status code on environments with available IMDS endpoints.
3939
- Added an `AzurePowerShellCredential` which will use the authenticated user session from the `Az.Account` PowerShell module. This credential will attempt to use PowerShell Core by calling `pwsh`, and on Windows it will fall back to Windows PowerShell (`powershell`) if PowerShell Core is not available.
40+
- Added support to `ManagedIdentityCredential` for Bridge to Kubernetes local development authentication.
4041

4142
### Breaking changes from 2.0.0-beta.1
4243

sdk/identity/identity/src/credentials/managedIdentityCredential/imdsMsi.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function prepareRequestOptions(resource?: string, clientId?: string): RequestPre
4444
}
4545

4646
return {
47-
url: imdsEndpoint,
47+
url: process.env.AZURE_POD_IDENTITY_TOKEN_URL ?? imdsEndpoint,
4848
method: "GET",
4949
queryParameters,
5050
headers: {
@@ -73,6 +73,11 @@ export const imdsMsi: MSI = {
7373
getTokenOptions
7474
);
7575

76+
// if the PodIdenityEndpoint environment variable was set no need to probe the endpoint, it can be assumed to exist
77+
if (process.env.AZURE_POD_IDENTITY_TOKEN_URL) {
78+
return true;
79+
}
80+
7681
const request = prepareRequestOptions(resource, clientId);
7782

7883
// This will always be populated, but let's make TypeScript happy

sdk/identity/identity/test/internal/node/managedIdentityCredential.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import {
1515
import { MockAuthHttpClient, MockAuthHttpClientOptions, assertRejects } from "../../authTestUtils";
1616
import { OAuthErrorResponse } from "../../../src/client/errors";
1717
import Sinon from "sinon";
18-
import { imdsMsiRetryConfig } from "../../../src/credentials/managedIdentityCredential/imdsMsi";
18+
import {
19+
imdsMsi,
20+
imdsMsiRetryConfig
21+
} from "../../../src/credentials/managedIdentityCredential/imdsMsi";
1922
import { mkdtempSync, rmdirSync, unlinkSync, writeFileSync } from "fs";
2023
import { join } from "path";
2124
import { tmpdir } from "os";
@@ -37,6 +40,7 @@ describe("ManagedIdentityCredential", function() {
3740
delete process.env.MSI_SECRET;
3841
delete process.env.IDENTITY_SERVER_THUMBPRINT;
3942
delete process.env.IMDS_ENDPOINT;
43+
delete process.env.AZURE_POD_IDENTITY_TOKEN_URL;
4044
sandbox = Sinon.createSandbox();
4145
});
4246
afterEach(() => {
@@ -47,6 +51,7 @@ describe("ManagedIdentityCredential", function() {
4751
process.env.MSI_SECRET = env.MSI_SECRET;
4852
process.env.IDENTITY_SERVER_THUMBPRINT = env.IDENTITY_SERVER_THUMBPRINT;
4953
process.env.IMDS_ENDPOINT = env.IMDS_ENDPOINT;
54+
process.env.AZURE_POD_IDENTITY_TOKEN_URL = env.AZURE_POD_IDENTITY_TOKEN_URL;
5055
sandbox.restore();
5156
});
5257

@@ -244,6 +249,12 @@ describe("ManagedIdentityCredential", function() {
244249
clock.restore();
245250
});
246251

252+
it("IMDS MSI skips verification if the AZURE_POD_IDENTITY_TOKEN_URL environment variable is available", async function() {
253+
process.env.AZURE_POD_IDENTITY_TOKEN_URL = "token URL";
254+
255+
assert.ok(await imdsMsi.isAvailable());
256+
});
257+
247258
// Unavailable exception throws while IMDS endpoint is unavailable. This test not valid.
248259
// it("can extend timeout for IMDS endpoint", async function() {
249260
// // Mock a timeout so that the endpoint ping fails

0 commit comments

Comments
 (0)