Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Execute Azure deployments using azd, Terraform, or Bicep with built-in error recovery.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/recipes/azd/sql-entra-auth.md
1# SQL Database Entra Authentication23Quick reference for Azure SQL Database Entra authentication in post-deployment scenarios.45## Prerequisites67Azure SQL Server must be configured with Entra-only authentication during provisioning. The signed-in user must be set as Entra admin:89```bicep10@allowed(['User', 'Group', 'Application'])11param principalType string = 'User'1213properties: {14administrators: {15administratorType: 'ActiveDirectory'16principalType: principalType // 'User' for interactive, 'Application' for CI/CD17login: principalName18sid: principalId19tenantId: subscription().tenantId20azureADOnlyAuthentication: true21}22}23```2425> ⚠️ **Warning:** Hardcoding `principalType: 'User'` causes `UnmatchedPrincipalType` errors when deploying from CI/CD with a service principal. Use a parameter instead.2627## Connection Patterns2829### Azure CLI (Recommended for Scripts)3031> ⚠️ **Warning:** `az sql db query` requires the `rdbms-connect` extension. Install it first: `az extension add --name rdbms-connect --yes`3233```bash34az sql db query \35--server "$SQL_SERVER" \36--database "$SQL_DATABASE" \37--resource-group "$AZURE_RESOURCE_GROUP" \38--auth-mode ActiveDirectoryDefault \39--queries "SELECT 1"40```4142### Connection Strings4344**For .NET applications with managed identity:**4546```47Server=tcp:{server}.database.windows.net,1433;Database={database};Authentication=Active Directory Default;Encrypt=True;48```4950**Required packages:**51- `Microsoft.Data.SqlClient` (v5.1.0+)52- `Azure.Identity` (for local development)5354## Database Roles5556| Role | Permissions | Use For |57|------|------------|---------|58| `db_datareader` | SELECT | Read operations |59| `db_datawriter` | INSERT, UPDATE, DELETE | Write operations |60| `db_ddladmin` | CREATE, ALTER, DROP schema | EF migrations |61| `db_owner` | Full control | Admin (use sparingly) |6263## Grant Managed Identity Access6465```sql66-- Create user from managed identity67CREATE USER [app-name] FROM EXTERNAL PROVIDER;6869-- Grant standard application permissions70ALTER ROLE db_datareader ADD MEMBER [app-name];71ALTER ROLE db_datawriter ADD MEMBER [app-name];72ALTER ROLE db_ddladmin ADD MEMBER [app-name];73```7475> 💡 **Tip:** The managed identity name matches the App Service or Container App name.7677## Verify Current Admin7879```bash80az sql server ad-admin list \81--server "$SQL_SERVER" \82--resource-group "$AZURE_RESOURCE_GROUP"83```8485## References8687- [SQL Managed Identity Access](sql-managed-identity.md)88- [EF Core Migrations](ef-migrations.md)89- [Post-Deployment Guide](post-deployment.md)90