@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.
Files changed (30) hide show
  1. package/dist/index.js +67 -121
  2. package/dist/index.js.map +1 -1
  3. package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js +12 -34
  4. package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
  5. package/dist-esm/src/credentials/managedIdentityCredential/index.browser.js.map +1 -1
  6. package/dist-esm/src/credentials/managedIdentityCredential/index.js +188 -8
  7. package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
  8. package/dist-esm/src/credentials/managedIdentityCredential/models.js.map +1 -1
  9. package/dist-esm/src/credentials/managedIdentityCredential/tokenExchangeMsi.js +4 -1
  10. package/dist-esm/src/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
  11. package/dist-esm/src/credentials/managedIdentityCredential/utils.js +1 -1
  12. package/dist-esm/src/credentials/managedIdentityCredential/utils.js.map +1 -1
  13. package/package.json +3 -4
  14. package/types/identity.d.ts +11 -1
  15. package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js +0 -71
  16. package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js.map +0 -1
  17. package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2019.js +0 -71
  18. package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2019.js.map +0 -1
  19. package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js +0 -140
  20. package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js.map +0 -1
  21. package/dist-esm/src/credentials/managedIdentityCredential/cloudShellMsi.js +0 -75
  22. package/dist-esm/src/credentials/managedIdentityCredential/cloudShellMsi.js.map +0 -1
  23. package/dist-esm/src/credentials/managedIdentityCredential/constants.js +0 -9
  24. package/dist-esm/src/credentials/managedIdentityCredential/constants.js.map +0 -1
  25. package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.js +0 -95
  26. package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.js.map +0 -1
  27. package/dist-esm/src/credentials/managedIdentityCredential/legacyMsiProvider.js +0 -309
  28. package/dist-esm/src/credentials/managedIdentityCredential/legacyMsiProvider.js.map +0 -1
  29. package/dist-esm/src/credentials/managedIdentityCredential/msalMsiProvider.js +0 -212
  30. package/dist-esm/src/credentials/managedIdentityCredential/msalMsiProvider.js.map +0 -1
@@ -1,71 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { createHttpHeaders, createPipelineRequest } from "@azure/core-rest-pipeline";
4
- import { credentialLogger } from "../../util/logging";
5
- import { mapScopesToResource } from "./utils";
6
- const msiName = "ManagedIdentityCredential - AppServiceMSI 2017";
7
- const logger = credentialLogger(msiName);
8
- /**
9
- * Generates the options used on the request for an access token.
10
- */
11
- function prepareRequestOptions(scopes, clientId) {
12
- const resource = mapScopesToResource(scopes);
13
- if (!resource) {
14
- throw new Error(`${msiName}: Multiple scopes are not supported.`);
15
- }
16
- const queryParameters = {
17
- resource,
18
- "api-version": "2017-09-01",
19
- };
20
- if (clientId) {
21
- queryParameters.clientid = clientId;
22
- }
23
- const query = new URLSearchParams(queryParameters);
24
- // This error should not bubble up, since we verify that this environment variable is defined in the isAvailable() method defined below.
25
- if (!process.env.MSI_ENDPOINT) {
26
- throw new Error(`${msiName}: Missing environment variable: MSI_ENDPOINT`);
27
- }
28
- if (!process.env.MSI_SECRET) {
29
- throw new Error(`${msiName}: Missing environment variable: MSI_SECRET`);
30
- }
31
- return {
32
- url: `${process.env.MSI_ENDPOINT}?${query.toString()}`,
33
- method: "GET",
34
- headers: createHttpHeaders({
35
- Accept: "application/json",
36
- secret: process.env.MSI_SECRET,
37
- }),
38
- };
39
- }
40
- /**
41
- * Defines how to determine whether the Azure App Service MSI is available, and also how to retrieve a token from the Azure App Service MSI.
42
- */
43
- export const appServiceMsi2017 = {
44
- name: "appServiceMsi2017",
45
- async isAvailable({ scopes }) {
46
- const resource = mapScopesToResource(scopes);
47
- if (!resource) {
48
- logger.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);
49
- return false;
50
- }
51
- const env = process.env;
52
- const result = Boolean(env.MSI_ENDPOINT && env.MSI_SECRET);
53
- if (!result) {
54
- logger.info(`${msiName}: Unavailable. The environment variables needed are: MSI_ENDPOINT and MSI_SECRET.`);
55
- }
56
- return result;
57
- },
58
- async getToken(configuration, getTokenOptions = {}) {
59
- const { identityClient, scopes, clientId, resourceId } = configuration;
60
- if (resourceId) {
61
- logger.warning(`${msiName}: managed Identity by resource Id is not supported. Argument resourceId might be ignored by the service.`);
62
- }
63
- logger.info(`${msiName}: Using the endpoint and the secret coming form the environment variables: MSI_ENDPOINT=${process.env.MSI_ENDPOINT} and MSI_SECRET=[REDACTED].`);
64
- const request = createPipelineRequest(Object.assign(Object.assign({ abortSignal: getTokenOptions.abortSignal }, prepareRequestOptions(scopes, clientId)), {
65
- // Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
66
- allowInsecureConnection: true }));
67
- const tokenResponse = await identityClient.sendTokenRequest(request);
68
- return (tokenResponse && tokenResponse.accessToken) || null;
69
- },
70
- };
71
- //# sourceMappingURL=appServiceMsi2017.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"appServiceMsi2017.js","sourceRoot":"","sources":["../../../../src/credentials/managedIdentityCredential/appServiceMsi2017.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAErF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,OAAO,GAAG,gDAAgD,CAAC;AACjE,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAEzC;;GAEG;AACH,SAAS,qBAAqB,CAC5B,MAAyB,EACzB,QAAiB;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YAC3E,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QACxB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;QAC3D,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,CAAC,IAAI,CACT,GAAG,OAAO,mFAAmF,CAC9F,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,KAAK,CAAC,QAAQ,CACZ,aAA+B,EAC/B,kBAAmC,EAAE;QAErC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC;QAEvE,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,CAAC,OAAO,CACZ,GAAG,OAAO,0GAA0G,CACrH,CAAC;QACJ,CAAC;QAED,MAAM,CAAC,IAAI,CACT,GAAG,OAAO,2FAA2F,OAAO,CAAC,GAAG,CAAC,YAAY,6BAA6B,CAC3J,CAAC;QAEF,MAAM,OAAO,GAAG,qBAAqB,+BACnC,WAAW,EAAE,eAAe,CAAC,WAAW,IACrC,qBAAqB,CAAC,MAAM,EAAE,QAAQ,CAAC;YAC1C,0FAA0F;YAC1F,uBAAuB,EAAE,IAAI,IAC7B,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,cAAc,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACrE,OAAO,CAAC,aAAa,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC;IAC9D,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelineRequestOptions } from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders, createPipelineRequest } from \"@azure/core-rest-pipeline\";\nimport type { GetTokenOptions } from \"@azure/core-auth\";\nimport { credentialLogger } from \"../../util/logging\";\nimport type { MSI, MSIConfiguration, MSIToken } from \"./models\";\nimport { mapScopesToResource } from \"./utils\";\n\nconst msiName = \"ManagedIdentityCredential - AppServiceMSI 2017\";\nconst logger = credentialLogger(msiName);\n\n/**\n * Generates the options used on the request for an access token.\n */\nfunction prepareRequestOptions(\n scopes: string | string[],\n clientId?: string,\n): PipelineRequestOptions {\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n throw new Error(`${msiName}: Multiple scopes are not supported.`);\n }\n\n const queryParameters: Record<string, string> = {\n resource,\n \"api-version\": \"2017-09-01\",\n };\n\n if (clientId) {\n queryParameters.clientid = clientId;\n }\n\n const query = new URLSearchParams(queryParameters);\n\n // This error should not bubble up, since we verify that this environment variable is defined in the isAvailable() method defined below.\n if (!process.env.MSI_ENDPOINT) {\n throw new Error(`${msiName}: Missing environment variable: MSI_ENDPOINT`);\n }\n if (!process.env.MSI_SECRET) {\n throw new Error(`${msiName}: Missing environment variable: MSI_SECRET`);\n }\n\n return {\n url: `${process.env.MSI_ENDPOINT}?${query.toString()}`,\n method: \"GET\",\n headers: createHttpHeaders({\n Accept: \"application/json\",\n secret: process.env.MSI_SECRET,\n }),\n };\n}\n\n/**\n * Defines how to determine whether the Azure App Service MSI is available, and also how to retrieve a token from the Azure App Service MSI.\n */\nexport const appServiceMsi2017: MSI = {\n name: \"appServiceMsi2017\",\n async isAvailable({ scopes }): Promise<boolean> {\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n logger.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);\n return false;\n }\n const env = process.env;\n const result = Boolean(env.MSI_ENDPOINT && env.MSI_SECRET);\n if (!result) {\n logger.info(\n `${msiName}: Unavailable. The environment variables needed are: MSI_ENDPOINT and MSI_SECRET.`,\n );\n }\n return result;\n },\n async getToken(\n configuration: MSIConfiguration,\n getTokenOptions: GetTokenOptions = {},\n ): Promise<MSIToken | null> {\n const { identityClient, scopes, clientId, resourceId } = configuration;\n\n if (resourceId) {\n logger.warning(\n `${msiName}: managed Identity by resource Id is not supported. Argument resourceId might be ignored by the service.`,\n );\n }\n\n logger.info(\n `${msiName}: Using the endpoint and the secret coming form the environment variables: MSI_ENDPOINT=${process.env.MSI_ENDPOINT} and MSI_SECRET=[REDACTED].`,\n );\n\n const request = createPipelineRequest({\n abortSignal: getTokenOptions.abortSignal,\n ...prepareRequestOptions(scopes, clientId),\n // Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).\n allowInsecureConnection: true,\n });\n const tokenResponse = await identityClient.sendTokenRequest(request);\n return (tokenResponse && tokenResponse.accessToken) || null;\n },\n};\n"]}
@@ -1,71 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { createHttpHeaders, createPipelineRequest } from "@azure/core-rest-pipeline";
4
- import { credentialLogger } from "../../util/logging";
5
- import { mapScopesToResource } from "./utils";
6
- const msiName = "ManagedIdentityCredential - AppServiceMSI 2019";
7
- const logger = credentialLogger(msiName);
8
- /**
9
- * Generates the options used on the request for an access token.
10
- */
11
- function prepareRequestOptions(scopes, clientId, resourceId) {
12
- const resource = mapScopesToResource(scopes);
13
- if (!resource) {
14
- throw new Error(`${msiName}: Multiple scopes are not supported.`);
15
- }
16
- const queryParameters = {
17
- resource,
18
- "api-version": "2019-08-01",
19
- };
20
- if (clientId) {
21
- queryParameters.client_id = clientId;
22
- }
23
- if (resourceId) {
24
- queryParameters.mi_res_id = resourceId;
25
- }
26
- const query = new URLSearchParams(queryParameters);
27
- // This error should not bubble up, since we verify that this environment variable is defined in the isAvailable() method defined below.
28
- if (!process.env.IDENTITY_ENDPOINT) {
29
- throw new Error(`${msiName}: Missing environment variable: IDENTITY_ENDPOINT`);
30
- }
31
- if (!process.env.IDENTITY_HEADER) {
32
- throw new Error(`${msiName}: Missing environment variable: IDENTITY_HEADER`);
33
- }
34
- return {
35
- url: `${process.env.IDENTITY_ENDPOINT}?${query.toString()}`,
36
- method: "GET",
37
- headers: createHttpHeaders({
38
- Accept: "application/json",
39
- "X-IDENTITY-HEADER": process.env.IDENTITY_HEADER,
40
- }),
41
- };
42
- }
43
- /**
44
- * Defines how to determine whether the Azure App Service MSI is available, and also how to retrieve a token from the Azure App Service MSI.
45
- */
46
- export const appServiceMsi2019 = {
47
- name: "appServiceMsi2019",
48
- async isAvailable({ scopes }) {
49
- const resource = mapScopesToResource(scopes);
50
- if (!resource) {
51
- logger.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);
52
- return false;
53
- }
54
- const env = process.env;
55
- const result = Boolean(env.IDENTITY_ENDPOINT && env.IDENTITY_HEADER);
56
- if (!result) {
57
- logger.info(`${msiName}: Unavailable. The environment variables needed are: IDENTITY_ENDPOINT and IDENTITY_HEADER.`);
58
- }
59
- return result;
60
- },
61
- async getToken(configuration, getTokenOptions = {}) {
62
- const { identityClient, scopes, clientId, resourceId } = configuration;
63
- logger.info(`${msiName}: Using the endpoint and the secret coming form the environment variables: IDENTITY_ENDPOINT=${process.env.IDENTITY_ENDPOINT} and IDENTITY_HEADER=[REDACTED].`);
64
- const request = createPipelineRequest(Object.assign(Object.assign({ abortSignal: getTokenOptions.abortSignal }, prepareRequestOptions(scopes, clientId, resourceId)), {
65
- // Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
66
- allowInsecureConnection: true }));
67
- const tokenResponse = await identityClient.sendTokenRequest(request);
68
- return (tokenResponse && tokenResponse.accessToken) || null;
69
- },
70
- };
71
- //# sourceMappingURL=appServiceMsi2019.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"appServiceMsi2019.js","sourceRoot":"","sources":["../../../../src/credentials/managedIdentityCredential/appServiceMsi2019.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAErF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,OAAO,GAAG,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C,IAAI,EAAE,mBAAmB;IACzB,KAAK,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE;QAC1B,MAAM,QAAQ,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;QAC7C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,mDAAmD,CAAC,CAAC;YAC3E,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QACxB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC;QACrE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,CAAC,IAAI,CACT,GAAG,OAAO,6FAA6F,CACxG,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,KAAK,CAAC,QAAQ,CACZ,aAA+B,EAC/B,kBAAmC,EAAE;QAErC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC;QAEvE,MAAM,CAAC,IAAI,CACT,GAAG,OAAO,gGAAgG,OAAO,CAAC,GAAG,CAAC,iBAAiB,kCAAkC,CAC1K,CAAC;QAEF,MAAM,OAAO,GAAG,qBAAqB,+BACnC,WAAW,EAAE,eAAe,CAAC,WAAW,IACrC,qBAAqB,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC;YACtD,0FAA0F;YAC1F,uBAAuB,EAAE,IAAI,IAC7B,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,cAAc,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACrE,OAAO,CAAC,aAAa,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC;IAC9D,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelineRequestOptions } from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders, createPipelineRequest } from \"@azure/core-rest-pipeline\";\nimport type { GetTokenOptions } from \"@azure/core-auth\";\nimport { credentialLogger } from \"../../util/logging\";\nimport type { MSI, MSIConfiguration, MSIToken } from \"./models\";\nimport { mapScopesToResource } from \"./utils\";\n\nconst msiName = \"ManagedIdentityCredential - AppServiceMSI 2019\";\nconst logger = credentialLogger(msiName);\n\n/**\n * Generates the options used on the request for an access token.\n */\nfunction prepareRequestOptions(\n scopes: string | string[],\n clientId?: string,\n resourceId?: string,\n): PipelineRequestOptions {\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n throw new Error(`${msiName}: Multiple scopes are not supported.`);\n }\n\n const queryParameters: Record<string, string> = {\n resource,\n \"api-version\": \"2019-08-01\",\n };\n\n if (clientId) {\n queryParameters.client_id = clientId;\n }\n\n if (resourceId) {\n queryParameters.mi_res_id = resourceId;\n }\n const query = new URLSearchParams(queryParameters);\n\n // This error should not bubble up, since we verify that this environment variable is defined in the isAvailable() method defined below.\n if (!process.env.IDENTITY_ENDPOINT) {\n throw new Error(`${msiName}: Missing environment variable: IDENTITY_ENDPOINT`);\n }\n if (!process.env.IDENTITY_HEADER) {\n throw new Error(`${msiName}: Missing environment variable: IDENTITY_HEADER`);\n }\n\n return {\n url: `${process.env.IDENTITY_ENDPOINT}?${query.toString()}`,\n method: \"GET\",\n headers: createHttpHeaders({\n Accept: \"application/json\",\n \"X-IDENTITY-HEADER\": process.env.IDENTITY_HEADER,\n }),\n };\n}\n\n/**\n * Defines how to determine whether the Azure App Service MSI is available, and also how to retrieve a token from the Azure App Service MSI.\n */\nexport const appServiceMsi2019: MSI = {\n name: \"appServiceMsi2019\",\n async isAvailable({ scopes }): Promise<boolean> {\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n logger.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);\n return false;\n }\n const env = process.env;\n const result = Boolean(env.IDENTITY_ENDPOINT && env.IDENTITY_HEADER);\n if (!result) {\n logger.info(\n `${msiName}: Unavailable. The environment variables needed are: IDENTITY_ENDPOINT and IDENTITY_HEADER.`,\n );\n }\n return result;\n },\n async getToken(\n configuration: MSIConfiguration,\n getTokenOptions: GetTokenOptions = {},\n ): Promise<MSIToken | null> {\n const { identityClient, scopes, clientId, resourceId } = configuration;\n\n logger.info(\n `${msiName}: Using the endpoint and the secret coming form the environment variables: IDENTITY_ENDPOINT=${process.env.IDENTITY_ENDPOINT} and IDENTITY_HEADER=[REDACTED].`,\n );\n\n const request = createPipelineRequest({\n abortSignal: getTokenOptions.abortSignal,\n ...prepareRequestOptions(scopes, clientId, resourceId),\n // Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).\n allowInsecureConnection: true,\n });\n const tokenResponse = await identityClient.sendTokenRequest(request);\n return (tokenResponse && tokenResponse.accessToken) || null;\n },\n};\n"]}
@@ -1,140 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { createHttpHeaders, createPipelineRequest } from "@azure/core-rest-pipeline";
4
- import { AuthenticationError } from "../../errors";
5
- import { azureArcAPIVersion } from "./constants";
6
- import { credentialLogger } from "../../util/logging";
7
- import fs from "node:fs";
8
- import { mapScopesToResource } from "./utils";
9
- const msiName = "ManagedIdentityCredential - Azure Arc MSI";
10
- const logger = credentialLogger(msiName);
11
- /**
12
- * Generates the options used on the request for an access token.
13
- */
14
- function prepareRequestOptions(scopes, clientId, resourceId) {
15
- const resource = mapScopesToResource(scopes);
16
- if (!resource) {
17
- throw new Error(`${msiName}: Multiple scopes are not supported.`);
18
- }
19
- const queryParameters = {
20
- resource,
21
- "api-version": azureArcAPIVersion,
22
- };
23
- if (clientId) {
24
- queryParameters.client_id = clientId;
25
- }
26
- if (resourceId) {
27
- queryParameters.msi_res_id = resourceId;
28
- }
29
- // This error should not bubble up, since we verify that this environment variable is defined in the isAvailable() method defined below.
30
- if (!process.env.IDENTITY_ENDPOINT) {
31
- throw new Error(`${msiName}: Missing environment variable: IDENTITY_ENDPOINT`);
32
- }
33
- const query = new URLSearchParams(queryParameters);
34
- return createPipelineRequest({
35
- // Should be similar to: http://localhost:40342/metadata/identity/oauth2/token
36
- url: `${process.env.IDENTITY_ENDPOINT}?${query.toString()}`,
37
- method: "GET",
38
- headers: createHttpHeaders({
39
- Accept: "application/json",
40
- Metadata: "true",
41
- }),
42
- });
43
- }
44
- /**
45
- * Does a request to the authentication provider that results in a file path.
46
- */
47
- async function filePathRequest(identityClient, requestPrepareOptions) {
48
- const response = await identityClient.sendRequest(createPipelineRequest(requestPrepareOptions));
49
- if (response.status !== 401) {
50
- let message = "";
51
- if (response.bodyAsText) {
52
- message = ` Response: ${response.bodyAsText}`;
53
- }
54
- throw new AuthenticationError(response.status, `${msiName}: To authenticate with Azure Arc MSI, status code 401 is expected on the first request. ${message}`);
55
- }
56
- const authHeader = response.headers.get("www-authenticate") || "";
57
- try {
58
- return authHeader.split("=").slice(1)[0];
59
- }
60
- catch (e) {
61
- throw Error(`Invalid www-authenticate header format: ${authHeader}`);
62
- }
63
- }
64
- export function platformToFilePath() {
65
- switch (process.platform) {
66
- case "win32":
67
- if (!process.env.PROGRAMDATA) {
68
- throw new Error(`${msiName}: PROGRAMDATA environment variable has no value.`);
69
- }
70
- return `${process.env.PROGRAMDATA}\\AzureConnectedMachineAgent\\Tokens`;
71
- case "linux":
72
- return "/var/opt/azcmagent/tokens";
73
- default:
74
- throw new Error(`${msiName}: Unsupported platform ${process.platform}.`);
75
- }
76
- }
77
- /**
78
- * Validates that a given Azure Arc MSI file path is valid for use.
79
- *
80
- * A valid file will:
81
- * 1. Be in the expected path for the current platform.
82
- * 2. Have a `.key` extension.
83
- * 3. Be at most 4096 bytes in size.
84
- */
85
- export function validateKeyFile(filePath) {
86
- if (!filePath) {
87
- throw new Error(`${msiName}: Failed to find the token file.`);
88
- }
89
- if (!filePath.endsWith(".key")) {
90
- throw new Error(`${msiName}: unexpected file path from HIMDS service: ${filePath}.`);
91
- }
92
- const expectedPath = platformToFilePath();
93
- if (!filePath.startsWith(expectedPath)) {
94
- throw new Error(`${msiName}: unexpected file path from HIMDS service: ${filePath}.`);
95
- }
96
- const stats = fs.statSync(filePath);
97
- if (stats.size > 4096) {
98
- throw new Error(`${msiName}: The file at ${filePath} is larger than expected at ${stats.size} bytes.`);
99
- }
100
- }
101
- /**
102
- * Defines how to determine whether the Azure Arc MSI is available, and also how to retrieve a token from the Azure Arc MSI.
103
- */
104
- export const arcMsi = {
105
- name: "arc",
106
- async isAvailable({ scopes }) {
107
- const resource = mapScopesToResource(scopes);
108
- if (!resource) {
109
- logger.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);
110
- return false;
111
- }
112
- const result = Boolean(process.env.IMDS_ENDPOINT && process.env.IDENTITY_ENDPOINT);
113
- if (!result) {
114
- logger.info(`${msiName}: The environment variables needed are: IMDS_ENDPOINT and IDENTITY_ENDPOINT`);
115
- }
116
- return result;
117
- },
118
- async getToken(configuration, getTokenOptions = {}) {
119
- var _a;
120
- const { identityClient, scopes, clientId, resourceId } = configuration;
121
- if (clientId) {
122
- logger.warning(`${msiName}: user-assigned identities not supported. The argument clientId might be ignored by the service.`);
123
- }
124
- if (resourceId) {
125
- logger.warning(`${msiName}: user defined managed Identity by resource Id is not supported. Argument resourceId will be ignored.`);
126
- }
127
- logger.info(`${msiName}: Authenticating.`);
128
- const requestOptions = Object.assign(Object.assign({ disableJsonStringifyOnBody: true, deserializationMapper: undefined, abortSignal: getTokenOptions.abortSignal }, prepareRequestOptions(scopes, clientId, resourceId)), { allowInsecureConnection: true });
129
- const filePath = await filePathRequest(identityClient, requestOptions);
130
- validateKeyFile(filePath);
131
- const key = await fs.promises.readFile(filePath, { encoding: "utf-8" });
132
- (_a = requestOptions.headers) === null || _a === void 0 ? void 0 : _a.set("Authorization", `Basic ${key}`);
133
- const request = createPipelineRequest(Object.assign(Object.assign({}, requestOptions), {
134
- // Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
135
- allowInsecureConnection: true }));
136
- const tokenResponse = await identityClient.sendTokenRequest(request);
137
- return (tokenResponse && tokenResponse.accessToken) || null;
138
- },
139
- };
140
- //# sourceMappingURL=arcMsi.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"arcMsi.js","sourceRoot":"","sources":["../../../../src/credentials/managedIdentityCredential/arcMsi.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAErF,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,OAAO,GAAG,2CAA2C,CAAC;AAC5D,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAEzC;;GAEG;AACH,SAAS,qBAAqB,CAC5B,MAAyB,EACzB,QAAiB,EACjB,UAAmB;IAEnB,MAAM,QAAQ,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,sCAAsC,CAAC,CAAC;IACpE,CAAC;IACD,MAAM,eAAe,GAA2B;QAC9C,QAAQ;QACR,aAAa,EAAE,kBAAkB;KAClC,CAAC;IAEF,IAAI,QAAQ,EAAE,CAAC;QACb,eAAe,CAAC,SAAS,GAAG,QAAQ,CAAC;IACvC,CAAC;IACD,IAAI,UAAU,EAAE,CAAC;QACf,eAAe,CAAC,UAAU,GAAG,UAAU,CAAC;IAC1C,CAAC;IAED,wIAAwI;IACxI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC;QACnC,MAAM,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,CAAC,CAAC;QACvE,eAAe,CAAC,QAAQ,CAAC,CAAC;QAE1B,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QACxE,MAAA,cAAc,CAAC,OAAO,0CAAE,GAAG,CAAC,eAAe,EAAE,SAAS,GAAG,EAAE,CAAC,CAAC;QAE7D,MAAM,OAAO,GAAG,qBAAqB,iCAChC,cAAc;YACjB,0FAA0F;YAC1F,uBAAuB,EAAE,IAAI,IAC7B,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,cAAc,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACrE,OAAO,CAAC,aAAa,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC;IAC9D,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { MSI, MSIConfiguration, MSIToken } from \"./models\";\nimport type { PipelineRequestOptions } from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders, createPipelineRequest } from \"@azure/core-rest-pipeline\";\n\nimport { AuthenticationError } from \"../../errors\";\nimport type { GetTokenOptions } from \"@azure/core-auth\";\nimport type { IdentityClient } from \"../../client/identityClient\";\nimport { azureArcAPIVersion } from \"./constants\";\nimport { credentialLogger } from \"../../util/logging\";\nimport fs from \"node:fs\";\nimport { mapScopesToResource } from \"./utils\";\n\nconst msiName = \"ManagedIdentityCredential - Azure Arc MSI\";\nconst logger = credentialLogger(msiName);\n\n/**\n * Generates the options used on the request for an access token.\n */\nfunction prepareRequestOptions(\n scopes: string | string[],\n clientId?: string,\n resourceId?: string,\n): PipelineRequestOptions {\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n throw new Error(`${msiName}: Multiple scopes are not supported.`);\n }\n const queryParameters: Record<string, string> = {\n resource,\n \"api-version\": azureArcAPIVersion,\n };\n\n if (clientId) {\n queryParameters.client_id = clientId;\n }\n if (resourceId) {\n queryParameters.msi_res_id = resourceId;\n }\n\n // This error should not bubble up, since we verify that this environment variable is defined in the isAvailable() method defined below.\n if (!process.env.IDENTITY_ENDPOINT) {\n throw new Error(`${msiName}: Missing environment variable: IDENTITY_ENDPOINT`);\n }\n\n const query = new URLSearchParams(queryParameters);\n\n return createPipelineRequest({\n // Should be similar to: http://localhost:40342/metadata/identity/oauth2/token\n url: `${process.env.IDENTITY_ENDPOINT}?${query.toString()}`,\n method: \"GET\",\n headers: createHttpHeaders({\n Accept: \"application/json\",\n Metadata: \"true\",\n }),\n });\n}\n\n/**\n * Does a request to the authentication provider that results in a file path.\n */\nasync function filePathRequest(\n identityClient: IdentityClient,\n requestPrepareOptions: PipelineRequestOptions,\n): Promise<string | undefined> {\n const response = await identityClient.sendRequest(createPipelineRequest(requestPrepareOptions));\n\n if (response.status !== 401) {\n let message = \"\";\n if (response.bodyAsText) {\n message = ` Response: ${response.bodyAsText}`;\n }\n throw new AuthenticationError(\n response.status,\n `${msiName}: To authenticate with Azure Arc MSI, status code 401 is expected on the first request. ${message}`,\n );\n }\n\n const authHeader = response.headers.get(\"www-authenticate\") || \"\";\n try {\n return authHeader.split(\"=\").slice(1)[0];\n } catch (e: any) {\n throw Error(`Invalid www-authenticate header format: ${authHeader}`);\n }\n}\n\nexport function platformToFilePath(): string {\n switch (process.platform) {\n case \"win32\":\n if (!process.env.PROGRAMDATA) {\n throw new Error(`${msiName}: PROGRAMDATA environment variable has no value.`);\n }\n return `${process.env.PROGRAMDATA}\\\\AzureConnectedMachineAgent\\\\Tokens`;\n case \"linux\":\n return \"/var/opt/azcmagent/tokens\";\n default:\n throw new Error(`${msiName}: Unsupported platform ${process.platform}.`);\n }\n}\n\n/**\n * Validates that a given Azure Arc MSI file path is valid for use.\n *\n * A valid file will:\n * 1. Be in the expected path for the current platform.\n * 2. Have a `.key` extension.\n * 3. Be at most 4096 bytes in size.\n */\nexport function validateKeyFile(filePath?: string): asserts filePath is string {\n if (!filePath) {\n throw new Error(`${msiName}: Failed to find the token file.`);\n }\n\n if (!filePath.endsWith(\".key\")) {\n throw new Error(`${msiName}: unexpected file path from HIMDS service: ${filePath}.`);\n }\n\n const expectedPath = platformToFilePath();\n if (!filePath.startsWith(expectedPath)) {\n throw new Error(`${msiName}: unexpected file path from HIMDS service: ${filePath}.`);\n }\n\n const stats = fs.statSync(filePath);\n if (stats.size > 4096) {\n throw new Error(\n `${msiName}: The file at ${filePath} is larger than expected at ${stats.size} bytes.`,\n );\n }\n}\n\n/**\n * Defines how to determine whether the Azure Arc MSI is available, and also how to retrieve a token from the Azure Arc MSI.\n */\nexport const arcMsi: MSI = {\n name: \"arc\",\n async isAvailable({ scopes }): Promise<boolean> {\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n logger.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);\n return false;\n }\n const result = Boolean(process.env.IMDS_ENDPOINT && process.env.IDENTITY_ENDPOINT);\n if (!result) {\n logger.info(\n `${msiName}: The environment variables needed are: IMDS_ENDPOINT and IDENTITY_ENDPOINT`,\n );\n }\n return result;\n },\n async getToken(\n configuration: MSIConfiguration,\n getTokenOptions: GetTokenOptions = {},\n ): Promise<MSIToken | null> {\n const { identityClient, scopes, clientId, resourceId } = configuration;\n\n if (clientId) {\n logger.warning(\n `${msiName}: user-assigned identities not supported. The argument clientId might be ignored by the service.`,\n );\n }\n if (resourceId) {\n logger.warning(\n `${msiName}: user defined managed Identity by resource Id is not supported. Argument resourceId will be ignored.`,\n );\n }\n\n logger.info(`${msiName}: Authenticating.`);\n\n const requestOptions = {\n disableJsonStringifyOnBody: true,\n deserializationMapper: undefined,\n abortSignal: getTokenOptions.abortSignal,\n ...prepareRequestOptions(scopes, clientId, resourceId),\n allowInsecureConnection: true,\n };\n\n const filePath = await filePathRequest(identityClient, requestOptions);\n validateKeyFile(filePath);\n\n const key = await fs.promises.readFile(filePath, { encoding: \"utf-8\" });\n requestOptions.headers?.set(\"Authorization\", `Basic ${key}`);\n\n const request = createPipelineRequest({\n ...requestOptions,\n // Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).\n allowInsecureConnection: true,\n });\n const tokenResponse = await identityClient.sendTokenRequest(request);\n return (tokenResponse && tokenResponse.accessToken) || null;\n },\n};\n"]}
@@ -1,75 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { createHttpHeaders, createPipelineRequest } from "@azure/core-rest-pipeline";
4
- import { credentialLogger } from "../../util/logging";
5
- import { mapScopesToResource } from "./utils";
6
- const msiName = "ManagedIdentityCredential - CloudShellMSI";
7
- export const logger = credentialLogger(msiName);
8
- /**
9
- * Generates the options used on the request for an access token.
10
- */
11
- function prepareRequestOptions(scopes, clientId, resourceId) {
12
- const resource = mapScopesToResource(scopes);
13
- if (!resource) {
14
- throw new Error(`${msiName}: Multiple scopes are not supported.`);
15
- }
16
- const body = {
17
- resource,
18
- };
19
- if (clientId) {
20
- body.client_id = clientId;
21
- }
22
- if (resourceId) {
23
- body.msi_res_id = resourceId;
24
- }
25
- // This error should not bubble up, since we verify that this environment variable is defined in the isAvailable() method defined below.
26
- if (!process.env.MSI_ENDPOINT) {
27
- throw new Error(`${msiName}: Missing environment variable: MSI_ENDPOINT`);
28
- }
29
- const params = new URLSearchParams(body);
30
- return {
31
- url: process.env.MSI_ENDPOINT,
32
- method: "POST",
33
- body: params.toString(),
34
- headers: createHttpHeaders({
35
- Accept: "application/json",
36
- Metadata: "true",
37
- "Content-Type": "application/x-www-form-urlencoded",
38
- }),
39
- };
40
- }
41
- /**
42
- * Defines how to determine whether the Azure Cloud Shell MSI is available, and also how to retrieve a token from the Azure Cloud Shell MSI.
43
- * Since Azure Managed Identities aren't available in the Azure Cloud Shell, we log a warning for users that try to access cloud shell using user assigned identity.
44
- */
45
- export const cloudShellMsi = {
46
- name: "cloudShellMsi",
47
- async isAvailable({ scopes }) {
48
- const resource = mapScopesToResource(scopes);
49
- if (!resource) {
50
- logger.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);
51
- return false;
52
- }
53
- const result = Boolean(process.env.MSI_ENDPOINT);
54
- if (!result) {
55
- logger.info(`${msiName}: Unavailable. The environment variable MSI_ENDPOINT is needed.`);
56
- }
57
- return result;
58
- },
59
- async getToken(configuration, getTokenOptions = {}) {
60
- const { identityClient, scopes, clientId, resourceId } = configuration;
61
- if (clientId) {
62
- logger.warning(`${msiName}: user-assigned identities not supported. The argument clientId might be ignored by the service.`);
63
- }
64
- if (resourceId) {
65
- logger.warning(`${msiName}: user defined managed Identity by resource Id not supported. The argument resourceId might be ignored by the service.`);
66
- }
67
- logger.info(`${msiName}: Using the endpoint coming form the environment variable MSI_ENDPOINT = ${process.env.MSI_ENDPOINT}.`);
68
- const request = createPipelineRequest(Object.assign(Object.assign({ abortSignal: getTokenOptions.abortSignal }, prepareRequestOptions(scopes, clientId, resourceId)), {
69
- // Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
70
- allowInsecureConnection: true }));
71
- const tokenResponse = await identityClient.sendTokenRequest(request);
72
- return (tokenResponse && tokenResponse.accessToken) || null;
73
- },
74
- };
75
- //# sourceMappingURL=cloudShellMsi.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cloudShellMsi.js","sourceRoot":"","sources":["../../../../src/credentials/managedIdentityCredential/cloudShellMsi.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,OAAO,GAAG,2CAA2C,CAAC;AAC5D,MAAM,CAAC,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAEhD;;GAEG;AACH,SAAS,qBAAqB,CAC5B,MAAyB,EACzB,QAAiB,EACjB,UAAmB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AC,GAAG,CAAC,YAAY,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,iEAAiE,CAAC,CAAC;QAC3F,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,KAAK,CAAC,QAAQ,CACZ,aAA+B,EAC/B,kBAAmC,EAAE;QAErC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC;QAEvE,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,CAAC,OAAO,CACZ,GAAG,OAAO,kGAAkG,CAC7G,CAAC;QACJ,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,CAAC,OAAO,CACZ,GAAG,OAAO,wHAAwH,CACnI,CAAC;QACJ,CAAC;QAED,MAAM,CAAC,IAAI,CACT,GAAG,OAAO,4EAA4E,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,CAClH,CAAC;QAEF,MAAM,OAAO,GAAG,qBAAqB,+BACnC,WAAW,EAAE,eAAe,CAAC,WAAW,IACrC,qBAAqB,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC;YACtD,0FAA0F;YAC1F,uBAAuB,EAAE,IAAI,IAC7B,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,cAAc,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACrE,OAAO,CAAC,aAAa,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC;IAC9D,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelineRequestOptions } from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders, createPipelineRequest } from \"@azure/core-rest-pipeline\";\nimport { credentialLogger } from \"../../util/logging\";\nimport type { GetTokenOptions } from \"@azure/core-auth\";\nimport type { MSI, MSIConfiguration, MSIToken } from \"./models\";\nimport { mapScopesToResource } from \"./utils\";\n\nconst msiName = \"ManagedIdentityCredential - CloudShellMSI\";\nexport const logger = credentialLogger(msiName);\n\n/**\n * Generates the options used on the request for an access token.\n */\nfunction prepareRequestOptions(\n scopes: string | string[],\n clientId?: string,\n resourceId?: string,\n): PipelineRequestOptions {\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n throw new Error(`${msiName}: Multiple scopes are not supported.`);\n }\n\n const body: Record<string, string> = {\n resource,\n };\n\n if (clientId) {\n body.client_id = clientId;\n }\n if (resourceId) {\n body.msi_res_id = resourceId;\n }\n\n // This error should not bubble up, since we verify that this environment variable is defined in the isAvailable() method defined below.\n if (!process.env.MSI_ENDPOINT) {\n throw new Error(`${msiName}: Missing environment variable: MSI_ENDPOINT`);\n }\n const params = new URLSearchParams(body);\n return {\n url: process.env.MSI_ENDPOINT,\n method: \"POST\",\n body: params.toString(),\n headers: createHttpHeaders({\n Accept: \"application/json\",\n Metadata: \"true\",\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n }),\n };\n}\n\n/**\n * Defines how to determine whether the Azure Cloud Shell MSI is available, and also how to retrieve a token from the Azure Cloud Shell MSI.\n * Since Azure Managed Identities aren't available in the Azure Cloud Shell, we log a warning for users that try to access cloud shell using user assigned identity.\n */\nexport const cloudShellMsi: MSI = {\n name: \"cloudShellMsi\",\n async isAvailable({ scopes }): Promise<boolean> {\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n logger.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);\n return false;\n }\n\n const result = Boolean(process.env.MSI_ENDPOINT);\n if (!result) {\n logger.info(`${msiName}: Unavailable. The environment variable MSI_ENDPOINT is needed.`);\n }\n return result;\n },\n async getToken(\n configuration: MSIConfiguration,\n getTokenOptions: GetTokenOptions = {},\n ): Promise<MSIToken | null> {\n const { identityClient, scopes, clientId, resourceId } = configuration;\n\n if (clientId) {\n logger.warning(\n `${msiName}: user-assigned identities not supported. The argument clientId might be ignored by the service.`,\n );\n }\n\n if (resourceId) {\n logger.warning(\n `${msiName}: user defined managed Identity by resource Id not supported. The argument resourceId might be ignored by the service.`,\n );\n }\n\n logger.info(\n `${msiName}: Using the endpoint coming form the environment variable MSI_ENDPOINT = ${process.env.MSI_ENDPOINT}.`,\n );\n\n const request = createPipelineRequest({\n abortSignal: getTokenOptions.abortSignal,\n ...prepareRequestOptions(scopes, clientId, resourceId),\n // Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).\n allowInsecureConnection: true,\n });\n const tokenResponse = await identityClient.sendTokenRequest(request);\n return (tokenResponse && tokenResponse.accessToken) || null;\n },\n};\n"]}
@@ -1,9 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- export const DefaultScopeSuffix = "/.default";
4
- export const imdsHost = "http://169.254.169.254";
5
- export const imdsEndpointPath = "/metadata/identity/oauth2/token";
6
- export const imdsApiVersion = "2018-02-01";
7
- export const azureArcAPIVersion = "2019-11-01";
8
- export const azureFabricVersion = "2019-07-01-preview";
9
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/credentials/managedIdentityCredential/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAC9C,MAAM,CAAC,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AACjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,iCAAiC,CAAC;AAClE,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAC3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAC/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport const DefaultScopeSuffix = \"/.default\";\nexport const imdsHost = \"http://169.254.169.254\";\nexport const imdsEndpointPath = \"/metadata/identity/oauth2/token\";\nexport const imdsApiVersion = \"2018-02-01\";\nexport const azureArcAPIVersion = \"2019-11-01\";\nexport const azureFabricVersion = \"2019-07-01-preview\";\n"]}
@@ -1,95 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import https from "https";
4
- import { createHttpHeaders, createPipelineRequest } from "@azure/core-rest-pipeline";
5
- import { credentialLogger } from "../../util/logging";
6
- import { mapScopesToResource } from "./utils";
7
- import { azureFabricVersion } from "./constants";
8
- // This MSI can be easily tested by deploying a container to Azure Service Fabric with the Dockerfile:
9
- //
10
- // FROM node:12
11
- // RUN wget https://host.any/path/bash.sh
12
- // CMD ["bash", "bash.sh"]
13
- //
14
- // Where the bash script contains:
15
- //
16
- // curl --insecure $IDENTITY_ENDPOINT'?api-version=2019-07-01-preview&resource=https://vault.azure.net/' -H "Secret: $IDENTITY_HEADER"
17
- //
18
- const msiName = "ManagedIdentityCredential - Fabric MSI";
19
- const logger = credentialLogger(msiName);
20
- /**
21
- * Generates the options used on the request for an access token.
22
- */
23
- function prepareRequestOptions(scopes, clientId, resourceId) {
24
- const resource = mapScopesToResource(scopes);
25
- if (!resource) {
26
- throw new Error(`${msiName}: Multiple scopes are not supported.`);
27
- }
28
- const queryParameters = {
29
- resource,
30
- "api-version": azureFabricVersion,
31
- };
32
- if (clientId) {
33
- queryParameters.client_id = clientId;
34
- }
35
- if (resourceId) {
36
- queryParameters.msi_res_id = resourceId;
37
- }
38
- const query = new URLSearchParams(queryParameters);
39
- // This error should not bubble up, since we verify that this environment variable is defined in the isAvailable() method defined below.
40
- if (!process.env.IDENTITY_ENDPOINT) {
41
- throw new Error("Missing environment variable: IDENTITY_ENDPOINT");
42
- }
43
- if (!process.env.IDENTITY_HEADER) {
44
- throw new Error("Missing environment variable: IDENTITY_HEADER");
45
- }
46
- return {
47
- url: `${process.env.IDENTITY_ENDPOINT}?${query.toString()}`,
48
- method: "GET",
49
- headers: createHttpHeaders({
50
- Accept: "application/json",
51
- secret: process.env.IDENTITY_HEADER,
52
- }),
53
- };
54
- }
55
- /**
56
- * Defines how to determine whether the Azure Service Fabric MSI is available, and also how to retrieve a token from the Azure Service Fabric MSI.
57
- */
58
- export const fabricMsi = {
59
- name: "fabricMsi",
60
- async isAvailable({ scopes }) {
61
- const resource = mapScopesToResource(scopes);
62
- if (!resource) {
63
- logger.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);
64
- return false;
65
- }
66
- const env = process.env;
67
- const result = Boolean(env.IDENTITY_ENDPOINT && env.IDENTITY_HEADER && env.IDENTITY_SERVER_THUMBPRINT);
68
- if (!result) {
69
- logger.info(`${msiName}: Unavailable. The environment variables needed are: IDENTITY_ENDPOINT, IDENTITY_HEADER and IDENTITY_SERVER_THUMBPRINT`);
70
- }
71
- return result;
72
- },
73
- async getToken(configuration, getTokenOptions = {}) {
74
- const { scopes, identityClient, clientId, resourceId } = configuration;
75
- if (resourceId) {
76
- logger.warning(`${msiName}: user defined managed Identity by resource Id is not supported. Argument resourceId might be ignored by the service.`);
77
- }
78
- logger.info([
79
- `${msiName}:`,
80
- "Using the endpoint and the secret coming from the environment variables:",
81
- `IDENTITY_ENDPOINT=${process.env.IDENTITY_ENDPOINT},`,
82
- "IDENTITY_HEADER=[REDACTED] and",
83
- "IDENTITY_SERVER_THUMBPRINT=[REDACTED].",
84
- ].join(" "));
85
- const request = createPipelineRequest(Object.assign({ abortSignal: getTokenOptions.abortSignal }, prepareRequestOptions(scopes, clientId, resourceId)));
86
- request.agent = new https.Agent({
87
- // This is necessary because Service Fabric provides a self-signed certificate.
88
- // The alternative path is to verify the certificate using the IDENTITY_SERVER_THUMBPRINT env variable.
89
- rejectUnauthorized: false,
90
- });
91
- const tokenResponse = await identityClient.sendTokenRequest(request);
92
- return (tokenResponse && tokenResponse.accessToken) || null;
93
- },
94
- };
95
- //# sourceMappingURL=fabricMsi.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fabricMsi.js","sourceRoot":"","sources":["../../../../src/credentials/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,CACZ,GAAG,OAAO,uHAAuH,CAClI,CAAC;QACJ,CAAC;QAED,MAAM,CAAC,IAAI,CACT;YACE,GAAG,OAAO,GAAG;YACb,0EAA0E;YAC1E,qBAAqB,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG;YACrD,gCAAgC;YAChC,wCAAwC;SACzC,CAAC,IAAI,CAAC,GAAG,CAAC,CACZ,CAAC;QAEF,MAAM,OAAO,GAAG,qBAAqB,iBACnC,WAAW,EAAE,eAAe,CAAC,WAAW,IACrC,qBAAqB,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,EAGtD,CAAC;QAEH,OAAO,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC;YAC9B,+EAA+E;YAC/E,uGAAuG;YACvG,kBAAkB,EAAE,KAAK;SAC1B,CAAC,CAAC;QAEH,MAAM,aAAa,GAAG,MAAM,cAAc,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACrE,OAAO,CAAC,aAAa,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC;IAC9D,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport https from \"https\";\nimport type { PipelineRequestOptions } from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders, createPipelineRequest } from \"@azure/core-rest-pipeline\";\nimport type { GetTokenOptions } from \"@azure/core-auth\";\nimport { credentialLogger } from \"../../util/logging\";\nimport type { MSI, MSIConfiguration, MSIToken } from \"./models\";\nimport { mapScopesToResource } from \"./utils\";\nimport { azureFabricVersion } from \"./constants\";\n\n// This MSI can be easily tested by deploying a container to Azure Service Fabric with the Dockerfile:\n//\n// FROM node:12\n// RUN wget https://host.any/path/bash.sh\n// CMD [\"bash\", \"bash.sh\"]\n//\n// Where the bash script contains:\n//\n// curl --insecure $IDENTITY_ENDPOINT'?api-version=2019-07-01-preview&resource=https://vault.azure.net/' -H \"Secret: $IDENTITY_HEADER\"\n//\n\nconst msiName = \"ManagedIdentityCredential - Fabric MSI\";\nconst logger = credentialLogger(msiName);\n\n/**\n * Generates the options used on the request for an access token.\n */\nfunction prepareRequestOptions(\n scopes: string | string[],\n clientId?: string,\n resourceId?: string,\n): PipelineRequestOptions {\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n throw new Error(`${msiName}: Multiple scopes are not supported.`);\n }\n\n const queryParameters: Record<string, string> = {\n resource,\n \"api-version\": azureFabricVersion,\n };\n\n if (clientId) {\n queryParameters.client_id = clientId;\n }\n if (resourceId) {\n queryParameters.msi_res_id = resourceId;\n }\n const query = new URLSearchParams(queryParameters);\n\n // This error should not bubble up, since we verify that this environment variable is defined in the isAvailable() method defined below.\n if (!process.env.IDENTITY_ENDPOINT) {\n throw new Error(\"Missing environment variable: IDENTITY_ENDPOINT\");\n }\n if (!process.env.IDENTITY_HEADER) {\n throw new Error(\"Missing environment variable: IDENTITY_HEADER\");\n }\n\n return {\n url: `${process.env.IDENTITY_ENDPOINT}?${query.toString()}`,\n method: \"GET\",\n headers: createHttpHeaders({\n Accept: \"application/json\",\n secret: process.env.IDENTITY_HEADER,\n }),\n };\n}\n\n/**\n * Defines how to determine whether the Azure Service Fabric MSI is available, and also how to retrieve a token from the Azure Service Fabric MSI.\n */\nexport const fabricMsi: MSI = {\n name: \"fabricMsi\",\n async isAvailable({ scopes }): Promise<boolean> {\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n logger.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);\n return false;\n }\n const env = process.env;\n const result = Boolean(\n env.IDENTITY_ENDPOINT && env.IDENTITY_HEADER && env.IDENTITY_SERVER_THUMBPRINT,\n );\n if (!result) {\n logger.info(\n `${msiName}: Unavailable. The environment variables needed are: IDENTITY_ENDPOINT, IDENTITY_HEADER and IDENTITY_SERVER_THUMBPRINT`,\n );\n }\n return result;\n },\n async getToken(\n configuration: MSIConfiguration,\n getTokenOptions: GetTokenOptions = {},\n ): Promise<MSIToken | null> {\n const { scopes, identityClient, clientId, resourceId } = configuration;\n\n if (resourceId) {\n logger.warning(\n `${msiName}: user defined managed Identity by resource Id is not supported. Argument resourceId might be ignored by the service.`,\n );\n }\n\n logger.info(\n [\n `${msiName}:`,\n \"Using the endpoint and the secret coming from the environment variables:\",\n `IDENTITY_ENDPOINT=${process.env.IDENTITY_ENDPOINT},`,\n \"IDENTITY_HEADER=[REDACTED] and\",\n \"IDENTITY_SERVER_THUMBPRINT=[REDACTED].\",\n ].join(\" \"),\n );\n\n const request = createPipelineRequest({\n abortSignal: getTokenOptions.abortSignal,\n ...prepareRequestOptions(scopes, clientId, resourceId),\n // The service fabric MSI endpoint will be HTTPS (however, the certificate will be self-signed).\n // allowInsecureConnection: true\n });\n\n request.agent = new https.Agent({\n // This is necessary because Service Fabric provides a self-signed certificate.\n // The alternative path is to verify the certificate using the IDENTITY_SERVER_THUMBPRINT env variable.\n rejectUnauthorized: false,\n });\n\n const tokenResponse = await identityClient.sendTokenRequest(request);\n return (tokenResponse && tokenResponse.accessToken) || null;\n },\n};\n"]}