@azure/msal-node 2.7.0-alpha.0 → 2.7.1-alpha.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/README.md +1 -1
- 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 +335 -333
- package/dist/client/ClientApplication.cjs.map +1 -1
- package/dist/client/ClientApplication.d.ts +143 -142
- package/dist/client/ClientApplication.d.ts.map +1 -1
- package/dist/client/ClientApplication.mjs +336 -334
- 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.cjs.map +1 -1
- package/dist/client/ClientCredentialClient.d.ts +33 -33
- package/dist/client/ClientCredentialClient.d.ts.map +1 -1
- package/dist/client/ClientCredentialClient.mjs +195 -195
- package/dist/client/ClientCredentialClient.mjs.map +1 -1
- package/dist/client/ConfidentialClientApplication.cjs +166 -163
- package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
- package/dist/client/ConfidentialClientApplication.d.ts +58 -58
- package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
- package/dist/client/ConfidentialClientApplication.mjs +168 -165
- package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
- 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 +75 -80
- 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 +76 -81
- 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 +116 -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 +118 -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.cjs.map +1 -1
- package/dist/client/OnBehalfOfClient.d.ts +47 -47
- package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
- package/dist/client/OnBehalfOfClient.mjs +203 -203
- package/dist/client/OnBehalfOfClient.mjs.map +1 -1
- 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.cjs.map +1 -1
- package/dist/client/UsernamePasswordClient.d.ts +25 -25
- package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
- package/dist/client/UsernamePasswordClient.mjs +96 -96
- package/dist/client/UsernamePasswordClient.mjs.map +1 -1
- package/dist/config/Configuration.cjs +102 -86
- package/dist/config/Configuration.cjs.map +1 -1
- package/dist/config/Configuration.d.ts +126 -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 +38 -28
- package/dist/error/ManagedIdentityError.cjs.map +1 -1
- package/dist/error/ManagedIdentityError.d.ts +26 -21
- package/dist/error/ManagedIdentityError.d.ts.map +1 -1
- package/dist/error/ManagedIdentityError.mjs +39 -29
- package/dist/error/ManagedIdentityError.mjs.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.cjs +26 -15
- package/dist/error/ManagedIdentityErrorCodes.cjs.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.d.ts +18 -9
- package/dist/error/ManagedIdentityErrorCodes.d.ts.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.mjs +23 -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 +21 -21
- package/dist/index.d.ts +44 -44
- package/dist/index.d.ts.map +1 -1
- 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 +281 -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 +281 -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.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/ClientCredentialRequest.d.ts.map +1 -1
- 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 +142 -103
- package/dist/utils/Constants.cjs.map +1 -1
- package/dist/utils/Constants.d.ts +132 -106
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +134 -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 +24 -10
- package/src/client/ClientCredentialClient.ts +14 -6
- package/src/client/ConfidentialClientApplication.ts +10 -5
- package/src/client/ManagedIdentityApplication.ts +8 -16
- 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 +82 -11
- 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/client/OnBehalfOfClient.ts +18 -7
- package/src/client/UsernamePasswordClient.ts +16 -7
- package/src/config/Configuration.ts +50 -18
- package/src/config/ManagedIdentityRequestParameters.ts +1 -6
- package/src/error/ManagedIdentityError.ts +15 -4
- package/src/error/ManagedIdentityErrorCodes.ts +19 -1
- package/src/index.ts +1 -0
- package/src/network/HttpClient.ts +27 -39
- package/src/network/HttpClientWithRetries.ts +80 -0
- package/src/packageMetadata.ts +1 -1
- package/src/request/ClientCredentialRequest.ts +6 -3
- package/src/retry/IHttpRetryPolicy.ts +18 -0
- package/src/retry/LinearRetryPolicy.ts +71 -0
- package/src/utils/Constants.ts +47 -10
|
@@ -3,23 +3,20 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { INetworkModule, Logger
|
|
6
|
+
import { INetworkModule, Logger } from "@azure/msal-common";
|
|
7
7
|
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource";
|
|
8
8
|
import {
|
|
9
9
|
HttpMethod,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
APP_SERVICE_SECRET_HEADER_NAME,
|
|
11
|
+
API_VERSION_QUERY_PARAMETER_NAME,
|
|
12
|
+
RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
|
|
13
|
+
ManagedIdentityEnvironmentVariableNames,
|
|
14
|
+
ManagedIdentitySourceNames,
|
|
13
15
|
ManagedIdentityIdType,
|
|
14
|
-
SECRET_HEADER_NAME,
|
|
15
16
|
} from "../../utils/Constants";
|
|
16
17
|
import { CryptoProvider } from "../../crypto/CryptoProvider";
|
|
17
18
|
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters";
|
|
18
19
|
import { ManagedIdentityId } from "../../config/ManagedIdentityId";
|
|
19
|
-
import {
|
|
20
|
-
ManagedIdentityErrorCodes,
|
|
21
|
-
createManagedIdentityError,
|
|
22
|
-
} from "../../error/ManagedIdentityError";
|
|
23
20
|
import { NodeStorage } from "../../cache/NodeStorage";
|
|
24
21
|
|
|
25
22
|
// MSI Constants. Docs for MSI are available here https://docs.microsoft.com/azure/app-service/overview-managed-identity
|
|
@@ -29,21 +26,21 @@ const APP_SERVICE_MSI_API_VERSION: string = "2019-08-01";
|
|
|
29
26
|
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/AppServiceManagedIdentitySource.cs
|
|
30
27
|
*/
|
|
31
28
|
export class AppService extends BaseManagedIdentitySource {
|
|
32
|
-
private
|
|
33
|
-
private
|
|
29
|
+
private identityEndpoint: string;
|
|
30
|
+
private identityHeader: string;
|
|
34
31
|
|
|
35
32
|
constructor(
|
|
36
33
|
logger: Logger,
|
|
37
34
|
nodeStorage: NodeStorage,
|
|
38
35
|
networkClient: INetworkModule,
|
|
39
36
|
cryptoProvider: CryptoProvider,
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
identityEndpoint: string,
|
|
38
|
+
identityHeader: string
|
|
42
39
|
) {
|
|
43
40
|
super(logger, nodeStorage, networkClient, cryptoProvider);
|
|
44
41
|
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
42
|
+
this.identityEndpoint = identityEndpoint;
|
|
43
|
+
this.identityHeader = identityHeader;
|
|
47
44
|
}
|
|
48
45
|
|
|
49
46
|
public static tryCreate(
|
|
@@ -52,27 +49,43 @@ export class AppService extends BaseManagedIdentitySource {
|
|
|
52
49
|
networkClient: INetworkModule,
|
|
53
50
|
cryptoProvider: CryptoProvider
|
|
54
51
|
): AppService | null {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
const identityEndpoint: string | undefined =
|
|
53
|
+
process.env[
|
|
54
|
+
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT
|
|
55
|
+
];
|
|
56
|
+
const identityHeader: string | undefined =
|
|
57
|
+
process.env[
|
|
58
|
+
ManagedIdentityEnvironmentVariableNames.IDENTITY_HEADER
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
// if either of the identity endpoint or identity header variables are undefined, this MSI provider is unavailable.
|
|
62
|
+
if (!identityEndpoint || !identityHeader) {
|
|
63
|
+
logger.info(
|
|
64
|
+
`[Managed Identity] ${ManagedIdentitySourceNames.APP_SERVICE} managed identity is unavailable because one or both of the '${ManagedIdentityEnvironmentVariableNames.IDENTITY_HEADER}' and '${ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT}' environment variables are not defined.`
|
|
65
|
+
);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const validatedIdentityEndpoint: string =
|
|
70
|
+
AppService.getValidatedEnvVariableUrlString(
|
|
71
|
+
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT,
|
|
72
|
+
identityEndpoint,
|
|
73
|
+
ManagedIdentitySourceNames.APP_SERVICE,
|
|
74
|
+
logger
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
logger.info(
|
|
78
|
+
`[Managed Identity] Environment variables validation passed for ${ManagedIdentitySourceNames.APP_SERVICE} managed identity. Endpoint URI: ${validatedIdentityEndpoint}. Creating ${ManagedIdentitySourceNames.APP_SERVICE} managed identity.`
|
|
64
79
|
);
|
|
65
80
|
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
)
|
|
75
|
-
: null;
|
|
81
|
+
return new AppService(
|
|
82
|
+
logger,
|
|
83
|
+
nodeStorage,
|
|
84
|
+
networkClient,
|
|
85
|
+
cryptoProvider,
|
|
86
|
+
identityEndpoint,
|
|
87
|
+
identityHeader
|
|
88
|
+
);
|
|
76
89
|
}
|
|
77
90
|
|
|
78
91
|
public createRequest(
|
|
@@ -80,72 +93,30 @@ export class AppService extends BaseManagedIdentitySource {
|
|
|
80
93
|
managedIdentityId: ManagedIdentityId
|
|
81
94
|
): ManagedIdentityRequestParameters {
|
|
82
95
|
const request: ManagedIdentityRequestParameters =
|
|
83
|
-
new ManagedIdentityRequestParameters(
|
|
96
|
+
new ManagedIdentityRequestParameters(
|
|
97
|
+
HttpMethod.GET,
|
|
98
|
+
this.identityEndpoint
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
request.headers[APP_SERVICE_SECRET_HEADER_NAME] = this.identityHeader;
|
|
102
|
+
|
|
103
|
+
request.queryParameters[API_VERSION_QUERY_PARAMETER_NAME] =
|
|
104
|
+
APP_SERVICE_MSI_API_VERSION;
|
|
105
|
+
request.queryParameters[RESOURCE_BODY_OR_QUERY_PARAMETER_NAME] =
|
|
106
|
+
resource;
|
|
107
|
+
|
|
108
|
+
if (
|
|
109
|
+
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
|
110
|
+
) {
|
|
111
|
+
request.queryParameters[
|
|
112
|
+
this.getManagedIdentityUserAssignedIdQueryParameterKey(
|
|
113
|
+
managedIdentityId.idType
|
|
114
|
+
)
|
|
115
|
+
] = managedIdentityId.id;
|
|
116
|
+
}
|
|
84
117
|
|
|
85
|
-
request.headers[SECRET_HEADER_NAME] = this.secret;
|
|
86
|
-
request.queryParameters["api-version"] = APP_SERVICE_MSI_API_VERSION;
|
|
87
|
-
request.queryParameters["resource"] = resource;
|
|
88
118
|
// bodyParameters calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity
|
|
89
119
|
|
|
90
|
-
switch (managedIdentityId.idType) {
|
|
91
|
-
case ManagedIdentityIdType.USER_ASSIGNED_CLIENT_ID:
|
|
92
|
-
this.logger.info(
|
|
93
|
-
"[Managed Identity] Adding user assigned client id to the request."
|
|
94
|
-
);
|
|
95
|
-
request.queryParameters[MANAGED_IDENTITY_CLIENT_ID] =
|
|
96
|
-
managedIdentityId.id;
|
|
97
|
-
break;
|
|
98
|
-
|
|
99
|
-
case ManagedIdentityIdType.USER_ASSIGNED_RESOURCE_ID:
|
|
100
|
-
this.logger.info(
|
|
101
|
-
"[Managed Identity] Adding user assigned resource id to the request."
|
|
102
|
-
);
|
|
103
|
-
request.queryParameters[MANAGED_IDENTITY_RESOURCE_ID] =
|
|
104
|
-
managedIdentityId.id;
|
|
105
|
-
break;
|
|
106
|
-
|
|
107
|
-
case ManagedIdentityIdType.USER_ASSIGNED_OBJECT_ID:
|
|
108
|
-
this.logger.info(
|
|
109
|
-
"[Managed Identity] Adding user assigned object id to the request."
|
|
110
|
-
);
|
|
111
|
-
request.queryParameters[MANAGED_IDENTITY_OBJECT_ID] =
|
|
112
|
-
managedIdentityId.id;
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
120
|
return request;
|
|
117
121
|
}
|
|
118
122
|
}
|
|
119
|
-
|
|
120
|
-
const validateEnvironmentVariables = (
|
|
121
|
-
endpoint: string | undefined,
|
|
122
|
-
secret: string | undefined,
|
|
123
|
-
logger: Logger
|
|
124
|
-
): [boolean, string | undefined] => {
|
|
125
|
-
let endpointUrlString: string | undefined;
|
|
126
|
-
|
|
127
|
-
// if either of the endpoint or secret environment variables are undefined, this MSI provider is unavailable.
|
|
128
|
-
if (!endpoint || !secret) {
|
|
129
|
-
logger.info(
|
|
130
|
-
"[Managed Identity] App Service managed identity is unavailable because one or both of the 'IDENTITY_HEADER' and 'IDENTITY_ENDPOINT' environment variables are missing."
|
|
131
|
-
);
|
|
132
|
-
return [false, endpointUrlString];
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
try {
|
|
136
|
-
endpointUrlString = new UrlString(endpoint).urlString;
|
|
137
|
-
} catch (error) {
|
|
138
|
-
logger.info(
|
|
139
|
-
"[Managed Identity] App Service managed identity is unavailable because the 'IDENTITY_ENDPOINT' environment variable is malformed."
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
throw createManagedIdentityError(
|
|
143
|
-
ManagedIdentityErrorCodes.urlParseError
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
logger.info(
|
|
148
|
-
`[Managed Identity] Environment variables validation passed for App Service managed identity. Endpoint URI: ${endpointUrlString}. Creating App Service managed identity.`
|
|
149
|
-
);
|
|
150
|
-
return [true, endpointUrlString];
|
|
151
|
-
};
|
|
@@ -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;
|
|
@@ -65,28 +81,31 @@ export abstract class BaseManagedIdentitySource {
|
|
|
65
81
|
public getServerTokenResponse(
|
|
66
82
|
response: NetworkResponse<ManagedIdentityTokenResponse>
|
|
67
83
|
): ServerAuthorizationTokenResponse {
|
|
84
|
+
let refreshIn, expiresIn: number | undefined;
|
|
85
|
+
if (response.body.expires_on) {
|
|
86
|
+
expiresIn = response.body.expires_on - TimeUtils.nowSeconds();
|
|
87
|
+
|
|
88
|
+
// compute refresh_in as 1/2 of expires_in, but only if expires_in > 2h
|
|
89
|
+
if (expiresIn > 2 * 3600) {
|
|
90
|
+
refreshIn = expiresIn / 2;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
68
94
|
const serverTokenResponse: ServerAuthorizationTokenResponse = {
|
|
69
95
|
status: response.status,
|
|
70
96
|
|
|
71
97
|
// success
|
|
72
98
|
access_token: response.body.access_token,
|
|
73
|
-
expires_in:
|
|
99
|
+
expires_in: expiresIn,
|
|
74
100
|
scope: response.body.resource,
|
|
75
101
|
token_type: response.body.token_type,
|
|
102
|
+
refresh_in: refreshIn,
|
|
76
103
|
|
|
77
104
|
// error
|
|
78
105
|
error: response.body.message,
|
|
79
106
|
correlation_id: response.body.correlationId,
|
|
80
107
|
};
|
|
81
108
|
|
|
82
|
-
// compute refresh_in as 1/2 of expires_in, but only if expires_in > 2h
|
|
83
|
-
if (
|
|
84
|
-
serverTokenResponse.expires_in &&
|
|
85
|
-
serverTokenResponse.expires_in > 2 * 3600
|
|
86
|
-
) {
|
|
87
|
-
serverTokenResponse.refresh_in = serverTokenResponse.expires_in / 2;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
109
|
return serverTokenResponse;
|
|
91
110
|
}
|
|
92
111
|
|
|
@@ -104,8 +123,10 @@ export abstract class BaseManagedIdentitySource {
|
|
|
104
123
|
|
|
105
124
|
const headers: Record<string, string> = networkRequest.headers;
|
|
106
125
|
headers[HeaderNames.CONTENT_TYPE] = Constants.URL_FORM_CONTENT_TYPE;
|
|
126
|
+
|
|
107
127
|
const networkRequestOptions: NetworkRequestOptions = { headers };
|
|
108
|
-
|
|
128
|
+
|
|
129
|
+
if (Object.keys(networkRequest.bodyParameters).length) {
|
|
109
130
|
networkRequestOptions.body =
|
|
110
131
|
networkRequest.computeParametersBodyString();
|
|
111
132
|
}
|
|
@@ -166,4 +187,54 @@ export abstract class BaseManagedIdentitySource {
|
|
|
166
187
|
managedIdentityRequest
|
|
167
188
|
);
|
|
168
189
|
}
|
|
190
|
+
|
|
191
|
+
public getManagedIdentityUserAssignedIdQueryParameterKey(
|
|
192
|
+
managedIdentityIdType: ManagedIdentityIdType
|
|
193
|
+
): string {
|
|
194
|
+
switch (managedIdentityIdType) {
|
|
195
|
+
case ManagedIdentityIdType.USER_ASSIGNED_CLIENT_ID:
|
|
196
|
+
this.logger.info(
|
|
197
|
+
"[Managed Identity] Adding user assigned client id to the request."
|
|
198
|
+
);
|
|
199
|
+
return ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_CLIENT_ID;
|
|
200
|
+
|
|
201
|
+
case ManagedIdentityIdType.USER_ASSIGNED_RESOURCE_ID:
|
|
202
|
+
this.logger.info(
|
|
203
|
+
"[Managed Identity] Adding user assigned resource id to the request."
|
|
204
|
+
);
|
|
205
|
+
return ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_RESOURCE_ID;
|
|
206
|
+
|
|
207
|
+
case ManagedIdentityIdType.USER_ASSIGNED_OBJECT_ID:
|
|
208
|
+
this.logger.info(
|
|
209
|
+
"[Managed Identity] Adding user assigned object id to the request."
|
|
210
|
+
);
|
|
211
|
+
return ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_OBJECT_ID;
|
|
212
|
+
default:
|
|
213
|
+
throw createManagedIdentityError(
|
|
214
|
+
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
public static getValidatedEnvVariableUrlString = (
|
|
220
|
+
envVariableStringName: string,
|
|
221
|
+
envVariable: string,
|
|
222
|
+
sourceName: string,
|
|
223
|
+
logger: Logger
|
|
224
|
+
): string => {
|
|
225
|
+
try {
|
|
226
|
+
return new UrlString(envVariable).urlString;
|
|
227
|
+
} catch (error) {
|
|
228
|
+
logger.info(
|
|
229
|
+
`[Managed Identity] ${sourceName} managed identity is unavailable because the '${envVariableStringName}' environment variable is malformed.`
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
throw createManagedIdentityError(
|
|
233
|
+
ManagedIdentityErrorCodes
|
|
234
|
+
.MsiEnvironmentVariableUrlMalformedErrorCodes[
|
|
235
|
+
envVariableStringName
|
|
236
|
+
]
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
169
240
|
}
|
|
@@ -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
|
}
|