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

possibility of adding service principal owners with the cli #9250

Open
mariojacobo opened this issue Apr 30, 2019 — with docs.microsoft.com · 53 comments
Open

possibility of adding service principal owners with the cli #9250

mariojacobo opened this issue Apr 30, 2019 — with docs.microsoft.com · 53 comments
Assignees
Labels
feature-request Graph az ad Service Attention This issue is responsible by Azure service team.
Milestone

Comments

Copy link

"az ad sp owner add" would be nice to have. we currently add owners as a manual step after the environment build completes. Is there something similar in the CLI package ?


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@mariojacobo mariojacobo changed the title possibility of adding SP owners with the cli possibility of adding service principal owners with the cli Apr 30, 2019
@marstr marstr added Feature RBAC az role labels Apr 30, 2019
@jurjenoskam
Copy link

It seems this should have been part of microsoftgraph/microsoft-graph-docs#7578, which says it "Graph: support add/remove/list owners on app, sp, and group". The PR did this for app and group, but appears to have forgotten to include code for sp. Looking at the commits in that PR it only removes a comment under "ad sp owner": "# TODO: Add support for 'add' and 'remove'", but doesn't add code to actually add and remove owners from service principals.

@yugangw-msft
Copy link
Contributor

yugangw-msft commented May 28, 2019

Okay, i will follow up to onboard the support since we have the ask now.

@yugangw-msft yugangw-msft self-assigned this May 28, 2019
@yugangw-msft yugangw-msft added Graph az ad and removed RBAC az role Needs Triage labels May 28, 2019
@jonaspetersorensen
Copy link

Any progress on this?

@yugangw-msft
Copy link
Contributor

The related API is missing in the spec. Before it gets fixed, you can use az rest. A bit more detail is needed from this command; otherwise it is just like other ones:

az rest --method post --uri https://graph.windows.net/<tenantId>/servicePrincipals/<object id of the service principal>/$links/owners?api-version=1.6 --body "{\"url\":\"https://graph.windows.net/<tenantId>/directoryObjects/<owner's object id>\"}"

@yugangw-msft yugangw-msft removed their assignment Jul 29, 2019
Copy link

Yugangw-msft, I don't suppose you know the az rest command to remove a owner??

@kautsig
Copy link

kautsig commented Sep 17, 2019

I ran into the same issue of having to add an additional owner to an existing SP.

Unfortunately the API responds with "bad request":
Unsupported resource type 'DirectoryObject' for operation 'Create'.

My first suspicion was a permission problem, but I would expect a proper response then. Any ideas?

@pgroene
Copy link

pgroene commented Nov 18, 2019

@yugangw-msft

The related API is missing in the spec. Before it gets fixed, you can use az rest. A bit more detail is needed from this command; otherwise it is just like other ones:

az rest --method post --uri https://graph.windows.net/<tenantId>/servicePrincipals/<object id of the service principal>/$links/owners?api-version=1.6 --body "{\"url\":\"https://graph.windows.net/<tenantId>/directoryObjects/<owner's object id>\"}"

I tried this, but the owners are not added if the call succeeds.

When is the release for the cli ad sp scheduled to be released?

@jiasli jiasli self-assigned this Nov 22, 2019
@yonzhan yonzhan added this to the S162 milestone Nov 22, 2019
@dekimsey
Copy link

Yugangw-msft, I don't suppose you know the az rest command to remove a owner??

@miicahjardine, I've found the following works to delete owners:

az rest --method=delete --uri=https://graph.windows.net/<tenantId>/servicePrincipals/<object id of the service principal>/$links/owners/<owner object id>?api-version=1.6

@yonzhan
Copy link
Collaborator

yonzhan commented Dec 15, 2019

Can we close this issue?

@yonzhan yonzhan modified the milestones: S162, S163 Dec 15, 2019
@trvsmtchll
Copy link

Is this fixed I tried using "az rest ..." and also got the "Unsupported resource type 'DirectoryObject' for operation 'Create'." error.

@yonzhan yonzhan modified the milestones: S163, S164 Dec 30, 2019
@drdamour
Copy link

@23min i've always use User which inherits directoryObjects, agree docs are strange, fwiw u linked the beta docs...but even the 1.0 docs example shows using beta for the post target...so weird

az rest -m POST -u https://graph.microsoft.com/beta/servicePrincipals/<sp object id>/owners/`$ref --headers Content-Type=application/json -b '{\"@odata.id\": \"https://graph.microsoft.com/beta/users/<user id>\"}'

@jiasli
Copy link
Member

jiasli commented Sep 22, 2021

Hi folks, as for the behavior of Microsoft Graph API, you may reach out to AAD support by creating a support ticket. A support engineer will gladly help you with it.

@saldroubi
Copy link

saldroubi commented Oct 28, 2021

I also would like for this to be implemented in az cli as well. Why is this issue closed? One should not have to use the rest API with az. Please reopen! Also, using MS Graph is not an option because would give permission to use it in our environment.
Also, why are all these MS tools require different authentications, PowerShell Az module, Power Shell MS Graph, and Az CLI, ...etc.

@jiasli
Copy link
Member

jiasli commented Oct 29, 2021

I will reopen this issue and mark it as feature request.

Also, using MS Graph is not an option because would give permission to use it in our environment.

As AD Graph has been deprecated, using Microsoft Graph is the only option.

Also, why are all these MS tools require different authentications, PowerShell Az module, Power Shell MS Graph, and Az CLI, ...etc.

Thanks for the feedback. Personally, I also like the idea to share login context between Azure tools (tracked by #16460).

@saldroubi
Copy link

Is this in the works? It has been requested a long time ago.

@Mykp3
Copy link

Mykp3 commented Sep 29, 2022

This is such a ... limitation, why SP cannot be owner of other application regardless of initial creator responding with bad request?
This role currently is rather useless...
Application.ReadWrite.OwnedBy

@saldroubi
Copy link

I really wish this gets implemented soon. It has been so loooooooong.

@Mykp3
Copy link

Mykp3 commented Nov 1, 2022

@yugangw-msft when shall we expect advancement in Application.ReadWrite.OwnedBy API Permission, in particular,

Ability to assign AD application as an owner to existing AD application, e.g. not necessarily actually created by that application?

@notaturkey
Copy link

bump, wish i could do this

@Mykp3
Copy link

Mykp3 commented Nov 15, 2022

@saldroubi @notaturkey It is possible to make application registration to be owner of other application registration.

Requirements:

  • Powershell (in Az Portal cloud will do)
  • Understanding Enterprise Application concept
  • Application.ReadWrite.OwnedBy API permission granted for the application which will be owner of other app

From the main page of application registration of the future owner navigate to the link under "Managed application in local directory" description - it will redirect you to enterprise application page, copy object ID
From the main page of application registration of application ,that you want to owned by any other app, copy object id and paste below

Perform next cmdlet
Add-AzureADApplicationOwner -ObjectId $app.ObjectId -RefObjectId $spn.owner.ObjectId

It should allow you to manage app under another app.
If not enough you may also grab of enterprise application of desired owned application and perform slightly different ( SPN level assignment)

Add-AzureADServicePrincipalOwner -ObjectId $spn.ObjectId -RefObjectId $spn.owner.ObjectId

So we always interested to grant enterprise app (SPN) of future owner,
with target SPN and/or regular application registration object ID that we want to own.

@drdamour
Copy link

drdamour commented Nov 16, 2022

Yes you certainly can use powershell to add sp’s as owners, but this ticket is about az cli not ps module

@kevinpauli
Copy link

What the heck, four years later and it's not in there yet?

@ncook-hxgn
Copy link

bumpy bump bump

@Annesars90
Copy link

BUMPPPP

@rcomanne
Copy link

Would be very nice to be able to manage owners of a service principle by the Azure CLI...
Any progress update? Or are we just supposed to use the Graph API directly and this will not be implemented?

@jiasli jiasli removed the Graph-cli label May 23, 2023
@uracharla1
Copy link

Hi there, am currently trying to assign SPN owner to enterprise application using microsoft graph but not seems to working. From the portal is only allowing to add user only. Is there any solution to fix it?

@sodds-eq
Copy link

bump

2 similar comments
@dalekseevs
Copy link

bump

@jordan-lee-accessgroup
Copy link

bump

@hoivikaj
Copy link

While this is still missing from AZ CLI native as of today, wanted to drop in the command that currently works for me via AZ REST. Not sure if BETA endpoint is still required but its what I am currently using.

Azure Service Principal to be owned by Azure Service Principal:

az rest --method POST --uri https://graph.microsoft.com/beta/servicePrincipals/{TARGET SP OBJECT ID}/owners/\$ref --body '{"@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{OWNER SP OBJECT ID}"}'

I was previously having trouble as I missed the escape of $ for $ref.

@chadcarlton
Copy link

Please implement this... pretty unbelievable that 4 years later this is not in place.

@DariuszPorowski
Copy link

+1

@syunwei
Copy link

syunwei commented Sep 23, 2024

While this is still missing from AZ CLI native as of today, wanted to drop in the command that currently works for me via AZ REST. Not sure if BETA endpoint is still required but its what I am currently using.

Azure Service Principal to be owned by Azure Service Principal:

az rest --method POST --uri https://graph.microsoft.com/beta/servicePrincipals/{TARGET SP OBJECT ID}/owners/\$ref --body '{"@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{OWNER SP OBJECT ID}"}'

I was previously having trouble as I missed the escape of $ for $ref.

Thanks a lot for the command, that is working well.
In powershell console, the character escaping is a bit of different 🤮.

az rest --method POST --uri https://graph.microsoft.com/beta/servicePrincipals/{TARGET SP OBJECT ID}/owners/`$ref --body '{\"@odata.id\": \"https://graph.microsoft.com/v1.0/directoryObjects/{OWNER SP OBJECT ID}\"}'

Hope that helps..

@swisman
Copy link

swisman commented Oct 7, 2024

While this is still missing from AZ CLI native as of today, wanted to drop in the command that currently works for me via AZ REST. Not sure if BETA endpoint is still required but its what I am currently using.
Azure Service Principal to be owned by Azure Service Principal:

az rest --method POST --uri https://graph.microsoft.com/beta/servicePrincipals/{TARGET SP OBJECT ID}/owners/\$ref --body '{"@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{OWNER SP OBJECT ID}"}'

I was previously having trouble as I missed the escape of $ for $ref.

Thanks a lot for the command, that is working well. In powershell console, the character escaping is a bit of different 🤮.

az rest --method POST --uri https://graph.microsoft.com/beta/servicePrincipals/{TARGET SP OBJECT ID}/owners/`$ref --body '{\"@odata.id\": \"https://graph.microsoft.com/v1.0/directoryObjects/{OWNER SP OBJECT ID}\"}'

Hope that helps..

Thanks for sharing! Unfortunately, I struggled getting this run in a foreach loop in a powershell script. I'm sharing that others may not be struggling with syntax issues for the body as I did (and, funnily, MS Copilot was of no use here!).
I finally got it run (for PSVersion 5.1.22621.4111) using:

    $uri = "https://graph.microsoft.com/beta/servicePrincipals/$spEAObjectId/owners/`$ref"
    $jsonBody = '{{\"@odata.id\": \"https://graph.microsoft.com/v1.0/directoryObjects/{0}\"}}' -f $ownerObjectId
    az rest --method POST --uri $uri --body $jsonBody 

Btw. deleting an owner works similarly:

    $uri = "https://graph.microsoft.com/beta/servicePrincipals/$spEAObjectId/owners/$ownerObjectId/`$ref"
    az rest --method DELETE --uri $uri

Hope that helps.
And yet: this should become part of Azure CLI!

@JustJordanT
Copy link

running into this issue when using terraform if you import a existing app reg, you need this to be able to set the sp (terraform) owner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Graph az ad Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests