@azure/identity 4.5.1-alpha.20241031.1 → 4.5.1-alpha.20241111.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +67 -121
- package/dist/index.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js +12 -34
- package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/index.browser.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/index.js +188 -8
- package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/models.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/tokenExchangeMsi.js +4 -1
- package/dist-esm/src/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/utils.js +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/utils.js.map +1 -1
- package/package.json +3 -4
- package/types/identity.d.ts +11 -1
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js +0 -71
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js.map +0 -1
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2019.js +0 -71
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2019.js.map +0 -1
- package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js +0 -140
- package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js.map +0 -1
- package/dist-esm/src/credentials/managedIdentityCredential/cloudShellMsi.js +0 -75
- package/dist-esm/src/credentials/managedIdentityCredential/cloudShellMsi.js.map +0 -1
- package/dist-esm/src/credentials/managedIdentityCredential/constants.js +0 -9
- package/dist-esm/src/credentials/managedIdentityCredential/constants.js.map +0 -1
- package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.js +0 -95
- package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.js.map +0 -1
- package/dist-esm/src/credentials/managedIdentityCredential/legacyMsiProvider.js +0 -309
- package/dist-esm/src/credentials/managedIdentityCredential/legacyMsiProvider.js.map +0 -1
- package/dist-esm/src/credentials/managedIdentityCredential/msalMsiProvider.js +0 -212
- package/dist-esm/src/credentials/managedIdentityCredential/msalMsiProvider.js.map +0 -1
package/dist/index.js
CHANGED
@@ -10,8 +10,8 @@ var coreTracing = require('@azure/core-tracing');
|
|
10
10
|
var fs = require('fs');
|
11
11
|
var os = require('os');
|
12
12
|
var path = require('path');
|
13
|
-
var abortController = require('@azure/abort-controller');
|
14
13
|
var msalCommon = require('@azure/msal-node');
|
14
|
+
var abortController = require('@azure/abort-controller');
|
15
15
|
var open = require('open');
|
16
16
|
var promises = require('fs/promises');
|
17
17
|
var child_process = require('child_process');
|
@@ -499,12 +499,6 @@ const tracingClient = coreTracing.createTracingClient({
|
|
499
499
|
// Copyright (c) Microsoft Corporation.
|
500
500
|
// Licensed under the MIT License.
|
501
501
|
const DefaultScopeSuffix = "/.default";
|
502
|
-
const imdsHost = "http://169.254.169.254";
|
503
|
-
const imdsEndpointPath = "/metadata/identity/oauth2/token";
|
504
|
-
const imdsApiVersion = "2018-02-01";
|
505
|
-
|
506
|
-
// Copyright (c) Microsoft Corporation.
|
507
|
-
// Licensed under the MIT License.
|
508
502
|
/**
|
509
503
|
* Most MSIs send requests to the IMDS endpoint, or a similar endpoint.
|
510
504
|
* These are GET requests that require sending a `resource` parameter on the query.
|
@@ -1256,10 +1250,44 @@ function deserializeAuthenticationRecord(serializedRecord) {
|
|
1256
1250
|
return parsed;
|
1257
1251
|
}
|
1258
1252
|
|
1253
|
+
// Copyright (c) Microsoft Corporation.
|
1254
|
+
// Licensed under the MIT License.
|
1255
|
+
// Matches the default retry configuration in expontentialRetryStrategy.ts
|
1256
|
+
const DEFAULT_CLIENT_MAX_RETRY_INTERVAL = 1000 * 64;
|
1257
|
+
/**
|
1258
|
+
* An additional policy that retries on 404 errors. The default retry policy does not retry on
|
1259
|
+
* 404s, but the IMDS endpoint can return 404s when the token is not yet available. This policy
|
1260
|
+
* will retry on 404s with an exponential backoff.
|
1261
|
+
*
|
1262
|
+
* @param msiRetryConfig - The retry configuration for the MSI credential.
|
1263
|
+
* @returns - The policy that will retry on 404s.
|
1264
|
+
*/
|
1265
|
+
function imdsRetryPolicy(msiRetryConfig) {
|
1266
|
+
return coreRestPipeline.retryPolicy([
|
1267
|
+
{
|
1268
|
+
name: "imdsRetryPolicy",
|
1269
|
+
retry: ({ retryCount, response }) => {
|
1270
|
+
if ((response === null || response === void 0 ? void 0 : response.status) !== 404) {
|
1271
|
+
return { skipStrategy: true };
|
1272
|
+
}
|
1273
|
+
return coreUtil.calculateRetryDelay(retryCount, {
|
1274
|
+
retryDelayInMs: msiRetryConfig.startDelayInMs,
|
1275
|
+
maxRetryDelayInMs: DEFAULT_CLIENT_MAX_RETRY_INTERVAL,
|
1276
|
+
});
|
1277
|
+
},
|
1278
|
+
},
|
1279
|
+
], {
|
1280
|
+
maxRetries: msiRetryConfig.maxRetries,
|
1281
|
+
});
|
1282
|
+
}
|
1283
|
+
|
1259
1284
|
// Copyright (c) Microsoft Corporation.
|
1260
1285
|
// Licensed under the MIT License.
|
1261
1286
|
const msiName$1 = "ManagedIdentityCredential - IMDS";
|
1262
1287
|
const logger$i = credentialLogger(msiName$1);
|
1288
|
+
const imdsHost = "http://169.254.169.254";
|
1289
|
+
const imdsEndpointPath = "/metadata/identity/oauth2/token";
|
1290
|
+
const imdsApiVersion = "2018-02-01";
|
1263
1291
|
/**
|
1264
1292
|
* Generates the options used on the request for an access token.
|
1265
1293
|
*/
|
@@ -1304,11 +1332,14 @@ function prepareRequestOptions(scopes, clientId, resourceId, options) {
|
|
1304
1332
|
};
|
1305
1333
|
}
|
1306
1334
|
/**
|
1307
|
-
* Defines how to determine whether the Azure IMDS MSI is available
|
1335
|
+
* Defines how to determine whether the Azure IMDS MSI is available.
|
1336
|
+
*
|
1337
|
+
* Actually getting the token once we determine IMDS is available is handled by MSAL.
|
1308
1338
|
*/
|
1309
1339
|
const imdsMsi = {
|
1310
1340
|
name: "imdsMsi",
|
1311
|
-
async isAvailable(
|
1341
|
+
async isAvailable(options) {
|
1342
|
+
const { scopes, identityClient, clientId, resourceId, getTokenOptions } = options;
|
1312
1343
|
const resource = mapScopesToResource(scopes);
|
1313
1344
|
if (!resource) {
|
1314
1345
|
logger$i.info(`${msiName$1}: Unavailable. Multiple scopes are not supported.`);
|
@@ -1325,16 +1356,16 @@ const imdsMsi = {
|
|
1325
1356
|
skipMetadataHeader: true,
|
1326
1357
|
skipQuery: true,
|
1327
1358
|
});
|
1328
|
-
return tracingClient.withSpan("ManagedIdentityCredential-pingImdsEndpoint", getTokenOptions, async (
|
1359
|
+
return tracingClient.withSpan("ManagedIdentityCredential-pingImdsEndpoint", getTokenOptions !== null && getTokenOptions !== void 0 ? getTokenOptions : {}, async (updatedOptions) => {
|
1329
1360
|
var _a, _b;
|
1330
|
-
requestOptions.tracingOptions =
|
1361
|
+
requestOptions.tracingOptions = updatedOptions.tracingOptions;
|
1331
1362
|
// Create a request with a timeout since we expect that
|
1332
1363
|
// not having a "Metadata" header should cause an error to be
|
1333
1364
|
// returned quickly from the endpoint, proving its availability.
|
1334
1365
|
const request = coreRestPipeline.createPipelineRequest(requestOptions);
|
1335
1366
|
// Default to 1000 if the default of 0 is used.
|
1336
1367
|
// Negative values can still be used to disable the timeout.
|
1337
|
-
request.timeout = ((_a =
|
1368
|
+
request.timeout = ((_a = updatedOptions.requestOptions) === null || _a === void 0 ? void 0 : _a.timeout) || 1000;
|
1338
1369
|
// This MSI uses the imdsEndpoint to get the token, which only uses http://
|
1339
1370
|
request.allowInsecureConnection = true;
|
1340
1371
|
let response;
|
@@ -1365,65 +1396,8 @@ const imdsMsi = {
|
|
1365
1396
|
return true;
|
1366
1397
|
});
|
1367
1398
|
},
|
1368
|
-
async getToken(configuration, getTokenOptions = {}) {
|
1369
|
-
const { identityClient, scopes, clientId, resourceId } = configuration;
|
1370
|
-
if (process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST) {
|
1371
|
-
logger$i.info(`${msiName$1}: Using the Azure IMDS endpoint coming from the environment variable AZURE_POD_IDENTITY_AUTHORITY_HOST=${process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST}.`);
|
1372
|
-
}
|
1373
|
-
else {
|
1374
|
-
logger$i.info(`${msiName$1}: Using the default Azure IMDS endpoint ${imdsHost}.`);
|
1375
|
-
}
|
1376
|
-
let nextDelayInMs = configuration.retryConfig.startDelayInMs;
|
1377
|
-
for (let retries = 0; retries < configuration.retryConfig.maxRetries; retries++) {
|
1378
|
-
try {
|
1379
|
-
const request = coreRestPipeline.createPipelineRequest(Object.assign(Object.assign({ abortSignal: getTokenOptions.abortSignal }, prepareRequestOptions(scopes, clientId, resourceId)), { allowInsecureConnection: true }));
|
1380
|
-
const tokenResponse = await identityClient.sendTokenRequest(request);
|
1381
|
-
return (tokenResponse && tokenResponse.accessToken) || null;
|
1382
|
-
}
|
1383
|
-
catch (error) {
|
1384
|
-
if (error.statusCode === 404) {
|
1385
|
-
await coreUtil.delay(nextDelayInMs);
|
1386
|
-
nextDelayInMs *= configuration.retryConfig.intervalIncrement;
|
1387
|
-
continue;
|
1388
|
-
}
|
1389
|
-
throw error;
|
1390
|
-
}
|
1391
|
-
}
|
1392
|
-
throw new AuthenticationError(404, `${msiName$1}: Failed to retrieve IMDS token after ${configuration.retryConfig.maxRetries} retries.`);
|
1393
|
-
},
|
1394
1399
|
};
|
1395
1400
|
|
1396
|
-
// Copyright (c) Microsoft Corporation.
|
1397
|
-
// Licensed under the MIT License.
|
1398
|
-
// Matches the default retry configuration in expontentialRetryStrategy.ts
|
1399
|
-
const DEFAULT_CLIENT_MAX_RETRY_INTERVAL = 1000 * 64;
|
1400
|
-
/**
|
1401
|
-
* An additional policy that retries on 404 errors. The default retry policy does not retry on
|
1402
|
-
* 404s, but the IMDS endpoint can return 404s when the token is not yet available. This policy
|
1403
|
-
* will retry on 404s with an exponential backoff.
|
1404
|
-
*
|
1405
|
-
* @param msiRetryConfig - The retry configuration for the MSI credential.
|
1406
|
-
* @returns - The policy that will retry on 404s.
|
1407
|
-
*/
|
1408
|
-
function imdsRetryPolicy(msiRetryConfig) {
|
1409
|
-
return coreRestPipeline.retryPolicy([
|
1410
|
-
{
|
1411
|
-
name: "imdsRetryPolicy",
|
1412
|
-
retry: ({ retryCount, response }) => {
|
1413
|
-
if ((response === null || response === void 0 ? void 0 : response.status) !== 404) {
|
1414
|
-
return { skipStrategy: true };
|
1415
|
-
}
|
1416
|
-
return coreUtil.calculateRetryDelay(retryCount, {
|
1417
|
-
retryDelayInMs: msiRetryConfig.startDelayInMs,
|
1418
|
-
maxRetryDelayInMs: DEFAULT_CLIENT_MAX_RETRY_INTERVAL,
|
1419
|
-
});
|
1420
|
-
},
|
1421
|
-
},
|
1422
|
-
], {
|
1423
|
-
maxRetries: msiRetryConfig.maxRetries,
|
1424
|
-
});
|
1425
|
-
}
|
1426
|
-
|
1427
1401
|
// Copyright (c) Microsoft Corporation.
|
1428
1402
|
// Licensed under the MIT License.
|
1429
1403
|
/**
|
@@ -2203,10 +2177,13 @@ const msiName = "ManagedIdentityCredential - Token Exchange";
|
|
2203
2177
|
const logger$f = credentialLogger(msiName);
|
2204
2178
|
/**
|
2205
2179
|
* Defines how to determine whether the token exchange MSI is available, and also how to retrieve a token from the token exchange MSI.
|
2180
|
+
*
|
2181
|
+
* Token exchange MSI (used by AKS) is the only MSI implementation handled entirely by Azure Identity.
|
2182
|
+
* The rest have been migrated to MSAL.
|
2206
2183
|
*/
|
2207
2184
|
const tokenExchangeMsi = {
|
2208
2185
|
name: "tokenExchangeMsi",
|
2209
|
-
async isAvailable(
|
2186
|
+
async isAvailable(clientId) {
|
2210
2187
|
const env = process.env;
|
2211
2188
|
const result = Boolean((clientId || env.AZURE_CLIENT_ID) &&
|
2212
2189
|
env.AZURE_TENANT_ID &&
|
@@ -2226,19 +2203,31 @@ const tokenExchangeMsi = {
|
|
2226
2203
|
|
2227
2204
|
// Copyright (c) Microsoft Corporation.
|
2228
2205
|
// Licensed under the MIT License.
|
2229
|
-
const logger$e = credentialLogger("ManagedIdentityCredential
|
2230
|
-
|
2231
|
-
|
2206
|
+
const logger$e = credentialLogger("ManagedIdentityCredential");
|
2207
|
+
/**
|
2208
|
+
* Attempts authentication using a managed identity available at the deployment environment.
|
2209
|
+
* This authentication type works in Azure VMs, App Service instances, Azure Functions applications,
|
2210
|
+
* Azure Kubernetes Services, Azure Service Fabric instances and inside of the Azure Cloud Shell.
|
2211
|
+
*
|
2212
|
+
* More information about configuring managed identities can be found here:
|
2213
|
+
* https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview
|
2214
|
+
*/
|
2215
|
+
class ManagedIdentityCredential {
|
2216
|
+
/**
|
2217
|
+
* @internal
|
2218
|
+
* @hidden
|
2219
|
+
*/
|
2220
|
+
constructor(clientIdOrOptions, options) {
|
2232
2221
|
var _a, _b;
|
2233
2222
|
this.msiRetryConfig = {
|
2234
2223
|
maxRetries: 5,
|
2235
2224
|
startDelayInMs: 800,
|
2236
2225
|
intervalIncrement: 2,
|
2237
2226
|
};
|
2238
|
-
let _options
|
2227
|
+
let _options;
|
2239
2228
|
if (typeof clientIdOrOptions === "string") {
|
2240
2229
|
this.clientId = clientIdOrOptions;
|
2241
|
-
_options = options;
|
2230
|
+
_options = options !== null && options !== void 0 ? options : {};
|
2242
2231
|
}
|
2243
2232
|
else {
|
2244
2233
|
this.clientId = clientIdOrOptions === null || clientIdOrOptions === void 0 ? void 0 : clientIdOrOptions.clientId;
|
@@ -2253,7 +2242,7 @@ class MsalMsiProvider {
|
|
2253
2242
|
}
|
2254
2243
|
// ManagedIdentity uses http for local requests
|
2255
2244
|
_options.allowInsecureConnection = true;
|
2256
|
-
if (((_a = _options
|
2245
|
+
if (((_a = _options.retryOptions) === null || _a === void 0 ? void 0 : _a.maxRetries) !== undefined) {
|
2257
2246
|
this.msiRetryConfig.maxRetries = _options.retryOptions.maxRetries;
|
2258
2247
|
}
|
2259
2248
|
this.identityClient = new IdentityClient(Object.assign(Object.assign({}, _options), { additionalPolicies: [{ policy: imdsRetryPolicy(this.msiRetryConfig), position: "perCall" }] }));
|
@@ -2264,12 +2253,11 @@ class MsalMsiProvider {
|
|
2264
2253
|
userAssignedObjectId: this.objectId,
|
2265
2254
|
},
|
2266
2255
|
system: {
|
2267
|
-
// todo: proxyUrl?
|
2268
2256
|
disableInternalRetries: true,
|
2269
2257
|
networkClient: this.identityClient,
|
2270
2258
|
loggerOptions: {
|
2271
2259
|
logLevel: getMSALLogLevel(logger$m.getLogLevel()),
|
2272
|
-
piiLoggingEnabled: (_b =
|
2260
|
+
piiLoggingEnabled: (_b = _options.loggingOptions) === null || _b === void 0 ? void 0 : _b.enableUnsafeSupportLogging,
|
2273
2261
|
loggerCallback: defaultLoggerCallback(logger$e),
|
2274
2262
|
},
|
2275
2263
|
},
|
@@ -2307,13 +2295,7 @@ class MsalMsiProvider {
|
|
2307
2295
|
return tracingClient.withSpan("ManagedIdentityCredential.getToken", options, async () => {
|
2308
2296
|
var _a;
|
2309
2297
|
try {
|
2310
|
-
const isTokenExchangeMsi = await tokenExchangeMsi.isAvailable(
|
2311
|
-
scopes,
|
2312
|
-
clientId: this.clientId,
|
2313
|
-
getTokenOptions: options,
|
2314
|
-
identityClient: this.identityClient,
|
2315
|
-
resourceId: this.resourceId,
|
2316
|
-
});
|
2298
|
+
const isTokenExchangeMsi = await tokenExchangeMsi.isAvailable(this.clientId);
|
2317
2299
|
// Most scenarios are handled by MSAL except for two:
|
2318
2300
|
// AKS pod identity - MSAL does not implement the token exchange flow.
|
2319
2301
|
// IMDS Endpoint probing - MSAL does not do any probing before trying to get a token.
|
@@ -2425,42 +2407,6 @@ function isNetworkError(err) {
|
|
2425
2407
|
return false;
|
2426
2408
|
}
|
2427
2409
|
|
2428
|
-
// Copyright (c) Microsoft Corporation.
|
2429
|
-
// Licensed under the MIT License.
|
2430
|
-
/**
|
2431
|
-
* Attempts authentication using a managed identity available at the deployment environment.
|
2432
|
-
* This authentication type works in Azure VMs, App Service instances, Azure Functions applications,
|
2433
|
-
* Azure Kubernetes Services, Azure Service Fabric instances and inside of the Azure Cloud Shell.
|
2434
|
-
*
|
2435
|
-
* More information about configuring managed identities can be found here:
|
2436
|
-
* https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview
|
2437
|
-
*/
|
2438
|
-
class ManagedIdentityCredential {
|
2439
|
-
/**
|
2440
|
-
* @internal
|
2441
|
-
* @hidden
|
2442
|
-
*/
|
2443
|
-
constructor(clientIdOrOptions, options) {
|
2444
|
-
// https://github.com/Azure/azure-sdk-for-js/issues/30189
|
2445
|
-
// If needed, you may release a hotfix to quickly rollback to the legacy implementation by changing the following line to:
|
2446
|
-
// this.implProvider = new LegacyMsiProvider(clientIdOrOptions, options);
|
2447
|
-
// Once stabilized, you can remove the legacy implementation and inline the msalMsiProvider code here as a drop-in replacement.
|
2448
|
-
this.implProvider = new MsalMsiProvider(clientIdOrOptions, options);
|
2449
|
-
}
|
2450
|
-
/**
|
2451
|
-
* Authenticates with Microsoft Entra ID and returns an access token if successful.
|
2452
|
-
* If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
|
2453
|
-
* If an unexpected error occurs, an {@link AuthenticationError} will be thrown with the details of the failure.
|
2454
|
-
*
|
2455
|
-
* @param scopes - The list of scopes for which the token will have access.
|
2456
|
-
* @param options - The options used to configure any requests this
|
2457
|
-
* TokenCredential implementation might make.
|
2458
|
-
*/
|
2459
|
-
async getToken(scopes, options) {
|
2460
|
-
return this.implProvider.getToken(scopes, options);
|
2461
|
-
}
|
2462
|
-
}
|
2463
|
-
|
2464
2410
|
// Copyright (c) Microsoft Corporation.
|
2465
2411
|
// Licensed under the MIT License.
|
2466
2412
|
/**
|