Skip to content

Commit 7d17705

Browse files
Enhancing the logging within the ManagedIdentityClient class to provide more detailed information about the detection of managed identity sources. (#5098)
logging Co-authored-by: Gladwin Johnson <[email protected]>
1 parent c33d5f5 commit 7d17705

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/client/Microsoft.Identity.Client/ManagedIdentity/ManagedIdentityClient.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,35 @@ internal static ManagedIdentitySource GetManagedIdentitySource(ILoggerAdapter lo
6060
string msiEndpoint = EnvironmentVariables.MsiEndpoint;
6161
string msiSecretMachineLearning = EnvironmentVariables.MsiSecret;
6262
string imdsEndpoint = EnvironmentVariables.ImdsEndpoint;
63-
string podIdentityEndpoint = EnvironmentVariables.PodIdentityEndpoint;
63+
64+
logger?.Info("[Managed Identity] Detecting managed identity source...");
6465

6566
if (!string.IsNullOrEmpty(identityEndpoint) && !string.IsNullOrEmpty(identityHeader))
6667
{
6768
if (!string.IsNullOrEmpty(identityServerThumbprint))
6869
{
70+
logger?.Info("[Managed Identity] Service Fabric detected.");
6971
return ManagedIdentitySource.ServiceFabric;
7072
}
7173
else
7274
{
75+
logger?.Info("[Managed Identity] App Service detected.");
7376
return ManagedIdentitySource.AppService;
7477
}
7578
}
7679
else if (!string.IsNullOrEmpty(msiSecretMachineLearning) && !string.IsNullOrEmpty(msiEndpoint))
7780
{
81+
logger?.Info("[Managed Identity] Machine Learning detected.");
7882
return ManagedIdentitySource.MachineLearning;
7983
}
8084
else if (!string.IsNullOrEmpty(msiEndpoint))
8185
{
86+
logger?.Info("[Managed Identity] Cloud Shell detected.");
8287
return ManagedIdentitySource.CloudShell;
8388
}
8489
else if (ValidateAzureArcEnvironment(identityEndpoint, imdsEndpoint, logger))
8590
{
91+
logger?.Info("[Managed Identity] Azure Arc detected.");
8692
return ManagedIdentitySource.AzureArc;
8793
}
8894
else
@@ -94,6 +100,9 @@ internal static ManagedIdentitySource GetManagedIdentitySource(ILoggerAdapter lo
94100
// Method to return true if a file exists and is not empty to validate the Azure arc environment.
95101
private static bool ValidateAzureArcEnvironment(string identityEndpoint, string imdsEndpoint, ILoggerAdapter logger)
96102
{
103+
logger?.Info("[Managed Identity] Checked for sources: Service Fabric, App Service, Machine Learning, and Cloud Shell. " +
104+
"They are not available.");
105+
97106
if (!string.IsNullOrEmpty(identityEndpoint) && !string.IsNullOrEmpty(imdsEndpoint))
98107
{
99108
logger?.Verbose(() => "[Managed Identity] Azure Arc managed identity is available through environment variables.");
@@ -110,10 +119,6 @@ private static bool ValidateAzureArcEnvironment(string identityEndpoint, string
110119
logger?.Verbose(() => "[Managed Identity] Azure Arc managed identity is available through file detection.");
111120
return true;
112121
}
113-
else
114-
{
115-
logger?.Warning("[Managed Identity] Azure Arc managed identity cannot be configured on a platform other than Windows and Linux.");
116-
}
117122

118123
logger?.Verbose(() => "[Managed Identity] Azure Arc managed identity is not available.");
119124
return false;

0 commit comments

Comments
 (0)