What role do I need to add to an application to enable it to add databases to a resource group?

Christopher Clark 50 Reputation points
2024-02-06T16:49:10.2366667+00:00

I'm trying to write a proof of concept for a provisioning app to create all the needed SQL resources for a new environment. I created an app registration and gave it the permissions SQL DB Contributor and SQL Managed Access Contributor. Based on the descriptions, this should give it SQL Write access. I know the roles are being applied because since I added them, I stopped getting the error that I do not have Read permissions and started getting an error that I do not have Write permissions. Which role would I actually need to give the app to be able to provision databases?

Azure SQL Database
Microsoft Security | Microsoft Graph
0 comments No comments

Answer accepted by question author
Ahamed Musthafa Careem 591 Reputation points
2024-02-06T18:52:53.6166667+00:00

The SQL DB Contributor and SQL Managed Instance Contributor roles provide broad permissions for managing existing databases and instances, but they may not include permissions to create new resources. For provisioning new databases, you might need more elevated permissions such as the Owner or Contributor role at the resource group or subscription level. These roles grant the ability to create and manage all types of Azure resources, including Azure SQL databases. Please check your current role assignments and consider assigning the Contributor role at the resource group where you intend to provision the databases. This should resolve the write permissions error you are encountering.

Was this answer helpful?

0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Christopher Clark 50 Reputation points
    2024-02-06T20:30:15.0666667+00:00

    A related question, is there a better resource to find good code examples that show exactly how to use azure.resourcemanager.sql package in .NET? All the resources I can find either give a list of dozens of methods with no context or they apply to a deprecated version of the package. It was tough just to figure out how to add a database, much less add it to an elastic versus vCore based pool.

    Was this answer helpful?

    0 comments No comments

  2. Christopher Clark 50 Reputation points
    2024-02-06T20:18:41.5566667+00:00

    Thanks for the responses. Using the Contributor role worked, but it kinda feels like overkill for a provisioning app, are admin level privileges the only way to give an app the ability to programmatically provision databases?

    Was this answer helpful?

    0 comments No comments

  3. Oury Ba-MSFT 21,156 Reputation points Microsoft Employee Moderator
    2024-02-06T19:45:43.0533333+00:00

    @Christopher Clark Thank you for reaching out. In addition to the above answers. From https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#sql-server-contributor: User's image

    The role includes the Microsoft.Sql/servers/* action. The * means that it also includes Microsoft.Sql/servers/databases/*.

    Regards, Oury

    Was this answer helpful?

    0 comments No comments

  4. Amira Bedhiafi 43,046 Reputation points MVP Volunteer Moderator
    2024-02-06T18:57:09.4733333+00:00

    For provisioning Azure SQL databases, in order to allow an application to add the CPU database packages for example as mentioned above IDs into a resource group within azure you need not only ensure that then given levels of permission at the level however it also needs and must be guaranteed even from entry point onward added functionality. The above-mentioned roles, SQL DB Contributor and SQL Managed Instance Adventurer, provide appropriate content responsibility concerning Azure SQL resources. Consquently, resource labor requires work of operation at the level of a resources group including deployment of resources.

    For your application to have the capability to provision databases, you should consider adding it to one of the following roles at the resource group (or subscription, depending on the scope of your operations) level:Despite protests by the Natives, they were relocated to South Park with a provision for tents from which meals could be provided.

    1. Contributor: This function enables the holder of this role to only be able generate, manage and control all Azure resources however it does not provide any form access for granting roles in azure RBAC or management allocation. This is a blanket permission and needs to be used with moderation, more so in the production settings.
    2. Owner: This position has all the access to Azure resources, which even include delegating permission. It allows controlling all the elements that form a part of resource group including role assignments. Just like the Contributor role, this is a very strong permission that needs to be limited among applications and users with rad full access only.

    Links : https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles https://learn.microsoft.com/en-us/azure/azure-sql/managed-instance/resource-limits?view=azuresql

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.