azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Azure AD permissions needed

Open markthebault opened this issue 6 years ago • 14 comments

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: image 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.

markthebault avatar Jun 23 '20 11:06 markthebault

add to S172

yonzhan avatar Jun 23 '20 12:06 yonzhan

Any update on this ? It should not be too difficult that someone from Microsoft answer this question ?

markthebault avatar Jun 29 '20 12:06 markthebault

If you are using az ad, the only permission needed to manage an application is Azure Active Directory Graph > Application.ReadWrite.OwnedBy:

image

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

image

Please note that

  • The query should be appId instead of appid, because JMESPath is case-sensitive.
  • (Optional) You don't need export since 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.

jiasli avatar Jun 30 '20 02:06 jiasli

If you are using az ad, the only permission needed to manage an application is Azure Active Directory Graph > Application.ReadWrite.OwnedBy:

image

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

image

Please note that

  • The query should be appId instead of appid, because JMESPath is case-sensitive.
  • (Optional) You don't need export since 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: #12946 (comment).

Did you run it on Azure dev-ops?

nishanperera avatar Jun 30 '20 14:06 nishanperera

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

nishanperera avatar Jun 30 '20 21:06 nishanperera

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?

jiasli avatar Jul 01 '20 02:07 jiasli

Hi @jiasli,

Yes, it does have access. It can create the AAD application but can not add owners. I am using Azure CLI task. image

nishanperera avatar Jul 01 '20 08:07 nishanperera

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 avatar Jul 01 '20 08:07 jiasli

@jiasli Yes, it has admin consent.

image

nishanperera avatar Jul 01 '20 08:07 nishanperera

This is really weird. 🤔 Could you reach out to AAD team? As I don't have access to the AAD logs.

jiasli avatar Jul 01 '20 09:07 jiasli

Hi Guys I managed to solve the issue, this is the permission that was missing: Screenshot 2020-07-09 at 09 55 34

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

markthebault avatar Jul 09 '20 07:07 markthebault

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.

jiasli avatar Jul 09 '20 08:07 jiasli

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

nishanperera avatar Jul 09 '20 09:07 nishanperera

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.

jiasli avatar Jul 08 '21 10:07 jiasli