Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I give an App Registration permission to access Azure KeyVault?

I have a python script running on an Ubuntu Linux virtual machine that needs to access a KeyVault in Azure. If have configured the following environment variables based on an "App Registration".

AZURE_CLIENT_ID=<Client ID from App Registration>
AZURE_TENANT_ID=<Tenent ID from App Registration>
AZURE_CLIENT_SECRET=<SECRET Created in App Registration>

When I try accessing the KeyVault I get an access denied error.

Code: Forbidden
Message: The user, group or application 'appid=<APP_ID>;oid= 
<GUID_VALUE>;iss=https://sts.windows.net/<GUID_VALUE>/' does not have secrets get permission 
on key vault '<KEY_VAULT_NAME>;location=westus'. For help resolving this issue, please see 
https://go.microsoft.com/fwlink/?linkid=2125287
Inner error: {
    "code": "AccessDenied"
}

I assume I am getting this, because there is no Role Assignment in the KeyVault, however I may be wrong.

When I try adding a new Role Assignment to the KeyVault, there is no option under "Assign access to" for "App Registration". I tried both "User, Group or Service Principal" and "User Assigned Managed Identity", but it I always get the error "No users, groups, or service principals found.".

enter image description here

What am I missing here?

like image 275
Dave Avatar asked Oct 20 '25 10:10

Dave


1 Answers

What am I missing here?

There are a few issues here:

  1. You're trying to assign an RBAC role to an App Registration. What you need to do is assign an RBAC role to the Service Principal. To get the Service Principal Id, you would need to go to Enterprise Applications section in Azure AD and find the Id of your Service Principal (Object ID).

  2. Assigning Reader RBAC role will not do the trick as this role is for managing the Key Vault itself and not the data inside it. There are two ways to solve this:

  • Use Access Policies: You can define appropriate access policies in your Azure Key Vault to give access to keys, secrets and certificates to your Service Principal.
  • Use Data RBAC Roles: Instead of using Management RBAC roles (like Reader, Contributor etc.), you will need to use RBAC roles for managing data inside the Key Vault.

Please see this link for more details: https://learn.microsoft.com/en-us/azure/key-vault/general/assign-access-policy-portal.

like image 192
Gaurav Mantri Avatar answered Oct 22 '25 00:10

Gaurav Mantri