Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Reference an Azure AD User by UPN #645

Open
floriankoch opened this issue Oct 13, 2020 · 27 comments
Open

How to Reference an Azure AD User by UPN #645

floriankoch opened this issue Oct 13, 2020 · 27 comments
Labels
intermediate language Related to the intermediate language revisit

Comments

@floriankoch
Copy link

Hi,

is there a way to reference a Azure Ad User by UPN als object ID?
For example in KeyVault access Policies

Regards

@ghost ghost added the Needs: Triage 🔍 label Oct 13, 2020
@alex-frankel
Copy link
Collaborator

Azure AD objects are not represented in ARM today, so there is no way to do this in bicep or ARM templates directly. So the goal is to input the principal name and return the entire AD object? Basically mimicking what this CLI command does?

az ad user show --id principal@domain.com

@floriankoch
Copy link
Author

The use Case is e.g

resource keyvault 'Microsoft.KeyVault/vaults@2019-09-01' = {    
  name: vaultName       
  location: location 
  properties: {
    tenantId: tenant
    sku: {
      family: 'A'
      name: sku
    }
   
    accessPolicies:  [
  {
    tenantId: tenant
    objectId: oid
    permissions: {
      secrets: [
        'Get'
        'List'
        'Set'
        'Delete'
        'Recover'
        'Backup'
        'Restore'
      ]
    }
  }

to lookup the User or Group oid from the Azure AD

az ad user show --id principal@domain.com --query objectId

@alex-frankel
Copy link
Collaborator

alex-frankel commented Oct 14, 2020

sorry for not following this one, but I am still a bit confused. What is the definition of oid in this case?

I was thinking you could have something like this:

resource keyvault 'Microsoft.KeyVault/vaults@2019-09-01' = {    
  name: vaultName       
  location: location 
  properties: {
    tenantId: tenant
    sku: {
      family: 'A'
      name: sku
    }
   
    accessPolicies:  [
  {
    tenantId: tenant
    objectId: aadLookup('principal@domain.com').objectId
    permissions: {
      secrets: [
        'Get'
        'List'
        'Set'
        'Delete'
        'Recover'
        'Backup'
        'Restore'
      ]
    }
  }

@alex-frankel alex-frankel added question Further information is requested intermediate language Related to the intermediate language and removed Needs: Triage 🔍 labels Oct 14, 2020
@alex-frankel alex-frankel changed the title [Question] How to Reference an Azure AD User by UPN How to Reference an Azure AD User by UPN Oct 14, 2020
@floriankoch
Copy link
Author

floriankoch commented Oct 14, 2020

You are right with your example, i was not clear enough sorry

Another usecase would be a group lookup

@alex-frankel
Copy link
Collaborator

np! thanks for confirming. I think we agree this should be done, just a matter of getting it scheduled.

@alex-frankel alex-frankel removed the question Further information is requested label Oct 14, 2020
@alex-frankel alex-frankel added this to the Committed Backlog milestone Oct 14, 2020
@floriankoch
Copy link
Author

@alex-frankel Thanks, can we use this issue for both , upn and group lookup?

@slavizh
Copy link
Contributor

slavizh commented Oct 15, 2020

Matter of getting scheduled? I have been asking for this for more than two years and it was never scheduled :P

@alex-frankel
Copy link
Collaborator

@floariankoch - yes, it should work for both when it gets implemented. @slavizh better late than never :)

@slavizh
Copy link
Contributor

slavizh commented Oct 16, 2020

haha. Actually it is not the first time I request something to Azure team after two years either it is done or started :)

@alex-frankel alex-frankel self-assigned this Oct 21, 2020
@alexs77
Copy link

alexs77 commented Jun 23, 2021

Sorry for making noise, I'm having the exact same issue and use case now.
Has this been scheduled in the last 8.033 months?

@Sreini
Copy link

Sreini commented Aug 4, 2021

very interested in this as well.

Another use case is configuring vulnerability baselines for azure sql database. If i have to make users to connect to the database through managed identity, I'd like to be able to just pass the name of the user instead of also manually having to search for the object Id and convert it to hexadecimal characters :)

@Sreini
Copy link

Sreini commented Aug 4, 2021

that said, a hex() function would also be greatly appreciated!

@JanneHarju
Copy link

I was trying to use logged in user's objectId. OPs suggestion is more robust, but is there currently possible to get objectId of user which is running command? It is similar to subscription().tenantId and resourceGroup().location. It could be in environment() or just new function like loggedInUser().objectId

@alex-frankel
Copy link
Collaborator

is there currently possible to get objectId of user which is running command

The ARM deployment runs service side, not client side, so it technically would be the principal who created the deployment (which would be the same as the user logged into the client). Either way, there is not a way to do this today, @JanneHarju, do you mind creating an issue for this?

Has this been scheduled in the last 8.033 months?

No update here unfortunately.

@Marc013
Copy link

Marc013 commented Feb 10, 2022

Is there any update on this?
It would be great when this feature would be made available.

@JanneHarju
Copy link

@alex-frankel i didn't create issue for my suggestion. Actually currently I don't need it anymore. In my solution it was bad design what so ever to use users principalsId. And in my scenario I was adding permissions to keyvault in old way. Now there is new way with RBAC what I can use in other situations. Although not with user principal. Usually with other Azure resources principal.

@alex-frankel
Copy link
Collaborator

No updates - I will create a separate issue for getting the current principal's ID. Relevant internal issue is tracked here:
https://msazure.visualstudio.com/One/_workitems/edit/7512394?src=WorkItemMention&src-action=artifact_link

@alex-frankel
Copy link
Collaborator

alex-frankel commented Feb 10, 2022

Also would be curious to see how MS Graph extensibility alters the need for this.

Tagging #7724

@JustinGrote
Copy link

A slow but effective workaround is to make a deploymentScript module that looks up the user and has their ID as an output, you can then use that output in your references.

https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/deployment-script-template

Another similar workaround: I specify my bicep parameter files as .psd1 files because they're much easier to read, and at deploy time I import the parameter file and pass it to the -TemplateParameterObject during a New-Az*Deployment. You could easily add a step in there to first lookup any names specified in the parameter file and translate them to their Guids before starting the deployment.

@slavizh
Copy link
Contributor

slavizh commented Jun 10, 2022

yeah, workarounds are well known but with them comes too much problems you have to take care of.

@obiwanjacobi
Copy link

obiwanjacobi commented Sep 12, 2022

I searched a long time thinking 'surely this must exist'...
So, yeah - another vote for this feature request.

One of my use cases is that I want to assign roles to the app-registrations of DevOps Service Connections to a Bicep Private Registry used for deployment.

It doesn't have to be a function (lookup() or similar), I could totally live with using a bicep resource name 'Microsoft.AAD.AppRegistration@2022-12-31' exisiting = {} syntax... (or whatever the resource identifier is going to be)

@JanneHarju
Copy link

JanneHarju commented Sep 19, 2022

Hello @obiwanjacobi I think you can do it through devops using Azure cli like you are using it with bicep but not using bicep at all. I found this blog by searching: "azure devops app registration to azure ad" - https://blog.hompus.nl/2020/11/11/manage-azure-ad-applications-from-an-azure-devops-pipeline/ I haven't try it by myself but seems quite simple.

@alex-frankel alex-frankel removed their assignment Dec 8, 2022
@Kaloszer
Copy link

Facing the same issue as Microsoft Sentinel requires you give an MS SPN RBAC role access to execute Automation Rules, I do not want to run an external tool (eg Powershell deployment step script to get the ID, as I want the flow all to be embedded in a single flow for potential whatIf usecase scenario).

I would expect this to work to get the ID but, yeah as @obiwanjacobi mentioned - here I am 😢

resource azSecurityInsightsAccount 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = {
  name: 'Azure Security Insights'
}
Status Message: At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details. (Code: DeploymentFailed)
 - The Resource 'Microsoft.ManagedIdentity/userAssignedIdentities/Azure Security Insights' under resource group '[rgname]' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix (Code:ResourceNotFound)

For now I suppose I will have to grab the principalId manually and embeed it in variables of ADO pipeline and just find and replace before the flow runs.

@brwilkinson
Copy link
Collaborator

brwilkinson commented Apr 28, 2023

@Kaloszer are you needing to get the principalId from a user assigned managed identity in order to perform a role assignment with it? This is possible today.

Or are you using a AAD App registration/Service Principal?

Edit, I see you mention the Sentinel App.

Looking forward to the AAD/Graph extensibility for this..

In the meantime, at least these are static, so you can maintain the lookup to the objectid, then load with loadjsoncontent() and check this in with your project.
E.g. Lookup file

@Kaloszer
Copy link

Kaloszer commented Apr 28, 2023

Hmm I might've overlooked it - I was under the impression the ID it was unique per tenant, is it not?

Edit: ah I see, you have a config file with the ID there, yeah that's my solution to it aswell more or less. '''hardcoded''' in

@brwilkinson
Copy link
Collaborator

@Kaloszer yes in my param file I use the Name. Then do the lookup from the name to the ID from that file in the Module.

That way the param file are portable and user friendly on the SP name, so users don't have to deal with guids. There is a central place to maintain the lookup file.

I believe the graph extensibility provider will solve this specific problem for these Application ID lookups. Look forward to test to see if this part will be in scope of its capability soon.

@luxant
Copy link

luxant commented Jan 23, 2024

I'm also interested in this feature. Please make it possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
intermediate language Related to the intermediate language revisit
Projects
None yet
Development

No branches or pull requests