12
12
import com .azure .core .util .logging .ClientLogger ;
13
13
import com .azure .identity .implementation .IdentityClientBuilder ;
14
14
import com .azure .identity .implementation .IdentityClientOptions ;
15
- import com .azure .identity .implementation .ManagedIdentityParameters ;
16
- import com .azure .identity .implementation .ManagedIdentityType ;
17
15
import com .azure .identity .implementation .util .LoggingUtil ;
18
16
import com .microsoft .aad .msal4j .ManagedIdentityApplication ;
19
17
import com .microsoft .aad .msal4j .ManagedIdentitySourceType ;
@@ -120,12 +118,7 @@ public final class ManagedIdentityCredential implements TokenCredential {
120
118
* Choose credential based on available environment variables in this order:
121
119
*
122
120
* Azure Arc: IDENTITY_ENDPOINT, IMDS_ENDPOINT
123
- * Service Fabric: IDENTITY_ENDPOINT, IDENTITY_HEADER, IDENTITY_SERVER_THUMBPRINT
124
- * App Service 2019-08-01: IDENTITY_ENDPOINT, IDENTITY_HEADER (MSI_ENDPOINT and MSI_SECRET will also be set.)
125
- * App Service 2017-09-01: MSI_ENDPOINT, MSI_SECRET
126
- * Cloud Shell: MSI_ENDPOINT
127
- * Pod Identity V2 (AksExchangeToken): AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_FEDERATED_TOKEN_FILE
128
- * IMDS/Pod Identity V1: No variables set.
121
+ * Other scenarios: Delegated to MSAL.
129
122
*/
130
123
if (configuration .contains (Configuration .PROPERTY_AZURE_TENANT_ID )
131
124
&& configuration .get (AZURE_FEDERATED_TOKEN_FILE ) != null ) {
@@ -136,51 +129,13 @@ public final class ManagedIdentityCredential implements TokenCredential {
136
129
clientBuilder .clientAssertionPath (configuration .get (AZURE_FEDERATED_TOKEN_FILE ));
137
130
clientBuilder .clientAssertionTimeout (Duration .ofMinutes (5 ));
138
131
managedIdentityServiceCredential = new AksExchangeTokenCredential (clientIdentifier ,
139
- clientBuilder
140
- .identityClientOptions (
141
- updateIdentityClientOptions (ManagedIdentityType .AKS , identityClientOptions , configuration ))
142
- .build ());
132
+ clientBuilder .identityClientOptions (identityClientOptions ).build ());
143
133
} else {
144
- identityClientOptions .setManagedIdentityType (getManagedIdentityEnv (configuration ));
145
134
managedIdentityServiceCredential = new ManagedIdentityMsalCredential (clientId , clientBuilder .build ());
146
135
}
147
136
LoggingUtil .logAvailableEnvironmentVariables (LOGGER , configuration );
148
137
}
149
138
150
- private IdentityClientOptions updateIdentityClientOptions (ManagedIdentityType managedIdentityType ,
151
- IdentityClientOptions clientOptions , Configuration configuration ) {
152
- switch (managedIdentityType ) {
153
- case APP_SERVICE :
154
- return clientOptions .setManagedIdentityType (ManagedIdentityType .APP_SERVICE )
155
- .setManagedIdentityParameters (new ManagedIdentityParameters ()
156
- .setMsiEndpoint (configuration .get (Configuration .PROPERTY_MSI_ENDPOINT ))
157
- .setMsiSecret (configuration .get (Configuration .PROPERTY_MSI_SECRET ))
158
- .setIdentityEndpoint (configuration .get (Configuration .PROPERTY_IDENTITY_ENDPOINT ))
159
- .setIdentityHeader (configuration .get (Configuration .PROPERTY_IDENTITY_HEADER )));
160
-
161
- case SERVICE_FABRIC :
162
- return clientOptions .setManagedIdentityType (ManagedIdentityType .SERVICE_FABRIC )
163
- .setManagedIdentityParameters (new ManagedIdentityParameters ()
164
- .setIdentityServerThumbprint (configuration .get (PROPERTY_IDENTITY_SERVER_THUMBPRINT ))
165
- .setIdentityEndpoint (configuration .get (Configuration .PROPERTY_IDENTITY_ENDPOINT ))
166
- .setIdentityHeader (configuration .get (Configuration .PROPERTY_IDENTITY_HEADER )));
167
-
168
- case ARC :
169
- return clientOptions .setManagedIdentityType (ManagedIdentityType .ARC )
170
- .setManagedIdentityParameters (new ManagedIdentityParameters ()
171
- .setIdentityEndpoint (configuration .get (Configuration .PROPERTY_IDENTITY_ENDPOINT )));
172
-
173
- case VM :
174
- return clientOptions .setManagedIdentityType (ManagedIdentityType .VM );
175
-
176
- case AKS :
177
- return clientOptions .setManagedIdentityType (ManagedIdentityType .AKS );
178
-
179
- default :
180
- return clientOptions ;
181
- }
182
- }
183
-
184
139
/**
185
140
* Gets the client ID of user assigned or system assigned identity.
186
141
* @return the client ID of user assigned or system assigned identity.
@@ -223,29 +178,6 @@ public Mono<AccessToken> getToken(TokenRequestContext request) {
223
178
.doOnError (error -> LoggingUtil .logTokenError (LOGGER , identityClientOptions , request , error ));
224
179
}
225
180
226
- ManagedIdentityType getManagedIdentityEnv (Configuration configuration ) {
227
- if (configuration .contains (Configuration .PROPERTY_MSI_ENDPOINT )) {
228
- return ManagedIdentityType .APP_SERVICE ;
229
- } else if (configuration .contains (Configuration .PROPERTY_IDENTITY_ENDPOINT )) {
230
- if (configuration .contains (Configuration .PROPERTY_IDENTITY_HEADER )) {
231
- if (configuration .get (PROPERTY_IDENTITY_SERVER_THUMBPRINT ) != null ) {
232
- return ManagedIdentityType .SERVICE_FABRIC ;
233
- } else {
234
- return ManagedIdentityType .APP_SERVICE ;
235
- }
236
- } else if (configuration .get (PROPERTY_IMDS_ENDPOINT ) != null ) {
237
- return ManagedIdentityType .ARC ;
238
- } else {
239
- return ManagedIdentityType .VM ;
240
- }
241
- } else if (configuration .contains (Configuration .PROPERTY_AZURE_TENANT_ID )
242
- && configuration .get (AZURE_FEDERATED_TOKEN_FILE ) != null ) {
243
- return ManagedIdentityType .AKS ;
244
- } else {
245
- return ManagedIdentityType .VM ;
246
- }
247
- }
248
-
249
181
String fetchManagedIdentityId (String clientId , String resourceId , String objectId ) {
250
182
if (clientId != null ) {
251
183
return clientId ;
0 commit comments