@azure/msal-node 2.7.0-alpha.0 → 2.7.0
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.
- package/dist/cache/ITokenCache.d.ts +15 -15
- package/dist/cache/NodeStorage.cjs +423 -423
- package/dist/cache/NodeStorage.cjs.map +1 -1
- package/dist/cache/NodeStorage.d.ts +193 -193
- package/dist/cache/NodeStorage.d.ts.map +1 -1
- package/dist/cache/NodeStorage.mjs +424 -424
- package/dist/cache/NodeStorage.mjs.map +1 -1
- package/dist/cache/TokenCache.cjs +265 -265
- package/dist/cache/TokenCache.d.ts +90 -90
- package/dist/cache/TokenCache.mjs +265 -265
- package/dist/cache/distributed/DistributedCachePlugin.cjs +26 -26
- package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
- package/dist/cache/distributed/DistributedCachePlugin.mjs +26 -26
- package/dist/cache/distributed/ICacheClient.d.ts +17 -17
- package/dist/cache/distributed/IPartitionManager.d.ts +28 -28
- package/dist/cache/serializer/Deserializer.cjs +167 -170
- package/dist/cache/serializer/Deserializer.cjs.map +1 -1
- package/dist/cache/serializer/Deserializer.d.ts +42 -42
- package/dist/cache/serializer/Deserializer.d.ts.map +1 -1
- package/dist/cache/serializer/Deserializer.mjs +168 -171
- package/dist/cache/serializer/Deserializer.mjs.map +1 -1
- package/dist/cache/serializer/Serializer.cjs +137 -137
- package/dist/cache/serializer/Serializer.d.ts +39 -39
- package/dist/cache/serializer/Serializer.mjs +137 -137
- package/dist/cache/serializer/SerializerTypes.d.ts +102 -102
- package/dist/client/ClientApplication.cjs +333 -333
- package/dist/client/ClientApplication.cjs.map +1 -1
- package/dist/client/ClientApplication.d.ts +142 -142
- package/dist/client/ClientApplication.d.ts.map +1 -1
- package/dist/client/ClientApplication.mjs +333 -333
- package/dist/client/ClientApplication.mjs.map +1 -1
- package/dist/client/ClientAssertion.cjs +116 -116
- package/dist/client/ClientAssertion.d.ts +46 -46
- package/dist/client/ClientAssertion.mjs +116 -116
- package/dist/client/ClientCredentialClient.cjs +194 -194
- package/dist/client/ClientCredentialClient.d.ts +33 -33
- package/dist/client/ClientCredentialClient.mjs +194 -194
- package/dist/client/ConfidentialClientApplication.cjs +163 -163
- package/dist/client/ConfidentialClientApplication.d.ts +58 -58
- package/dist/client/ConfidentialClientApplication.mjs +163 -163
- package/dist/client/DeviceCodeClient.cjs +207 -207
- package/dist/client/DeviceCodeClient.d.ts +53 -53
- package/dist/client/DeviceCodeClient.mjs +207 -207
- package/dist/client/IConfidentialClientApplication.d.ts +39 -39
- package/dist/client/IPublicClientApplication.d.ts +42 -42
- package/dist/client/ManagedIdentityApplication.cjs +79 -78
- package/dist/client/ManagedIdentityApplication.cjs.map +1 -1
- package/dist/client/ManagedIdentityApplication.d.ts +23 -23
- package/dist/client/ManagedIdentityApplication.d.ts.map +1 -1
- package/dist/client/ManagedIdentityApplication.mjs +79 -78
- package/dist/client/ManagedIdentityApplication.mjs.map +1 -1
- package/dist/client/ManagedIdentityClient.cjs +40 -36
- package/dist/client/ManagedIdentityClient.cjs.map +1 -1
- package/dist/client/ManagedIdentityClient.d.ts +19 -24
- package/dist/client/ManagedIdentityClient.d.ts.map +1 -1
- package/dist/client/ManagedIdentityClient.mjs +40 -36
- package/dist/client/ManagedIdentityClient.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AppService.cjs +42 -69
- package/dist/client/ManagedIdentitySources/AppService.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AppService.d.ts +16 -16
- package/dist/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/AppService.mjs +43 -70
- package/dist/client/ManagedIdentitySources/AppService.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.cjs +81 -92
- package/dist/client/ManagedIdentitySources/AzureArc.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts +18 -18
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.mjs +84 -95
- package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +112 -77
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +30 -18
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +114 -80
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.cjs +47 -0
- package/dist/client/ManagedIdentitySources/CloudShell.cjs.map +1 -0
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts +15 -6
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.mjs +45 -0
- package/dist/client/ManagedIdentitySources/CloudShell.mjs.map +1 -0
- package/dist/client/ManagedIdentitySources/Imds.cjs +43 -52
- package/dist/client/ManagedIdentitySources/Imds.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/Imds.d.ts +12 -12
- package/dist/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/Imds.mjs +44 -53
- package/dist/client/ManagedIdentitySources/Imds.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.cjs +61 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.cjs.map +1 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +16 -6
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +59 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs.map +1 -0
- package/dist/client/OnBehalfOfClient.cjs +202 -202
- package/dist/client/OnBehalfOfClient.d.ts +47 -47
- package/dist/client/OnBehalfOfClient.mjs +202 -202
- package/dist/client/PublicClientApplication.cjs +229 -229
- package/dist/client/PublicClientApplication.d.ts +71 -71
- package/dist/client/PublicClientApplication.mjs +229 -229
- package/dist/client/UsernamePasswordClient.cjs +95 -95
- package/dist/client/UsernamePasswordClient.d.ts +25 -25
- package/dist/client/UsernamePasswordClient.mjs +95 -95
- package/dist/config/Configuration.cjs +102 -86
- package/dist/config/Configuration.cjs.map +1 -1
- package/dist/config/Configuration.d.ts +123 -122
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +102 -86
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/config/ManagedIdentityId.cjs +48 -48
- package/dist/config/ManagedIdentityId.d.ts +11 -11
- package/dist/config/ManagedIdentityId.mjs +48 -48
- package/dist/config/ManagedIdentityRequestParameters.cjs +28 -29
- package/dist/config/ManagedIdentityRequestParameters.cjs.map +1 -1
- package/dist/config/ManagedIdentityRequestParameters.d.ts +11 -11
- package/dist/config/ManagedIdentityRequestParameters.d.ts.map +1 -1
- package/dist/config/ManagedIdentityRequestParameters.mjs +28 -29
- package/dist/config/ManagedIdentityRequestParameters.mjs.map +1 -1
- package/dist/crypto/CryptoProvider.cjs +75 -75
- package/dist/crypto/CryptoProvider.d.ts +52 -52
- package/dist/crypto/CryptoProvider.mjs +75 -75
- package/dist/crypto/GuidGenerator.cjs +22 -22
- package/dist/crypto/GuidGenerator.d.ts +14 -14
- package/dist/crypto/GuidGenerator.mjs +22 -22
- package/dist/crypto/HashUtils.cjs +13 -13
- package/dist/crypto/HashUtils.d.ts +8 -8
- package/dist/crypto/HashUtils.mjs +13 -13
- package/dist/crypto/PkceGenerator.cjs +49 -49
- package/dist/crypto/PkceGenerator.d.ts +22 -22
- package/dist/crypto/PkceGenerator.mjs +49 -49
- package/dist/error/ManagedIdentityError.cjs +39 -28
- package/dist/error/ManagedIdentityError.cjs.map +1 -1
- package/dist/error/ManagedIdentityError.d.ts +27 -21
- package/dist/error/ManagedIdentityError.d.ts.map +1 -1
- package/dist/error/ManagedIdentityError.mjs +40 -29
- package/dist/error/ManagedIdentityError.mjs.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.cjs +27 -14
- package/dist/error/ManagedIdentityErrorCodes.cjs.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.d.ts +19 -9
- package/dist/error/ManagedIdentityErrorCodes.d.ts.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.mjs +24 -14
- package/dist/error/ManagedIdentityErrorCodes.mjs.map +1 -1
- package/dist/error/NodeAuthError.cjs +85 -85
- package/dist/error/NodeAuthError.d.ts +65 -65
- package/dist/error/NodeAuthError.mjs +85 -85
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +44 -44
- package/dist/index.mjs +1 -1
- package/dist/internals.cjs +8 -8
- package/dist/internals.d.ts +6 -6
- package/dist/internals.mjs +8 -8
- package/dist/network/HttpClient.cjs +283 -283
- package/dist/network/HttpClient.cjs.map +1 -1
- package/dist/network/HttpClient.d.ts +25 -26
- package/dist/network/HttpClient.d.ts.map +1 -1
- package/dist/network/HttpClient.mjs +283 -283
- package/dist/network/HttpClient.mjs.map +1 -1
- package/dist/network/HttpClientWithRetries.cjs +44 -0
- package/dist/network/HttpClientWithRetries.cjs.map +1 -0
- package/dist/network/HttpClientWithRetries.d.ts +12 -0
- package/dist/network/HttpClientWithRetries.d.ts.map +1 -0
- package/dist/network/HttpClientWithRetries.mjs +42 -0
- package/dist/network/HttpClientWithRetries.mjs.map +1 -0
- package/dist/network/ILoopbackClient.d.ts +10 -10
- package/dist/network/LoopbackClient.cjs +77 -77
- package/dist/network/LoopbackClient.d.ts +21 -21
- package/dist/network/LoopbackClient.mjs +77 -77
- package/dist/packageMetadata.cjs +4 -4
- package/dist/packageMetadata.d.ts +2 -2
- package/dist/packageMetadata.d.ts.map +1 -1
- package/dist/packageMetadata.mjs +4 -4
- package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
- package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
- package/dist/request/ClientCredentialRequest.d.ts +14 -14
- package/dist/request/DeviceCodeRequest.d.ts +15 -15
- package/dist/request/InteractiveRequest.d.ts +22 -22
- package/dist/request/ManagedIdentityRequest.d.ts +8 -8
- package/dist/request/ManagedIdentityRequestParams.d.ts +9 -9
- package/dist/request/OnBehalfOfRequest.d.ts +14 -14
- package/dist/request/RefreshTokenRequest.d.ts +17 -17
- package/dist/request/SignOutRequest.d.ts +5 -5
- package/dist/request/SilentFlowRequest.d.ts +16 -16
- package/dist/request/UsernamePasswordRequest.d.ts +19 -19
- package/dist/response/ManagedIdentityTokenResponse.d.ts +24 -24
- package/dist/retry/IHttpRetryPolicy.d.ts +6 -0
- package/dist/retry/IHttpRetryPolicy.d.ts.map +1 -0
- package/dist/retry/LinearRetryPolicy.cjs +47 -0
- package/dist/retry/LinearRetryPolicy.cjs.map +1 -0
- package/dist/retry/LinearRetryPolicy.d.ts +12 -0
- package/dist/retry/LinearRetryPolicy.d.ts.map +1 -0
- package/dist/retry/LinearRetryPolicy.mjs +45 -0
- package/dist/retry/LinearRetryPolicy.mjs.map +1 -0
- package/dist/utils/Constants.cjs +141 -103
- package/dist/utils/Constants.cjs.map +1 -1
- package/dist/utils/Constants.d.ts +131 -106
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +133 -100
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/EncodingUtils.cjs +44 -44
- package/dist/utils/EncodingUtils.d.ts +26 -26
- package/dist/utils/EncodingUtils.mjs +44 -44
- package/dist/utils/NetworkUtils.cjs +38 -38
- package/dist/utils/NetworkUtils.d.ts +5 -5
- package/dist/utils/NetworkUtils.mjs +38 -38
- package/package.json +5 -5
- package/src/cache/NodeStorage.ts +4 -9
- package/src/cache/serializer/Deserializer.ts +1 -5
- package/src/client/ClientApplication.ts +5 -4
- package/src/client/ManagedIdentityApplication.ts +3 -3
- package/src/client/ManagedIdentityClient.ts +23 -11
- package/src/client/ManagedIdentitySources/AppService.ts +68 -97
- package/src/client/ManagedIdentitySources/AzureArc.ts +59 -68
- package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +70 -2
- package/src/client/ManagedIdentitySources/CloudShell.ts +93 -8
- package/src/client/ManagedIdentitySources/Imds.ts +54 -40
- package/src/client/ManagedIdentitySources/ServiceFabric.ts +126 -5
- package/src/config/Configuration.ts +44 -16
- package/src/config/ManagedIdentityRequestParameters.ts +1 -6
- package/src/error/ManagedIdentityError.ts +15 -2
- package/src/error/ManagedIdentityErrorCodes.ts +19 -0
- package/src/network/HttpClient.ts +6 -11
- package/src/network/HttpClientWithRetries.ts +80 -0
- package/src/packageMetadata.ts +1 -1
- package/src/retry/IHttpRetryPolicy.ts +18 -0
- package/src/retry/LinearRetryPolicy.ts +71 -0
- package/src/utils/Constants.ts +43 -7
|
@@ -12,10 +12,8 @@ import {
|
|
|
12
12
|
NetworkResponse,
|
|
13
13
|
NetworkRequestOptions,
|
|
14
14
|
Logger,
|
|
15
|
-
UrlString,
|
|
16
15
|
ServerAuthorizationTokenResponse,
|
|
17
16
|
} from "@azure/msal-common";
|
|
18
|
-
import { ManagedIdentityId } from "../../config/ManagedIdentityId";
|
|
19
17
|
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters";
|
|
20
18
|
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource";
|
|
21
19
|
import { CryptoProvider } from "../../crypto/CryptoProvider";
|
|
@@ -24,14 +22,19 @@ import {
|
|
|
24
22
|
createManagedIdentityError,
|
|
25
23
|
} from "../../error/ManagedIdentityError";
|
|
26
24
|
import {
|
|
25
|
+
API_VERSION_QUERY_PARAMETER_NAME,
|
|
27
26
|
AUTHORIZATION_HEADER_NAME,
|
|
28
27
|
HttpMethod,
|
|
29
28
|
METADATA_HEADER_NAME,
|
|
29
|
+
ManagedIdentityEnvironmentVariableNames,
|
|
30
30
|
ManagedIdentityIdType,
|
|
31
|
+
ManagedIdentitySourceNames,
|
|
32
|
+
RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
|
|
31
33
|
} from "../../utils/Constants";
|
|
32
34
|
import { NodeStorage } from "../../cache/NodeStorage";
|
|
33
35
|
import { readFileSync } from "fs";
|
|
34
36
|
import { ManagedIdentityTokenResponse } from "../../response/ManagedIdentityTokenResponse";
|
|
37
|
+
import { ManagedIdentityId } from "../../config/ManagedIdentityId";
|
|
35
38
|
|
|
36
39
|
export const ARC_API_VERSION: string = "2019-11-01";
|
|
37
40
|
|
|
@@ -39,52 +42,65 @@ export const ARC_API_VERSION: string = "2019-11-01";
|
|
|
39
42
|
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/AzureArcManagedIdentitySource.cs
|
|
40
43
|
*/
|
|
41
44
|
export class AzureArc extends BaseManagedIdentitySource {
|
|
42
|
-
private
|
|
45
|
+
private identityEndpoint: string;
|
|
43
46
|
|
|
44
47
|
constructor(
|
|
45
48
|
logger: Logger,
|
|
46
49
|
nodeStorage: NodeStorage,
|
|
47
50
|
networkClient: INetworkModule,
|
|
48
51
|
cryptoProvider: CryptoProvider,
|
|
49
|
-
|
|
52
|
+
identityEndpoint: string
|
|
50
53
|
) {
|
|
51
54
|
super(logger, nodeStorage, networkClient, cryptoProvider);
|
|
52
55
|
|
|
53
|
-
this.
|
|
56
|
+
this.identityEndpoint = identityEndpoint;
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
public static tryCreate(
|
|
57
60
|
logger: Logger,
|
|
58
61
|
nodeStorage: NodeStorage,
|
|
59
62
|
networkClient: INetworkModule,
|
|
60
|
-
cryptoProvider: CryptoProvider
|
|
63
|
+
cryptoProvider: CryptoProvider,
|
|
64
|
+
managedIdentityId: ManagedIdentityId
|
|
61
65
|
): AzureArc | null {
|
|
62
|
-
const
|
|
66
|
+
const identityEndpoint: string | undefined =
|
|
67
|
+
process.env[
|
|
68
|
+
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT
|
|
69
|
+
];
|
|
70
|
+
const imdsEndpoint: string | undefined =
|
|
71
|
+
process.env[ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT];
|
|
72
|
+
|
|
73
|
+
// if either of the identity or imds endpoints are undefined, this MSI provider is unavailable.
|
|
74
|
+
if (!identityEndpoint || !imdsEndpoint) {
|
|
75
|
+
logger.info(
|
|
76
|
+
`[Managed Identity] ${ManagedIdentitySourceNames.AZURE_ARC} managed identity is unavailable because one or both of the '${ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT}' and '${ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT}' environment variables are not defined.`
|
|
77
|
+
);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const validatedIdentityEndpoint: string =
|
|
82
|
+
AzureArc.getValidatedEnvVariableUrlString(
|
|
83
|
+
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT,
|
|
84
|
+
identityEndpoint,
|
|
85
|
+
ManagedIdentitySourceNames.AZURE_ARC,
|
|
86
|
+
logger
|
|
87
|
+
);
|
|
88
|
+
// remove trailing slash
|
|
89
|
+
validatedIdentityEndpoint.endsWith("/")
|
|
90
|
+
? validatedIdentityEndpoint.slice(0, -1)
|
|
91
|
+
: validatedIdentityEndpoint;
|
|
63
92
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
string | undefined
|
|
67
|
-
] = validateEnvironmentVariables(
|
|
68
|
-
process.env["IDENTITY_ENDPOINT"] || undefined,
|
|
93
|
+
AzureArc.getValidatedEnvVariableUrlString(
|
|
94
|
+
ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT,
|
|
69
95
|
imdsEndpoint,
|
|
96
|
+
ManagedIdentitySourceNames.AZURE_ARC,
|
|
70
97
|
logger
|
|
71
98
|
);
|
|
72
99
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
nodeStorage,
|
|
77
|
-
networkClient,
|
|
78
|
-
cryptoProvider,
|
|
79
|
-
endpoint as string
|
|
80
|
-
)
|
|
81
|
-
: null;
|
|
82
|
-
}
|
|
100
|
+
logger.info(
|
|
101
|
+
`[Managed Identity] Environment variables validation passed for ${ManagedIdentitySourceNames.AZURE_ARC} managed identity. Endpoint URI: ${validatedIdentityEndpoint}. Creating ${ManagedIdentitySourceNames.AZURE_ARC} managed identity.`
|
|
102
|
+
);
|
|
83
103
|
|
|
84
|
-
public createRequest(
|
|
85
|
-
resource: string,
|
|
86
|
-
managedIdentityId: ManagedIdentityId
|
|
87
|
-
): ManagedIdentityRequestParameters {
|
|
88
104
|
if (
|
|
89
105
|
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
|
90
106
|
) {
|
|
@@ -93,15 +109,29 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
93
109
|
);
|
|
94
110
|
}
|
|
95
111
|
|
|
112
|
+
return new AzureArc(
|
|
113
|
+
logger,
|
|
114
|
+
nodeStorage,
|
|
115
|
+
networkClient,
|
|
116
|
+
cryptoProvider,
|
|
117
|
+
identityEndpoint
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public createRequest(resource: string): ManagedIdentityRequestParameters {
|
|
96
122
|
const request: ManagedIdentityRequestParameters =
|
|
97
123
|
new ManagedIdentityRequestParameters(
|
|
98
124
|
HttpMethod.GET,
|
|
99
|
-
this.
|
|
125
|
+
this.identityEndpoint.replace("localhost", "127.0.0.1")
|
|
100
126
|
);
|
|
101
127
|
|
|
102
128
|
request.headers[METADATA_HEADER_NAME] = "true";
|
|
103
|
-
|
|
104
|
-
request.queryParameters[
|
|
129
|
+
|
|
130
|
+
request.queryParameters[API_VERSION_QUERY_PARAMETER_NAME] =
|
|
131
|
+
ARC_API_VERSION;
|
|
132
|
+
request.queryParameters[RESOURCE_BODY_OR_QUERY_PARAMETER_NAME] =
|
|
133
|
+
resource;
|
|
134
|
+
|
|
105
135
|
// bodyParameters calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity
|
|
106
136
|
|
|
107
137
|
return request;
|
|
@@ -167,42 +197,3 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
167
197
|
return this.getServerTokenResponse(retryResponse || originalResponse);
|
|
168
198
|
}
|
|
169
199
|
}
|
|
170
|
-
|
|
171
|
-
const validateEnvironmentVariables = (
|
|
172
|
-
identityEndpoint: string | undefined,
|
|
173
|
-
imdsEndpoint: string | undefined,
|
|
174
|
-
logger: Logger
|
|
175
|
-
): [boolean, string | undefined] => {
|
|
176
|
-
let endpointUrlString: string | undefined;
|
|
177
|
-
|
|
178
|
-
// if either of the identity or imds endpoints are undefined, this MSI provider is unavailable.
|
|
179
|
-
if (!identityEndpoint || !imdsEndpoint) {
|
|
180
|
-
logger.info(
|
|
181
|
-
"[Managed Identity] Azure Arc managed identity is unavailable because one or both of the 'IDENTITY_ENDPOINT' and 'IMDS_ENDPOINT' environment variables are missing."
|
|
182
|
-
);
|
|
183
|
-
return [false, endpointUrlString];
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
try {
|
|
187
|
-
endpointUrlString = new UrlString(identityEndpoint).urlString;
|
|
188
|
-
} catch (error) {
|
|
189
|
-
logger.info(
|
|
190
|
-
"[Managed Identity] App service managed identity is unavailable because the 'IDENTITY_ENDPOINT' environment variable is malformed."
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
throw createManagedIdentityError(
|
|
194
|
-
ManagedIdentityErrorCodes.urlParseError
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
logger.info(
|
|
199
|
-
`[Managed Identity] Environment variables validation passed for Azure Arc managed identity. Endpoint URI: ${endpointUrlString}. Creating Azure Arc managed identity.`
|
|
200
|
-
);
|
|
201
|
-
return [
|
|
202
|
-
true,
|
|
203
|
-
// remove trailing slash
|
|
204
|
-
endpointUrlString.endsWith("/")
|
|
205
|
-
? endpointUrlString.slice(0, -1)
|
|
206
|
-
: endpointUrlString,
|
|
207
|
-
];
|
|
208
|
-
};
|
|
@@ -18,14 +18,30 @@ import {
|
|
|
18
18
|
TimeUtils,
|
|
19
19
|
createClientAuthError,
|
|
20
20
|
AuthenticationResult,
|
|
21
|
+
UrlString,
|
|
21
22
|
} from "@azure/msal-common";
|
|
22
23
|
import { ManagedIdentityId } from "../../config/ManagedIdentityId";
|
|
23
24
|
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters";
|
|
24
25
|
import { CryptoProvider } from "../../crypto/CryptoProvider";
|
|
25
26
|
import { ManagedIdentityRequest } from "../../request/ManagedIdentityRequest";
|
|
26
|
-
import { HttpMethod } from "../../utils/Constants";
|
|
27
|
+
import { HttpMethod, ManagedIdentityIdType } from "../../utils/Constants";
|
|
27
28
|
import { ManagedIdentityTokenResponse } from "../../response/ManagedIdentityTokenResponse";
|
|
28
29
|
import { NodeStorage } from "../../cache/NodeStorage";
|
|
30
|
+
import {
|
|
31
|
+
ManagedIdentityErrorCodes,
|
|
32
|
+
createManagedIdentityError,
|
|
33
|
+
} from "../../error/ManagedIdentityError";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Managed Identity User Assigned Id Query Parameter Names
|
|
37
|
+
*/
|
|
38
|
+
export const ManagedIdentityUserAssignedIdQueryParameterNames = {
|
|
39
|
+
MANAGED_IDENTITY_CLIENT_ID: "client_id",
|
|
40
|
+
MANAGED_IDENTITY_OBJECT_ID: "object_id",
|
|
41
|
+
MANAGED_IDENTITY_RESOURCE_ID: "mi_res_id",
|
|
42
|
+
} as const;
|
|
43
|
+
export type ManagedIdentityUserAssignedIdQueryParameterNames =
|
|
44
|
+
(typeof ManagedIdentityUserAssignedIdQueryParameterNames)[keyof typeof ManagedIdentityUserAssignedIdQueryParameterNames];
|
|
29
45
|
|
|
30
46
|
export abstract class BaseManagedIdentitySource {
|
|
31
47
|
protected logger: Logger;
|
|
@@ -104,8 +120,10 @@ export abstract class BaseManagedIdentitySource {
|
|
|
104
120
|
|
|
105
121
|
const headers: Record<string, string> = networkRequest.headers;
|
|
106
122
|
headers[HeaderNames.CONTENT_TYPE] = Constants.URL_FORM_CONTENT_TYPE;
|
|
123
|
+
|
|
107
124
|
const networkRequestOptions: NetworkRequestOptions = { headers };
|
|
108
|
-
|
|
125
|
+
|
|
126
|
+
if (Object.keys(networkRequest.bodyParameters).length) {
|
|
109
127
|
networkRequestOptions.body =
|
|
110
128
|
networkRequest.computeParametersBodyString();
|
|
111
129
|
}
|
|
@@ -166,4 +184,54 @@ export abstract class BaseManagedIdentitySource {
|
|
|
166
184
|
managedIdentityRequest
|
|
167
185
|
);
|
|
168
186
|
}
|
|
187
|
+
|
|
188
|
+
public getManagedIdentityUserAssignedIdQueryParameterKey(
|
|
189
|
+
managedIdentityIdType: ManagedIdentityIdType
|
|
190
|
+
): string {
|
|
191
|
+
switch (managedIdentityIdType) {
|
|
192
|
+
case ManagedIdentityIdType.USER_ASSIGNED_CLIENT_ID:
|
|
193
|
+
this.logger.info(
|
|
194
|
+
"[Managed Identity] Adding user assigned client id to the request."
|
|
195
|
+
);
|
|
196
|
+
return ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_CLIENT_ID;
|
|
197
|
+
|
|
198
|
+
case ManagedIdentityIdType.USER_ASSIGNED_RESOURCE_ID:
|
|
199
|
+
this.logger.info(
|
|
200
|
+
"[Managed Identity] Adding user assigned resource id to the request."
|
|
201
|
+
);
|
|
202
|
+
return ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_RESOURCE_ID;
|
|
203
|
+
|
|
204
|
+
case ManagedIdentityIdType.USER_ASSIGNED_OBJECT_ID:
|
|
205
|
+
this.logger.info(
|
|
206
|
+
"[Managed Identity] Adding user assigned object id to the request."
|
|
207
|
+
);
|
|
208
|
+
return ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_OBJECT_ID;
|
|
209
|
+
default:
|
|
210
|
+
throw createManagedIdentityError(
|
|
211
|
+
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
public static getValidatedEnvVariableUrlString = (
|
|
217
|
+
envVariableStringName: string,
|
|
218
|
+
envVariable: string,
|
|
219
|
+
sourceName: string,
|
|
220
|
+
logger: Logger
|
|
221
|
+
): string => {
|
|
222
|
+
try {
|
|
223
|
+
return new UrlString(envVariable).urlString;
|
|
224
|
+
} catch (error) {
|
|
225
|
+
logger.info(
|
|
226
|
+
`[Managed Identity] ${sourceName} managed identity is unavailable because the '${envVariableStringName}' environment variable is malformed.`
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
throw createManagedIdentityError(
|
|
230
|
+
ManagedIdentityErrorCodes
|
|
231
|
+
.MsiEnvironmentVariableUrlMalformedErrorCodes[
|
|
232
|
+
envVariableStringName
|
|
233
|
+
]
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
169
237
|
}
|
|
@@ -3,17 +3,102 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { INetworkModule, Logger } from "@azure/msal-common";
|
|
7
7
|
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters";
|
|
8
8
|
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource";
|
|
9
|
+
import { NodeStorage } from "../../cache/NodeStorage";
|
|
10
|
+
import { CryptoProvider } from "../../crypto/CryptoProvider";
|
|
11
|
+
import {
|
|
12
|
+
HttpMethod,
|
|
13
|
+
METADATA_HEADER_NAME,
|
|
14
|
+
ManagedIdentityEnvironmentVariableNames,
|
|
15
|
+
ManagedIdentityIdType,
|
|
16
|
+
ManagedIdentitySourceNames,
|
|
17
|
+
RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
|
|
18
|
+
} from "../../utils/Constants";
|
|
19
|
+
import {
|
|
20
|
+
ManagedIdentityErrorCodes,
|
|
21
|
+
createManagedIdentityError,
|
|
22
|
+
} from "../../error/ManagedIdentityError";
|
|
23
|
+
import { ManagedIdentityId } from "../../config/ManagedIdentityId";
|
|
9
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/CloudShellManagedIdentitySource.cs
|
|
27
|
+
*/
|
|
10
28
|
export class CloudShell extends BaseManagedIdentitySource {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
29
|
+
private msiEndpoint: string;
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
logger: Logger,
|
|
33
|
+
nodeStorage: NodeStorage,
|
|
34
|
+
networkClient: INetworkModule,
|
|
35
|
+
cryptoProvider: CryptoProvider,
|
|
36
|
+
msiEndpoint: string
|
|
37
|
+
) {
|
|
38
|
+
super(logger, nodeStorage, networkClient, cryptoProvider);
|
|
39
|
+
|
|
40
|
+
this.msiEndpoint = msiEndpoint;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public static tryCreate(
|
|
44
|
+
logger: Logger,
|
|
45
|
+
nodeStorage: NodeStorage,
|
|
46
|
+
networkClient: INetworkModule,
|
|
47
|
+
cryptoProvider: CryptoProvider,
|
|
48
|
+
managedIdentityId: ManagedIdentityId
|
|
49
|
+
): CloudShell | null {
|
|
50
|
+
const msiEndpoint: string | undefined =
|
|
51
|
+
process.env[ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT];
|
|
52
|
+
|
|
53
|
+
// if the msi endpoint environment variable is undefined, this MSI provider is unavailable.
|
|
54
|
+
if (!msiEndpoint) {
|
|
55
|
+
logger.info(
|
|
56
|
+
`[Managed Identity] ${ManagedIdentitySourceNames.CLOUD_SHELL} managed identity is unavailable because the '${ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT} environment variable is not defined.`
|
|
57
|
+
);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const validatedMsiEndpoint: string =
|
|
62
|
+
CloudShell.getValidatedEnvVariableUrlString(
|
|
63
|
+
ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT,
|
|
64
|
+
msiEndpoint,
|
|
65
|
+
ManagedIdentitySourceNames.CLOUD_SHELL,
|
|
66
|
+
logger
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
logger.info(
|
|
70
|
+
`[Managed Identity] Environment variable validation passed for ${ManagedIdentitySourceNames.CLOUD_SHELL} managed identity. Endpoint URI: ${validatedMsiEndpoint}. Creating ${ManagedIdentitySourceNames.CLOUD_SHELL} managed identity.`
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
if (
|
|
74
|
+
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
|
75
|
+
) {
|
|
76
|
+
throw createManagedIdentityError(
|
|
77
|
+
ManagedIdentityErrorCodes.unableToCreateCloudShell
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return new CloudShell(
|
|
82
|
+
logger,
|
|
83
|
+
nodeStorage,
|
|
84
|
+
networkClient,
|
|
85
|
+
cryptoProvider,
|
|
86
|
+
msiEndpoint
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public createRequest(resource: string): ManagedIdentityRequestParameters {
|
|
91
|
+
const request: ManagedIdentityRequestParameters =
|
|
92
|
+
new ManagedIdentityRequestParameters(
|
|
93
|
+
HttpMethod.POST,
|
|
94
|
+
this.msiEndpoint
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
request.headers[METADATA_HEADER_NAME] = "true";
|
|
98
|
+
|
|
99
|
+
request.bodyParameters[RESOURCE_BODY_OR_QUERY_PARAMETER_NAME] =
|
|
100
|
+
resource;
|
|
101
|
+
|
|
102
|
+
return request;
|
|
18
103
|
}
|
|
19
104
|
}
|
|
@@ -9,12 +9,13 @@ import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRe
|
|
|
9
9
|
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource";
|
|
10
10
|
import { CryptoProvider } from "../../crypto/CryptoProvider";
|
|
11
11
|
import {
|
|
12
|
+
API_VERSION_QUERY_PARAMETER_NAME,
|
|
12
13
|
HttpMethod,
|
|
13
|
-
MANAGED_IDENTITY_CLIENT_ID,
|
|
14
|
-
MANAGED_IDENTITY_OBJECT_ID,
|
|
15
|
-
MANAGED_IDENTITY_RESOURCE_ID,
|
|
16
14
|
METADATA_HEADER_NAME,
|
|
15
|
+
ManagedIdentityEnvironmentVariableNames,
|
|
17
16
|
ManagedIdentityIdType,
|
|
17
|
+
ManagedIdentitySourceNames,
|
|
18
|
+
RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
|
|
18
19
|
} from "../../utils/Constants";
|
|
19
20
|
import { NodeStorage } from "../../cache/NodeStorage";
|
|
20
21
|
|
|
@@ -26,18 +27,18 @@ const IMDS_API_VERSION: string = "2018-02-01";
|
|
|
26
27
|
|
|
27
28
|
// Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs
|
|
28
29
|
export class Imds extends BaseManagedIdentitySource {
|
|
29
|
-
private
|
|
30
|
+
private identityEndpoint: string;
|
|
30
31
|
|
|
31
32
|
constructor(
|
|
32
33
|
logger: Logger,
|
|
33
34
|
nodeStorage: NodeStorage,
|
|
34
35
|
networkClient: INetworkModule,
|
|
35
36
|
cryptoProvider: CryptoProvider,
|
|
36
|
-
|
|
37
|
+
identityEndpoint: string
|
|
37
38
|
) {
|
|
38
39
|
super(logger, nodeStorage, networkClient, cryptoProvider);
|
|
39
40
|
|
|
40
|
-
this.
|
|
41
|
+
this.identityEndpoint = identityEndpoint;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
public static tryCreate(
|
|
@@ -46,18 +47,40 @@ export class Imds extends BaseManagedIdentitySource {
|
|
|
46
47
|
networkClient: INetworkModule,
|
|
47
48
|
cryptoProvider: CryptoProvider
|
|
48
49
|
): Imds {
|
|
49
|
-
let
|
|
50
|
+
let validatedIdentityEndpoint: string;
|
|
50
51
|
|
|
51
|
-
if (
|
|
52
|
+
if (
|
|
53
|
+
process.env[
|
|
54
|
+
ManagedIdentityEnvironmentVariableNames
|
|
55
|
+
.AZURE_POD_IDENTITY_AUTHORITY_HOST
|
|
56
|
+
]
|
|
57
|
+
) {
|
|
52
58
|
logger.info(
|
|
53
|
-
`[Managed Identity] Environment variable
|
|
59
|
+
`[Managed Identity] Environment variable ${
|
|
60
|
+
ManagedIdentityEnvironmentVariableNames.AZURE_POD_IDENTITY_AUTHORITY_HOST
|
|
61
|
+
} for ${ManagedIdentitySourceNames.IMDS} returned endpoint: ${
|
|
62
|
+
process.env[
|
|
63
|
+
ManagedIdentityEnvironmentVariableNames
|
|
64
|
+
.AZURE_POD_IDENTITY_AUTHORITY_HOST
|
|
65
|
+
]
|
|
66
|
+
}`
|
|
67
|
+
);
|
|
68
|
+
validatedIdentityEndpoint = Imds.getValidatedEnvVariableUrlString(
|
|
69
|
+
ManagedIdentityEnvironmentVariableNames.AZURE_POD_IDENTITY_AUTHORITY_HOST,
|
|
70
|
+
`${
|
|
71
|
+
process.env[
|
|
72
|
+
ManagedIdentityEnvironmentVariableNames
|
|
73
|
+
.AZURE_POD_IDENTITY_AUTHORITY_HOST
|
|
74
|
+
]
|
|
75
|
+
}${IMDS_TOKEN_PATH}`,
|
|
76
|
+
ManagedIdentitySourceNames.IMDS,
|
|
77
|
+
logger
|
|
54
78
|
);
|
|
55
|
-
endpoint = `${process.env["AZURE_POD_IDENTITY_AUTHORITY_HOST"]}${IMDS_TOKEN_PATH}`;
|
|
56
79
|
} else {
|
|
57
80
|
logger.info(
|
|
58
|
-
|
|
81
|
+
`[Managed Identity] Unable to find ${ManagedIdentityEnvironmentVariableNames.AZURE_POD_IDENTITY_AUTHORITY_HOST} environment variable for ${ManagedIdentitySourceNames.IMDS}, using the default endpoint.`
|
|
59
82
|
);
|
|
60
|
-
|
|
83
|
+
validatedIdentityEndpoint = DEFAULT_IMDS_ENDPOINT;
|
|
61
84
|
}
|
|
62
85
|
|
|
63
86
|
return new Imds(
|
|
@@ -65,7 +88,7 @@ export class Imds extends BaseManagedIdentitySource {
|
|
|
65
88
|
nodeStorage,
|
|
66
89
|
networkClient,
|
|
67
90
|
cryptoProvider,
|
|
68
|
-
|
|
91
|
+
validatedIdentityEndpoint
|
|
69
92
|
);
|
|
70
93
|
}
|
|
71
94
|
|
|
@@ -74,39 +97,30 @@ export class Imds extends BaseManagedIdentitySource {
|
|
|
74
97
|
managedIdentityId: ManagedIdentityId
|
|
75
98
|
): ManagedIdentityRequestParameters {
|
|
76
99
|
const request: ManagedIdentityRequestParameters =
|
|
77
|
-
new ManagedIdentityRequestParameters(
|
|
100
|
+
new ManagedIdentityRequestParameters(
|
|
101
|
+
HttpMethod.GET,
|
|
102
|
+
this.identityEndpoint
|
|
103
|
+
);
|
|
78
104
|
|
|
79
105
|
request.headers[METADATA_HEADER_NAME] = "true";
|
|
80
|
-
request.queryParameters["api-version"] = IMDS_API_VERSION;
|
|
81
|
-
request.queryParameters["resource"] = resource;
|
|
82
|
-
// bodyParameters calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity
|
|
83
106
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
);
|
|
89
|
-
request.queryParameters[MANAGED_IDENTITY_CLIENT_ID] =
|
|
90
|
-
managedIdentityId.id;
|
|
91
|
-
break;
|
|
107
|
+
request.queryParameters[API_VERSION_QUERY_PARAMETER_NAME] =
|
|
108
|
+
IMDS_API_VERSION;
|
|
109
|
+
request.queryParameters[RESOURCE_BODY_OR_QUERY_PARAMETER_NAME] =
|
|
110
|
+
resource;
|
|
92
111
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
managedIdentityId.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
case ManagedIdentityIdType.USER_ASSIGNED_OBJECT_ID:
|
|
102
|
-
this.logger.info(
|
|
103
|
-
"[Managed Identity] Adding user assigned object id to the request."
|
|
104
|
-
);
|
|
105
|
-
request.queryParameters[MANAGED_IDENTITY_OBJECT_ID] =
|
|
106
|
-
managedIdentityId.id;
|
|
107
|
-
break;
|
|
112
|
+
if (
|
|
113
|
+
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
|
114
|
+
) {
|
|
115
|
+
request.queryParameters[
|
|
116
|
+
this.getManagedIdentityUserAssignedIdQueryParameterKey(
|
|
117
|
+
managedIdentityId.idType
|
|
118
|
+
)
|
|
119
|
+
] = managedIdentityId.id;
|
|
108
120
|
}
|
|
109
121
|
|
|
122
|
+
// bodyParameters calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity
|
|
123
|
+
|
|
110
124
|
return request;
|
|
111
125
|
}
|
|
112
126
|
}
|