@azure/msal-node 2.9.1 → 2.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/dist/cache/NodeStorage.cjs +1 -1
  2. package/dist/cache/NodeStorage.mjs +1 -1
  3. package/dist/cache/TokenCache.cjs +1 -1
  4. package/dist/cache/TokenCache.mjs +1 -1
  5. package/dist/cache/distributed/DistributedCachePlugin.cjs +1 -1
  6. package/dist/cache/distributed/DistributedCachePlugin.mjs +1 -1
  7. package/dist/cache/serializer/Deserializer.cjs +1 -1
  8. package/dist/cache/serializer/Deserializer.mjs +1 -1
  9. package/dist/cache/serializer/Serializer.cjs +1 -1
  10. package/dist/cache/serializer/Serializer.mjs +1 -1
  11. package/dist/client/ClientApplication.cjs +1 -1
  12. package/dist/client/ClientApplication.mjs +1 -1
  13. package/dist/client/ClientAssertion.cjs +1 -1
  14. package/dist/client/ClientAssertion.mjs +1 -1
  15. package/dist/client/ClientCredentialClient.cjs +1 -1
  16. package/dist/client/ClientCredentialClient.mjs +1 -1
  17. package/dist/client/ConfidentialClientApplication.cjs +1 -1
  18. package/dist/client/ConfidentialClientApplication.mjs +1 -1
  19. package/dist/client/DeviceCodeClient.cjs +1 -1
  20. package/dist/client/DeviceCodeClient.mjs +1 -1
  21. package/dist/client/ManagedIdentityApplication.cjs +1 -1
  22. package/dist/client/ManagedIdentityApplication.mjs +1 -1
  23. package/dist/client/ManagedIdentityClient.cjs +1 -1
  24. package/dist/client/ManagedIdentityClient.mjs +1 -1
  25. package/dist/client/ManagedIdentitySources/AppService.cjs +1 -1
  26. package/dist/client/ManagedIdentitySources/AppService.mjs +1 -1
  27. package/dist/client/ManagedIdentitySources/AzureArc.cjs +41 -3
  28. package/dist/client/ManagedIdentitySources/AzureArc.cjs.map +1 -1
  29. package/dist/client/ManagedIdentitySources/AzureArc.d.ts +4 -0
  30. package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
  31. package/dist/client/ManagedIdentitySources/AzureArc.mjs +44 -7
  32. package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
  33. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +1 -1
  34. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +1 -1
  35. package/dist/client/ManagedIdentitySources/CloudShell.cjs +1 -1
  36. package/dist/client/ManagedIdentitySources/CloudShell.mjs +1 -1
  37. package/dist/client/ManagedIdentitySources/Imds.cjs +1 -1
  38. package/dist/client/ManagedIdentitySources/Imds.mjs +1 -1
  39. package/dist/client/ManagedIdentitySources/ServiceFabric.cjs +1 -1
  40. package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +1 -1
  41. package/dist/client/OnBehalfOfClient.cjs +1 -1
  42. package/dist/client/OnBehalfOfClient.mjs +1 -1
  43. package/dist/client/PublicClientApplication.cjs +1 -1
  44. package/dist/client/PublicClientApplication.mjs +1 -1
  45. package/dist/client/UsernamePasswordClient.cjs +1 -1
  46. package/dist/client/UsernamePasswordClient.mjs +1 -1
  47. package/dist/config/Configuration.cjs +1 -1
  48. package/dist/config/Configuration.mjs +1 -1
  49. package/dist/config/ManagedIdentityId.cjs +1 -1
  50. package/dist/config/ManagedIdentityId.mjs +1 -1
  51. package/dist/config/ManagedIdentityRequestParameters.cjs +1 -1
  52. package/dist/config/ManagedIdentityRequestParameters.mjs +1 -1
  53. package/dist/crypto/CryptoProvider.cjs +15 -1
  54. package/dist/crypto/CryptoProvider.cjs.map +1 -1
  55. package/dist/crypto/CryptoProvider.d.ts +10 -0
  56. package/dist/crypto/CryptoProvider.d.ts.map +1 -1
  57. package/dist/crypto/CryptoProvider.mjs +15 -1
  58. package/dist/crypto/CryptoProvider.mjs.map +1 -1
  59. package/dist/crypto/GuidGenerator.cjs +1 -1
  60. package/dist/crypto/GuidGenerator.mjs +1 -1
  61. package/dist/crypto/HashUtils.cjs +1 -1
  62. package/dist/crypto/HashUtils.mjs +1 -1
  63. package/dist/crypto/PkceGenerator.cjs +1 -1
  64. package/dist/crypto/PkceGenerator.mjs +1 -1
  65. package/dist/error/ManagedIdentityError.cjs +5 -1
  66. package/dist/error/ManagedIdentityError.cjs.map +1 -1
  67. package/dist/error/ManagedIdentityError.d.ts +4 -0
  68. package/dist/error/ManagedIdentityError.d.ts.map +1 -1
  69. package/dist/error/ManagedIdentityError.mjs +6 -2
  70. package/dist/error/ManagedIdentityError.mjs.map +1 -1
  71. package/dist/error/ManagedIdentityErrorCodes.cjs +9 -1
  72. package/dist/error/ManagedIdentityErrorCodes.cjs.map +1 -1
  73. package/dist/error/ManagedIdentityErrorCodes.d.ts +4 -0
  74. package/dist/error/ManagedIdentityErrorCodes.d.ts.map +1 -1
  75. package/dist/error/ManagedIdentityErrorCodes.mjs +6 -2
  76. package/dist/error/ManagedIdentityErrorCodes.mjs.map +1 -1
  77. package/dist/error/NodeAuthError.cjs +1 -1
  78. package/dist/error/NodeAuthError.mjs +1 -1
  79. package/dist/index.cjs +1 -1
  80. package/dist/index.mjs +1 -1
  81. package/dist/internals.cjs +1 -1
  82. package/dist/internals.mjs +1 -1
  83. package/dist/network/HttpClient.cjs +1 -1
  84. package/dist/network/HttpClient.mjs +1 -1
  85. package/dist/network/HttpClientWithRetries.cjs +1 -1
  86. package/dist/network/HttpClientWithRetries.mjs +1 -1
  87. package/dist/network/LoopbackClient.cjs +1 -1
  88. package/dist/network/LoopbackClient.mjs +1 -1
  89. package/dist/packageMetadata.cjs +2 -2
  90. package/dist/packageMetadata.d.ts +1 -1
  91. package/dist/packageMetadata.mjs +2 -2
  92. package/dist/retry/LinearRetryPolicy.cjs +1 -1
  93. package/dist/retry/LinearRetryPolicy.mjs +1 -1
  94. package/dist/utils/Constants.cjs +3 -1
  95. package/dist/utils/Constants.cjs.map +1 -1
  96. package/dist/utils/Constants.d.ts +1 -0
  97. package/dist/utils/Constants.d.ts.map +1 -1
  98. package/dist/utils/Constants.mjs +3 -2
  99. package/dist/utils/Constants.mjs.map +1 -1
  100. package/dist/utils/EncodingUtils.cjs +1 -1
  101. package/dist/utils/EncodingUtils.mjs +1 -1
  102. package/dist/utils/NetworkUtils.cjs +1 -1
  103. package/dist/utils/NetworkUtils.mjs +1 -1
  104. package/package.json +2 -2
  105. package/src/client/ManagedIdentitySources/AzureArc.ts +60 -3
  106. package/src/crypto/CryptoProvider.ts +15 -0
  107. package/src/error/ManagedIdentityError.ts +8 -0
  108. package/src/error/ManagedIdentityErrorCodes.ts +4 -0
  109. package/src/packageMetadata.ts +1 -1
  110. package/src/utils/Constants.ts +2 -0
@@ -24,6 +24,7 @@ import {
24
24
  import {
25
25
  API_VERSION_QUERY_PARAMETER_NAME,
26
26
  AUTHORIZATION_HEADER_NAME,
27
+ AZURE_ARC_SECRET_FILE_MAX_SIZE_BYTES,
27
28
  HttpMethod,
28
29
  METADATA_HEADER_NAME,
29
30
  ManagedIdentityEnvironmentVariableNames,
@@ -32,12 +33,18 @@ import {
32
33
  RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
33
34
  } from "../../utils/Constants";
34
35
  import { NodeStorage } from "../../cache/NodeStorage";
35
- import { readFileSync } from "fs";
36
+ import { readFileSync, statSync } from "fs";
36
37
  import { ManagedIdentityTokenResponse } from "../../response/ManagedIdentityTokenResponse";
37
38
  import { ManagedIdentityId } from "../../config/ManagedIdentityId";
39
+ import path from "path";
38
40
 
39
41
  export const ARC_API_VERSION: string = "2019-11-01";
40
42
 
43
+ export const SUPPORTED_AZURE_ARC_PLATFORMS = {
44
+ win32: `${process.env["ProgramData"]}\\AzureConnectedMachineAgent\\Tokens\\`,
45
+ linux: "/var/opt/azcmagent/tokens/",
46
+ };
47
+
41
48
  /**
42
49
  * Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/AzureArcManagedIdentitySource.cs
43
50
  */
@@ -168,10 +175,60 @@ export class AzureArc extends BaseManagedIdentitySource {
168
175
  );
169
176
  }
170
177
 
171
- const secretFile = wwwAuthHeader.split("Basic realm=")[1];
178
+ const secretFilePath = wwwAuthHeader.split("Basic realm=")[1];
179
+
180
+ // throw an error if the managed identity application is not being run on Windows or Linux
181
+ if (
182
+ !SUPPORTED_AZURE_ARC_PLATFORMS.hasOwnProperty(process.platform)
183
+ ) {
184
+ throw createManagedIdentityError(
185
+ ManagedIdentityErrorCodes.platformNotSupported
186
+ );
187
+ }
188
+
189
+ // get the expected Windows or Linux file path)
190
+ const expectedSecretFilePath: string =
191
+ SUPPORTED_AZURE_ARC_PLATFORMS[process.platform as string];
192
+
193
+ // throw an error if the file in the file path is not a .key file
194
+ const fileName: string = path.basename(secretFilePath);
195
+ if (!fileName.endsWith(".key")) {
196
+ throw createManagedIdentityError(
197
+ ManagedIdentityErrorCodes.invalidFileExtension
198
+ );
199
+ }
200
+
201
+ /*
202
+ * throw an error if the file path from the www-authenticate header does not match the
203
+ * expected file path for the platform (Windows or Linux) the managed identity application
204
+ * is running on
205
+ */
206
+ if (expectedSecretFilePath + fileName !== secretFilePath) {
207
+ throw createManagedIdentityError(
208
+ ManagedIdentityErrorCodes.invalidFilePath
209
+ );
210
+ }
211
+
212
+ let secretFileSize;
213
+ // attempt to get the secret file's size, in bytes
214
+ try {
215
+ secretFileSize = await statSync(secretFilePath).size;
216
+ } catch (e) {
217
+ throw createManagedIdentityError(
218
+ ManagedIdentityErrorCodes.unableToReadSecretFile
219
+ );
220
+ }
221
+ // throw an error if the secret file's size is greater than 4096 bytes
222
+ if (secretFileSize > AZURE_ARC_SECRET_FILE_MAX_SIZE_BYTES) {
223
+ throw createManagedIdentityError(
224
+ ManagedIdentityErrorCodes.invalidSecret
225
+ );
226
+ }
227
+
228
+ // attempt to read the contents of the secret file
172
229
  let secret;
173
230
  try {
174
- secret = readFileSync(secretFile, "utf-8");
231
+ secret = readFileSync(secretFilePath, "utf-8");
175
232
  } catch (e) {
176
233
  throw createManagedIdentityError(
177
234
  ManagedIdentityErrorCodes.unableToReadSecretFile
@@ -26,6 +26,21 @@ export class CryptoProvider implements ICrypto {
26
26
  this.hashUtils = new HashUtils();
27
27
  }
28
28
 
29
+ /**
30
+ * base64 URL safe encoded string
31
+ */
32
+ base64UrlEncode(): string {
33
+ throw new Error("Method not implemented.");
34
+ }
35
+ /**
36
+ * Stringifies and base64Url encodes input public key
37
+ * @param inputKid
38
+ * @returns Base64Url encoded public key
39
+ */
40
+ encodeKid(): string {
41
+ throw new Error("Method not implemented.");
42
+ }
43
+
29
44
  /**
30
45
  * Creates a new random GUID - used to populate state and nonce.
31
46
  * @returns string (GUID)
@@ -12,8 +12,16 @@ export { ManagedIdentityErrorCodes };
12
12
  * ManagedIdentityErrorMessage class containing string constants used by error codes and messages.
13
13
  */
14
14
  export const ManagedIdentityErrorMessages = {
15
+ [ManagedIdentityErrorCodes.invalidFileExtension]:
16
+ "The file path in the WWW-Authenticate header does not contain a .key file.",
17
+ [ManagedIdentityErrorCodes.invalidFilePath]:
18
+ "The file path in the WWW-Authenticate header is not in a valid Windows or Linux Format.",
15
19
  [ManagedIdentityErrorCodes.invalidManagedIdentityIdType]:
16
20
  "More than one ManagedIdentityIdType was provided.",
21
+ [ManagedIdentityErrorCodes.invalidSecret]:
22
+ "The secret in the file on the file path in the WWW-Authenticate header is greater than 4096 bytes.",
23
+ [ManagedIdentityErrorCodes.platformNotSupported]:
24
+ "The platform is not supported by Azure Arc. Azure Arc only supports Windows and Linux.",
17
25
  [ManagedIdentityErrorCodes.missingId]:
18
26
  "A ManagedIdentityId id was not provided.",
19
27
  [ManagedIdentityErrorCodes.MsiEnvironmentVariableUrlMalformedErrorCodes
@@ -5,9 +5,13 @@
5
5
 
6
6
  import { ManagedIdentityEnvironmentVariableNames } from "../utils/Constants";
7
7
 
8
+ export const invalidFileExtension = "invalid_file_extension";
9
+ export const invalidFilePath = "invalid_file_path";
8
10
  export const invalidManagedIdentityIdType = "invalid_managed_identity_id_type";
11
+ export const invalidSecret = "invalid_secret";
9
12
  export const missingId = "missing_client_id";
10
13
  export const networkUnavailable = "network_unavailable";
14
+ export const platformNotSupported = "platform_not_supported";
11
15
  export const unableToCreateAzureArc = "unable_to_create_azure_arc";
12
16
  export const unableToCreateCloudShell = "unable_to_create_cloud_shell";
13
17
  export const unableToCreateSource = "unable_to_create_source";
@@ -1,3 +1,3 @@
1
1
  /* eslint-disable header/header */
2
2
  export const name = "@azure/msal-node";
3
- export const version = "2.9.1";
3
+ export const version = "2.9.2";
@@ -161,6 +161,8 @@ export const LOOPBACK_SERVER_CONSTANTS = {
161
161
  TIMEOUT_MS: 5000,
162
162
  };
163
163
 
164
+ export const AZURE_ARC_SECRET_FILE_MAX_SIZE_BYTES = 4096; // 4 KB
165
+
164
166
  export const MANAGED_IDENTITY_MAX_RETRIES = 3;
165
167
  export const MANAGED_IDENTITY_RETRY_DELAY = 1000;
166
168
  export const MANAGED_IDENTITY_HTTP_STATUS_CODES_TO_RETRY_ON = [