Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ internal static TokenCredential CreateCredential(IConfiguration configuration)
return new WorkloadIdentityCredential(workloadIdentityOptions);
}

throw new ArgumentException("For workload identity, 'tenantId', 'clientId', and 'tokenFilePath' must be specified via environment variables or the configuration.");
throw new ArgumentException("For workload identity, 'tenantId', 'clientId', and 'tokenFilePath' must be specified via the configuration.");
}

if (string.Equals(credentialType, "managedidentityasfederatedidentity", StringComparison.OrdinalIgnoreCase))
Expand All @@ -189,7 +189,7 @@ internal static TokenCredential CreateCredential(IConfiguration configuration)
string.IsNullOrWhiteSpace(clientId) ||
string.IsNullOrWhiteSpace(azureCloud))
{
throw new ArgumentException("For managed identity as a federated identity credential, 'tenantId', 'clientId', 'azureCloud', and one of ['managedIdentityClientId', 'resourceId', 'objectId'] must be specified via environment variables or the configuration.");
throw new ArgumentException("For managed identity as a federated identity credential, 'tenantId', 'clientId', 'azureCloud', and one of ['managedIdentityClientId', 'managedIdentityResourceId', 'managedIdentityObjectId'] must be specified via the configuration.");
}

if (!string.IsNullOrWhiteSpace(resourceId))
Expand Down Expand Up @@ -413,17 +413,20 @@ private static void AssertSingleManagedIdentityIdentifier(string clientId, strin
idCount += string.IsNullOrWhiteSpace(objectId) ? 0 : 1;

var validIdentifiers = isFederated
? "'clientId', 'managedIdentityClientId', 'managedIdentityResourceId', or 'managedIdentityObjectId'"
: "'managedIdentityClientId', 'managedIdentityResourceId', or 'managedIdentityObjectId'";
? "'managedIdentityClientId', 'managedIdentityResourceId', or 'managedIdentityObjectId'"
: "'clientId', 'managedIdentityClientId', 'managedIdentityResourceId', or 'managedIdentityObjectId'";
Comment on lines +416 to +417
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic was correct before. If federated, clientId is required. The underlying ClientAssertionCredential will need it.

Suggested change
? "'managedIdentityClientId', 'managedIdentityResourceId', or 'managedIdentityObjectId'"
: "'clientId', 'managedIdentityClientId', 'managedIdentityResourceId', or 'managedIdentityObjectId'";
? "'clientId', 'managedIdentityClientId', 'managedIdentityResourceId', or 'managedIdentityObjectId'"
: "'managedIdentityClientId', 'managedIdentityResourceId', or 'managedIdentityObjectId'";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing L426. The message ends up being:

Managed Identity (non-fed)
I need a 'clientId', 'managedIdentityClientId', 'managedIdentityResourceId', or 'managedIdentityObjectId' to use.

Federated Managed Identity

I need a clientId AND "'managedIdentityClientId', 'managedIdentityResourceId', or 'managedIdentityObjectId' to use.


if (idCount > 1)
{
throw new ArgumentException($"Only one of [{validIdentifiers}] can be specified for managed identity.");
}

if (isFederated && idCount < 1)
if (idCount < 1)
{
throw new ArgumentException($"At least one of [{validIdentifiers}] must be specified for managed identity.");
var clientIdPart = isFederated ? "A clientId and exactly one" : "Exactly one";
var federatedPart = isFederated ? "federated " : " ";

throw new ArgumentException($"{clientIdPart} of [{validIdentifiers}] must be specified for {federatedPart}managed identity.");
}
}

Expand Down
Loading