Azure AD permissions needed
Hi There, I am running a pipeline under a service principal and I try to add new owners to the Azure AD applications that I create through this SP. The latter as the following permissions granted:
However I am not able to add new owners when I create a new application here is the steps that I follow:
#login using the service principal
$ az login --service-principal --user $app_id --password $app_secret --tenant $tenant_id
#creating new application
$ export created_app_id=$(az ad app create --display-name "sp-created-app2" --query appid -o tsv)
#Add new owner to my subscription
$ az ad app owner add --id $created_app_id --owner-object-id $my_azuread_user
Insufficient privileges to complete the operation.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 7af83ae6-8be6-c2a3-e994-d09b60ddc167
- Version Independent ID: 70f8a6b9-5cba-2e41-1046-423405782c4c
- Content: az ad app owner
- Content Source: src/azure-cli/azure/cli/command_modules/role/_help.py
- Service: active-directory
- GitHub Login: @rloutlaw
- Microsoft Alias: routlaw
add to S172
Any update on this ? It should not be too difficult that someone from Microsoft answer this question ?
If you are using az ad, the only permission needed to manage an application is Azure Active Directory Graph > Application.ReadWrite.OwnedBy:

I refined your script a little bit and it works fine:
app_id=93dde3da-9fca-47dd-aee2-409b402ffed3
app_secret="IB0..."
tenant_id=54826b22-38d6-4fb2-bad9-b7b93a3e9c5a
my_azuread_user=7a938a30-4226-420e-996f-4d48bca6d537
# Login using the service principal
az login --service-principal --username $app_id --password $app_secret --tenant $tenant_id --allow-no-subscriptions
# Creating new application
created_app_id=$(az ad app create --display-name "sp-created-app2" --query appId -o tsv)
# Add new owner to my application
az ad app owner add --id $created_app_id --owner-object-id $my_azuread_user

Please note that
- The query should be
appIdinstead ofappid, because JMESPath is case-sensitive. - (Optional) You don't need
exportsince these commands are in the same Bash script. 😉
If it still doesn't work, please run the command with --debug and share the output.
You may also be interested in the new az rest and Microsoft Graph way: https://github.com/Azure/azure-cli/issues/12946#issuecomment-611922734.
If you are using
az ad, the only permission needed to manage an application is Azure Active Directory Graph > Application.ReadWrite.OwnedBy:
I refined your script a little bit and it works fine:
app_id=93dde3da-9fca-47dd-aee2-409b402ffed3 app_secret="IB0..." tenant_id=54826b22-38d6-4fb2-bad9-b7b93a3e9c5a my_azuread_user=7a938a30-4226-420e-996f-4d48bca6d537 # Login using the service principal az login --service-principal --username $app_id --password $app_secret --tenant $tenant_id --allow-no-subscriptions # Creating new application created_app_id=$(az ad app create --display-name "sp-created-app2" --query appId -o tsv) # Add new owner to my application az ad app owner add --id $created_app_id --owner-object-id $my_azuread_user
Please note that
- The query should be
appIdinstead ofappid, because JMESPath is case-sensitive.- (Optional) You don't need
exportsince these commands are in the same Bash script. 😉If it still doesn't work, please run the command with
--debugand share the output.You may also be interested in the new
az restand Microsoft Graph way: #12946 (comment).
Did you run it on Azure dev-ops?
Hi @jiasli
Part of the log.
2020-06-30T20:33:20.1579640Z msrest.http_logger : Request method: 'POST' 2020-06-30T20:33:20.1580139Z msrest.http_logger : Request headers: 2020-06-30T20:33:20.1580569Z msrest.http_logger : 'Content-Type': 'application/json; charset=utf-8' 2020-06-30T20:33:20.1581012Z msrest.http_logger : 'accept-language': 'en-US' 2020-06-30T20:33:20.1581406Z msrest.http_logger : 'Accept': 'application/json' 2020-06-30T20:33:20.1581805Z msrest.http_logger : 'Content-Length': '127' 2020-06-30T20:33:20.1582627Z msrest.http_logger : 'User-Agent': 'python/3.6.6 (Windows-10-10.0.14393-SP0) msrest/0.6.9 VSTS_df52c552-bfb2-4247-bf60-fd1abee0a25b_Release__1070_2816_1 msrest_azure/0.6.3 azure-graphrbac/0.60.0 Azure-SDK-For-Python AZURECLI/2.7.0 (MSI)' 2020-06-30T20:33:20.1583323Z msrest.http_logger : Request body: 2020-06-30T20:33:20.1583888Z msrest.http_logger : {"url": "https://graph.windows.net//directoryObjects/xxxxxxx"} 2020-06-30T20:33:20.1584450Z msrest.universal_http : Configuring redirects: allow=True, max=30 2020-06-30T20:33:20.1584946Z msrest.universal_http : Configuring request: timeout=100, verify=True, cert=None 2020-06-30T20:33:20.1585531Z msrest.universal_http : Configuring proxies: '' 2020-06-30T20:33:20.1585987Z msrest.universal_http : Evaluate proxies against ENV settings: True 2020-06-30T20:33:20.1611847Z urllib3.connectionpool : Starting new HTTPS connection (1): graph.windows.net:443 2020-06-30T20:33:20.2679503Z urllib3.connectionpool : https://graph.windows.net:443 "POST //applications/xxxxxxxxxxxxxxxxxxxxx/$links/owners?api-version=1.6 HTTP/1.1" 403 219 2020-06-30T20:33:20.2680968Z msrest.http_logger : Response status: 403 2020-06-30T20:33:20.2681391Z msrest.http_logger : Response headers: 2020-06-30T20:33:20.2682608Z msrest.http_logger : 'Cache-Control': 'no-cache'
Thanks
Hi @nishanperera, I ran that script on a local machine, but I don't think there is any difference between running on DevOps or a local machine.
From the debug log, the failed request is
POST https://graph.windows.net:443/***/applications/xxxxxxxxxxxxxxxxxxxxx/$links/owners?api-version=1.6
Does the service principal has Azure Active Directory Graph > Application.ReadWrite.OwnedBy permission?
Hi @jiasli,
Yes, it does have access. It can create the AAD application but can not add owners. I am using Azure CLI task.

The screenshot doesn't contain the admin consent status. Please make sure it shows a green check mark (similar to ✅) as shown in https://github.com/Azure/azure-cli/issues/14074#issuecomment-651480005.
If so and adding owner still doesn't work, could you open a support ticket to AAD in Azure Portal and provide the --debug log? A support engineer will gladly help you troubleshoot it from backend. Thanks for your understanding.
@jiasli Yes, it has admin consent.

This is really weird. 🤔 Could you reach out to AAD team? As I don't have access to the AAD logs.
Hi Guys I managed to solve the issue, this is the permission that was missing:

You do only need the following permissions to do the use-case presented: Azure active directory graphs:
- Application.readWrite.OwnedBy -- Application
- Directory.Read.All -- Application
Hi @markthebault, Directory.Read.All -- Application is not a trivial permission, and may grant the application the permission to read sensitive data in the directory. I would still recommend contacting AAD support team to report this issue or asking for clarification.
Hi, @markthebault I am in the process of adding the permission. Found this article https://docs.microsoft.com/en-us/graph/api/application-post-owners?view=graph-rest-1.0&tabs=http seems like it is necessary @jiasli
Thanks @nishanperera for the link.
Indeed, https://docs.microsoft.com/en-us/graph/api/application-post-owners?view=graph-rest-1.0&tabs=http indicates that for Application, Application.ReadWrite.OwnedBy and Directory.Read.All are the minimum required permissions.