Repository navigation
How to get the principal id of the current principal executing the azure bicep deployment? #9969
Replies: 5 comments 21 replies
|
There's no function to get the principal ID of the user executing the deployment (though it is planned). For your specific use case, though, such a function wouldn't help. The |
|
Just adding another case for where I wanted to do this. When the bicep deployment runs, it creates a keyVault. The KeyVault uses access policies. I want it to create an access policy to give its own principal (object id) access to secrets. |
|
The workaround I just used was to get it from the Azure CLI and pass it in as a let principalId = az rest --method GET --uri https://graph.microsoft.com/v1.0/me | from json | get id
az deployment group create -g mygroup -f my.bicep -p $"principalId=($principalId)" |
|
Jonny Eskew (@jeskew), is there any update on when the "function to get the principal ID of the user executing the deployment" is planned? My use case is that I write a lot of templates that deploy database or data services and I want my Bicep templates to have local keys disabled by default. In a perfect world, I could call a function in the Bicep template to get the metadata for the executing identity (human, managed, or etc.) and then assign the least permissive roles using RBAC. Today, I have two workarounds:
These work for now, but this just adds complexity when all I really want is for someone to deploy a Bicep template as a one-liner and not need the prerequisite steps. Thanks! |
|
You can now get the current deployment principal using the new |
Uh oh!
There was an error while loading. Please reload this page.
My bicep template makes use of
deployment scriptresourceOne of the properties you have to supply is an identity.
At the moment, in my bicep deployment itself I have to create this identity, so I can then assign it to the deployment script.
However I don't think this should be necessary. Given my bicep deployment is executing as an authenticated az identity, I am wondering how get access to the current principal executing the deployment so I can assign that identity and re-use it. Similar to how you can use
subscription()to get hold of the current subscription info for example.Is this possible?
All reactions