Skip to content

Commit 9f46190

Browse files
authored
[Identity] Cleanups after end-to-end testing and meetings (Azure#12347)
* [Identity] Cleanups after end-to-end testing and meetings * test fixes
1 parent b8a7759 commit 9f46190

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ const logger = credentialLogger("ManagedIdentityCredential - ArcMSI");
1515
// Azure Arc MSI doesn't have a special expiresIn parser.
1616
const expiresInParser = undefined;
1717

18-
function prepareRequestOptions(resource?: string, clientId?: string): RequestPrepareOptions {
18+
function prepareRequestOptions(resource?: string): RequestPrepareOptions {
1919
const queryParameters: any = {
2020
resource,
2121
"api-version": azureArcAPIVersion
2222
};
2323

24-
if (clientId) {
25-
queryParameters.client_id = clientId;
26-
}
27-
2824
return {
2925
// Should be similar to: http://localhost:40342/metadata/identity/oauth2/token
3026
url: process.env.IDENTITY_ENDPOINT,
@@ -84,12 +80,18 @@ export const arcMsi: MSI = {
8480
): Promise<AccessToken | null> {
8581
logger.info(`Using the Azure Arc MSI to authenticate.`);
8682

83+
if (clientId) {
84+
throw new Error(
85+
"User assigned identity is not supported by the Azure Arc Managed Identity Endpoint. To authenticate with the system assigned identity omit the client id when constructing the ManagedIdentityCredential, or if authenticating with the DefaultAzureCredential ensure the AZURE_CLIENT_ID environment variable is not set."
86+
);
87+
}
88+
8789
const requestOptions = {
8890
disableJsonStringifyOnBody: true,
8991
deserializationMapper: undefined,
9092
abortSignal: getTokenOptions.abortSignal,
9193
spanOptions: getTokenOptions.tracingOptions && getTokenOptions.tracingOptions.spanOptions,
92-
...prepareRequestOptions(resource, clientId)
94+
...prepareRequestOptions(resource)
9395
};
9496

9597
const filePath = await filePathRequest(identityClient, requestOptions);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export const DefaultScopeSuffix = "/.default";
55

66
export const imdsEndpoint = "http://169.254.169.254/metadata/identity/oauth2/token";
77
export const imdsApiVersion = "2018-02-01";
8-
export const azureArcAPIVersion = "2019-08-15";
8+
export const azureArcAPIVersion = "2019-11-01";
9+
export const azureFabricVersion = "2019-07-01-preview";

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { MSI } from "./models";
66
import { credentialLogger } from "../../util/logging";
77
import { IdentityClient } from "../../client/identityClient";
88
import { msiGenericGetToken } from "./utils";
9+
import { azureFabricVersion } from "./constants";
910

1011
const logger = credentialLogger("ManagedIdentityCredential - Fabric MSI");
1112

@@ -17,7 +18,7 @@ function expiresInParser(requestBody: any): number {
1718
function prepareRequestOptions(resource: string, clientId?: string): RequestPrepareOptions {
1819
const queryParameters: any = {
1920
resource,
20-
"api-version": "2019-07-01-preview"
21+
"api-version": azureFabricVersion
2122
};
2223

2324
if (clientId) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { imdsMsi } from "./imdsMsi";
1717
import { MSI } from "./models";
1818
import { appServiceMsi2017 } from "./appServiceMsi2017";
1919
import { arcMsi } from "./arcMsi";
20-
import { fabricMsi } from "./fabricMsi";
2120

2221
const logger = credentialLogger("ManagedIdentityCredential");
2322

@@ -78,7 +77,9 @@ export class ManagedIdentityCredential implements TokenCredential {
7877
return this.cachedMSI;
7978
}
8079

81-
const MSIs = [fabricMsi, appServiceMsi2017, cloudShellMsi, arcMsi, imdsMsi];
80+
// "fabricMsi" can't be added yet because our HTTPs pipeline doesn't allow skipping the SSL verification step,
81+
// which is necessary since Service Fabric only provides self-signed certificates on their Identity Endpoint.
82+
const MSIs = [appServiceMsi2017, cloudShellMsi, arcMsi, imdsMsi];
8283

8384
for (const msi of MSIs) {
8485
if (await msi.isAvailable(this.identityClient, resource, clientId, getTokenOptions)) {

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface AuthRequestDetails {
1717
token: AccessToken | null;
1818
}
1919

20-
describe("ManagedIdentityCredential", function() {
20+
describe("ManagedIdentityCredential", function () {
2121
afterEach(() => {
2222
delete process.env.IDENTITY_ENDPOINT;
2323
delete process.env.IDENTITY_HEADER;
@@ -26,7 +26,7 @@ describe("ManagedIdentityCredential", function() {
2626
delete process.env.IDENTITY_SERVER_THUMBPRINT;
2727
});
2828

29-
it("sends an authorization request with a modified resource name", async function() {
29+
it("sends an authorization request with a modified resource name", async function () {
3030
const authDetails = await getMsiTokenAuthRequest(["https://service/.default"], "client", {
3131
authResponse: [
3232
{ status: 200 }, // Respond to IMDS isAvailable
@@ -83,7 +83,7 @@ describe("ManagedIdentityCredential", function() {
8383
}
8484
});
8585

86-
it("returns error when ManagedIdentityCredential authentication failed", async function() {
86+
it("returns error when ManagedIdentityCredential authentication failed", async function () {
8787
process.env.AZURE_CLIENT_ID = "errclient";
8888

8989
const errResponse: OAuthErrorResponse = {
@@ -211,7 +211,7 @@ describe("ManagedIdentityCredential", function() {
211211
[`${filePath}`]: key
212212
});
213213

214-
const authDetails = await getMsiTokenAuthRequest(["https://service/.default"], "client", {
214+
const authDetails = await getMsiTokenAuthRequest(["https://service/.default"], undefined, {
215215
authResponse: [
216216
{
217217
status: 401,
@@ -234,7 +234,6 @@ describe("ManagedIdentityCredential", function() {
234234
assert.ok(validationRequest.query, "No query string parameters on request");
235235

236236
assert.equal(validationRequest.method, "GET");
237-
assert.equal(validationRequest.query!["client_id"], "client");
238237
assert.equal(decodeURIComponent(validationRequest.query!["resource"]), "https://service");
239238

240239
assert.ok(
@@ -247,7 +246,6 @@ describe("ManagedIdentityCredential", function() {
247246
assert.ok(authRequest.query, "No query string parameters on request");
248247

249248
assert.equal(authRequest.method, "GET");
250-
assert.equal(authRequest.query!["client_id"], "client");
251249
assert.equal(decodeURIComponent(authRequest.query!["resource"]), "https://service");
252250

253251
assert.ok(
@@ -259,15 +257,18 @@ describe("ManagedIdentityCredential", function() {
259257
if (authDetails.token) {
260258
// We use Date.now underneath.
261259
assert.equal(
262-
Math.floor(authDetails.token.expiresOnTimestamp / 100000),
263-
Math.floor(Date.now() / 100000)
260+
Math.floor(authDetails.token.expiresOnTimestamp / 1000000),
261+
Math.floor(Date.now() / 1000000)
264262
);
265263
} else {
266264
assert.fail("No token was returned!");
267265
}
268266
});
269267

270-
it("sends an authorization request correctly in an Azure Fabric environment", async () => {
268+
// "fabricMsi" isn't part of the ManagedIdentityCredential MSIs yet
269+
// because our HTTPs pipeline doesn't allow skipping the SSL verification step,
270+
// which is necessary since Service Fabric only provides self-signed certificates on their Identity Endpoint.
271+
it.skip("sends an authorization request correctly in an Azure Fabric environment", async () => {
271272
// Trigger App Service behavior by setting environment variables
272273
process.env.IDENTITY_ENDPOINT = "https://endpoint";
273274
process.env.IDENTITY_HEADER = "secret";

0 commit comments

Comments
 (0)