-
My bicep template makes use of
One 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 Is this possible? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 17 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 |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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)" |
Beta Was this translation helpful? Give feedback.
-
@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! |
Beta Was this translation helpful? Give feedback.
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
identity
property of a deployment script can only specify a user-assigned managed service identity, however, so even if you had the ID of the user executing the deployment, you wouldn't be able to use that in theidentity
property of the deploymentScripts resource. You could always omit theidentity
property and then log in within the script itself usingConnect-AzAccount
(for a powershell script) oraz login
(for a CLI script), passing login credentials to the script as secure environment variables. There's some mo…