After many days of banging my head against a wall, reading countless forum posts, and possibly every document about Azure Key Vaults, I finally resolved my issue.
Problem:
I don't know if this is even documented anywhere because I did not find the answer anywhere online. I found it by sheer luck and determination, trying every tiny idea that I could come up with. It turns out my issue was the way the Key Vault was created. When you are creating a Key Vault resource, during the "Networking" step, if you choose to start with the "Private endpoint" option, it will disable public network access, even if you add a public IP or virtual network to the firewall, and even if you set the firewall to allow access from "All networks". It will not let anything other than the private endpoint through.
Solution:
The solution was to create the Key Vault with initial access as either "All networks" or "Selected networks". Then setting my IP address as the only IP address allowed past the firewall worked properly and I was able to authenticate through Visual Studio and through the interactive browser using DefaultAzureCredential(true)
. I was also able to create a private endpoint for the new vault that I can properly use from the VNet but it does not disable my firewall settings so I am still able to access the vault from my local IP address (and not from any other IP addresses).
Main Points:
If you want to be able to authenticate to your Key Vault from ONLY your IP address and a private endpoint (for development and production environments, respectively) then:
- Make sure you first create the vault without a private endpoint otherwise it will disable all other options with no way around it. You can add a private endpoint after it is created and use both your IP and the endpoint properly.
- Make sure you have the correct access policies to the vault set on your account user for local authentication. Either through the permissions in "Vault access policy" or through the IAM roles with "Azure role-based access control".