Since Azure
can be really complicated, I will try to break it down so anyone can understand.
Everyone are welcome to modify this post to the better as I am probably not 100% clear either.
Account Directories
When you create an Azure account, it creates a directory
(Default Directory), a directory is called a Tenant
, you can have multiple such directories
, I think you can even have separate login credentials for each, it is like an entirely separate organization, each directory
has its subscriptions
, resource groups
, resources
/apps
, etc.
Azure Active Directory
Each directory has its own Azure Active Directory
listing all its Users
, Groups
, and Applications
, that are the clients
/objects
going to be accessing or performing actions on the Resources
within this Directory
(tenant).
In this case it's your programmed app
that's gonna execute tasks on your Azure resources
, and in order to do this, the client
(your app) needs to have proper permission
to perform the specific action
(whatever action you wanna do), directly permitted to execute it on the specific resource
.
First you need to create a client
- which is the process of registering your app
, at Azure Active Directory
> App Registrations
click New Registration
, here you register your program app
as a client
/object
that you want to use for accessing your Azure resources
, give it a name MyApp, click Register
, you will get an Application (client) ID
which you gonna use in your code as the client ID
, this app
is now a User
/Service Principal
in your Azure AD (active directory)
, it now remains to give it permission for the actions you wanna perform on some resource
.
Go to the Resource
/Resource group
(App Service
/Database
/VM
), or to the Subscription
(which would give it permission to access all resources
within the entire subscription
), click on Access control (IAM)
> Add
> Add role assignment
.
- In the 'Add role assignment' screen, select the role action, in your case
Reader
.
- Go to the
Members
tab and here we're going to select the Service principal
(the app that you just registered).
- Click on "Select members", you'll see the AD users, but by default, you will not see AD
apps
that you registered, you need to search for them by their name, enter the name you've just given 'MyApp'.
- Select it from the list below and click
Select
at the bottom
- Finish the Assignment...
Follow the clicks by the numbers in the image below.
You should now refresh your credentials in your app, by re-executing the code that authorizes the client
, make sure you use the correct client-ID
of the app
that you registered in Azure, for some permissions, it may take a few minutes for the permissions to be updated, once it is, you should be good to go.
If you see the AuthorizationFailed
again, check if it's still the failed for same action
, as there might be another action
you need to assign for the principal
in order to achieve your output.
I hope this is going to help somebody... Good luck!
Links that might be helpful: