Skip to content

Commit

Permalink
FIX Azure SQL DB Permissions (#440)
Browse files Browse the repository at this point in the history
Co-authored-by: rdheekonda <[email protected]>
  • Loading branch information
rdheekonda and rdheekonda authored Oct 8, 2024
1 parent 94f4227 commit b6828f9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions doc/setup/use_azure_sql_db.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Azure SQL Database Setup, Authentication and User Permissions

This document provides a comprehensive guide to setting up and managing Azure SQL Database with a focus on using Entra ID authentication. It covers the essential steps for creating an Azure SQL Database, configuring Azure SQL Server security controls such as enabling Entra ID-only authentication and restricting access to selected networks, mapping Entra ID users to specific Azure SQL DB roles like `db_owner`, `db_writer`, and `db_reader`, and verifying if corporate email users exist in the database while granting appropriate permissions to them.
This document provides a comprehensive guide to setting up and managing Azure SQL Database with a focus on using Entra ID authentication. It covers the essential steps for creating an Azure SQL Database, configuring Azure SQL Server security controls such as enabling Entra ID-only authentication and restricting access to selected networks, mapping Entra ID users to specific Azure SQL DB roles like `db_owner`, `db_datawriter`, and `db_datareader`, and verifying if corporate email users exist in the database while granting appropriate permissions to them.

If the Azure SQL Database is already set up, you can skip directly to Section 3 to manage user DB permissions.

Expand Down Expand Up @@ -45,21 +45,21 @@ Even when users authenticate via Entra ID, they must be explicitly mapped to spe
### Key Database Roles:

1. **db_owner**: Provides full control over the Azure SQL Database. Users with this role can create, modify, and delete database objects, manage security, and grant/revoke permissions to other users.
2. **db_writer**: Allows users to insert, update, and delete data but does not permit modifying the database schema or managing users.
3. **db_reader**: Grants read-only access to all tables and views in the database.
2. **db_datawriter**: Allows users to insert, update, and delete data but does not permit modifying the database schema or managing users.
3. **db_datareader**: Grants read-only access to all tables and views in the database.

### Mapping Entra ID Users to Database Roles

To grant users access to the database, you must map them to the appropriate role. Developers/maintainers should be assigned the `db_owner` role, while operators can be assigned the `db_writer` role.
To grant users access to the database, you must map them to the appropriate role. Developers/maintainers should be assigned the `db_owner` role, while operators can be assigned the `db_datawriter` role.

### Example: Mapping Entra ID Users

```sql
-- Create a database user for the Entra ID user
CREATE USER [user@domain.com] FROM EXTERNAL PROVIDER;

-- Map the user to the db_writer role
ALTER ROLE db_writer ADD MEMBER [user@domain.com];
-- Map the user to the db_datawriter role
ALTER ROLE db_datawriter ADD MEMBER [user@domain.com];
```

`[email protected]` could be corporate email address, such as `[email protected]`, which is linked to Entra ID.
Expand All @@ -85,14 +85,14 @@ ORDER BY UserName, RoleName;

| UserName | UserType | RoleName |
|--------------------|---------------|-------------|
| [email protected] | EXTERNAL_USER | db_writer |
| [email protected] | EXTERNAL_USER | db_datawriter |
| [email protected] | EXTERNAL_USER | db_owner |

## 5. Granting Permissions to a New User

1. Determine whether the user needs the `db_owner` or `db_writer` role.
1. Determine whether the user needs the `db_owner` or `db_datawriter` role.
- **db_owner** is recommended for developers and maintainers.
- **db_writer** is recommended for operators interacting with the database.
- **db_datawriter** is recommended for operators interacting with the database.

2. Run the following commands from the query editor:

Expand All @@ -101,7 +101,7 @@ ORDER BY UserName, RoleName;
CREATE USER [user@domain.com] FROM EXTERNAL PROVIDER;

-- Map the user to the required role
ALTER ROLE db_writer ADD MEMBER [user@domain.com];
ALTER ROLE db_datawriter ADD MEMBER [user@domain.com];
```

3. Verify the permissions by running the above **Checking If a Corporate Email Address Exists** query again in the Query Editor.
Expand Down

0 comments on commit b6828f9

Please sign in to comment.