question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Unable to set tenant id when creating a key vault resource

See original GitHub issue

Describe the bug When creating an Azure KeyVault in an empty resource group, an Unrecognized Guid format. exception is thrown. After some debugging and investigation I found that the TenantId of the vault object is not set.

Exception or Stack Trace

System.FormatException
  HResult=0x80131537
  Message=Unrecognized Guid format.
  Source=System.Private.CoreLib
  StackTrace:
  System.Guid.GuidResult.SetFailure(bool, string)
  System.Guid.TryParseGuid(System.ReadOnlySpan<char>, ref System.Guid.GuidResult)
  System.Guid.Parse(string)
  Microsoft.Azure.Management.KeyVault.Fluent.VaultsImpl.WrapModel(string)
  Microsoft.Azure.Management.KeyVault.Fluent.VaultsImpl.Define(string)
  Microsoft.Azure.Management.KeyVault.Fluent.VaultsImpl.Microsoft.Azure.Management.ResourceManager.Fluent.Core.CollectionActions.ISupportsCreating<Microsoft.Azure.Management.KeyVault.Fluent.Vault.Definition.IBlank>.Define(string)
  ...
  [Call Stack Truncated]

To Reproduce I run this code in an .NET Core 3.1 console application inside Visual Studio 16.4.1

Code Snippet

AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
string accessToken = await azureServiceTokenProvider.GetAccessTokenAsync("https://management.core.windows.net/", "<MyTenantId>");
TokenCredentials tokenCredential = new TokenCredentials(accessToken);
AzureCredentials azureCredential = new AzureCredentials(tokenCredential, tokenCredential, string.Empty, AzureEnvironment.AzureGlobalCloud);
IAzure azure = Azure.Authenticate(azureCredential).WithSubscription("<mySubscriptionId>");

await azure.Vaults.Define("MyVaultName")
  .WithRegion(Region.EuropeWest)
  .WithExistingResourceGroup("MyResourceGroupName")
  .WithEmptyAccessPolicy()
  .CreateAsync();

Expected behavior I would expect that the tenant ID is inferred from the current subscription context of the IAzure object or that it can be set with some .Define() properties or actions.

Screenshots – none –

Setup (please complete the following information):

  • OS: Windows 10 1809 on my local development machine
  • IDE : Visual Studio 2019 16.4.1
  • Version of the Library
    • NuGet package Microsoft.Azure.Management.Fluent 1.29.0
    • NuGet package Microsoft.Azure.Services.AppAuthentication 1.3.1

Additional context My Azure AD account assigned with Visual Studio (Azure Service Authentication) is owner of the target subscription. This account is owner of subscriptions for multiple tenants, that is the reason why I need to specify the tenant id within the GetAccessTokenAsync method.

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
xseeseeseecommented, May 26, 2020

@Andreas-Lehmann @ArnimSchinz Sorry for late response. It looks you didn’t set the tenant ID correctly. AzureCredentials azureCredential = new AzureCredentials(tokenCredential, tokenCredential, string.Empty, AzureEnvironment.AzureGlobalCloud);

Please refer this. I think you can replace the string.Empty with your tenant ID.

And also, you may check AUTH.md and AzureCredentialsFactory if any existing method could help you build credential more easily. Thanks.

0reactions
Andreas-Lehmanncommented, May 26, 2020

Great seems to work that way. Thanks for your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting Azure Key Vault access policy issues
Recommended troubleshooting Steps for following error types​​ Check if you've delete access permission to key vault: See Assign an access policy ...
Read more >
Unable to generate and import the certificate in azure key ...
Hi, I am unable to generate or import the certificate in azure key vault. I am getting the error as attached image.
Read more >
Using Azure KeyVault, cannot find object in Azure Active ...
The tenant ID refers to the unique identifier of the Azure AD directory. Every Azure subscription is associated with a directory (or "tenant"). ......
Read more >
Unable to create a key in a keyvault #6546
I am trying to build a hashicorp vault seal/unseal solution. in the solution i have a vm with managed identity that should have...
Read more >
Impossible to create keys in Azure Key Vault #8421
I have tried to do the key creation on an existing key vault as well (not created by the script but with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found