Azure Database SQL Active Directory ADMinistrator

This page shows how to write Terraform and Azure Resource Manager for Database SQL Active Directory ADMinistrator and write them securely.

azurerm_sql_active_directory_administrator (Terraform)

The SQL Active Directory ADMinistrator in Database can be configured in Terraform with the resource name azurerm_sql_active_directory_administrator. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L74
resource "azurerm_sql_active_directory_administrator" "adadmin" {
  server_name         = azurerm_sql_server.main.name
  resource_group_name = azurerm_resource_group.main.name
  login               = "sampleadgroup"
  tenant_id           = data.azuread_client_config.current.tenant_id
  object_id           = azuread_group.adg.object_id
positive.tf#L18
resource "azurerm_sql_active_directory_administrator" "positive3" {
  server_name         = azurerm_sql_server.example.name
  resource_group_name = azurerm_resource_group.example.name
  login               = ""
  tenant_id           = data.azurerm_client_config.current.tenant_id
  object_id           = data.azurerm_client_config.current.object_id
positive1.tf#L15
resource "azurerm_sql_active_directory_administrator" "positive3" {
  server_name         = "mysqlserver2"
  resource_group_name = "acceptanceTestResourceGroup1"
  login               = "sqladmin"
  tenant_id           = data.azurerm_client_config.current.tenant_id
  object_id           = data.azurerm_client_config.current.object_id
main.tf#L1
resource "azurerm_sql_active_directory_administrator" "sqladadmin" {
  server_name         = var.sql_server_name
  resource_group_name = var.sql_server_rg
  login               = var.sql_server_login
  tenant_id           = var.azure_tenant_id
  object_id           = var.ad_object_id
positive.tf#L18
resource "azurerm_sql_active_directory_administrator" "positive3" {
  server_name         = azurerm_sql_server.example.name
  resource_group_name = azurerm_resource_group.example.name
  login               = ""
  tenant_id           = data.azurerm_client_config.current.tenant_id
  object_id           = data.azurerm_client_config.current.object_id
sql_admin_group.tf#L5
resource "azurerm_sql_active_directory_administrator" "sql_admins" {
  server_name         = azurerm_sql_server.sql_server.name
  resource_group_name = var.rg_name # azurerm_resource_group.sql-pri.name
  login               = var.sqladmins
  tenant_id           = data.azurerm_client_config.current.tenant_id
  object_id           = var.sqladmins
mssql.tf#L23
resource "azurerm_sql_active_directory_administrator" "sqlad_admin_login" {
  server_name         = azurerm_sql_server.mssqlserver.name
  resource_group_name = var.rgroup_name
  login               = "sqladmin"
  tenant_id           = data.azurerm_client_config.current.tenant_id
  object_id           = data.azurerm_client_config.current.object_id
azurerm_sql_active_directory_administrator.example.tf#L1
resource "azurerm_sql_active_directory_administrator" "example" {
  server_name         = azurerm_sql_server.examplea.name
  resource_group_name = var.resource_group.name
  login               = "sqladmin"
  tenant_id           = data.azurerm_client_config.current.tenant_id
  object_id           = data.azurerm_client_config.current.object_id
main.tf#L15
resource "azurerm_sql_active_directory_administrator" "positive3" {
  server_name         = "mysqlserver2"
  resource_group_name = "acceptanceTestResourceGroup1"
  login               = "sqladmin"
  tenant_id           = data.azurerm_client_config.current.tenant_id
  object_id           = data.azurerm_client_config.current.object_id
main.tf#L7
resource "azurerm_sql_active_directory_administrator" "this" {
  login               = var.login
  object_id           = var.object_id
  resource_group_name = var.resource_group_name
  server_name         = var.server_name
  tenant_id           = var.tenant_id

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Allows you to set a user or group as the AD administrator for an Azure SQL server

Tips: Best Practices for The Other Azure Database Resources

In addition to the azurerm_mariadb_firewall_rule, Azure Database has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

azurerm_mariadb_firewall_rule

Ensure database firewalls do not permit public access

It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.

risk-label

azurerm_mariadb_server

Ensure that access to Azure SQL Database is restricted

It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.

risk-label

azurerm_mssql_database_extended_auditing_policy

Ensure to configure retention periods of database auditing to enough duration

It is better to configure retention periods of database auditing to enough duration. It would be better to set greater than at least 90 days.

risk-label

azurerm_mssql_server

Ensure to enable auditing on Azure SQL databases

It is better to enable auditing on Azure SQL databases. It helps you maintain regulatory compliance, monitor the activities indicating unexpected incidents or suspected security violations.

risk-label

azurerm_mssql_server_security_alert_policy

Ensure to configure at least one email address for threat alerts

It is better to configure at least one email address for threat alerts. SQL Server is able to send alerts for threat detection via emails and it could support us to notice the incident on time.

risk-label

azurerm_mysql_firewall_rule

Ensure database firewalls do not permit public access

It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.

risk-label

azurerm_mysql_server

Ensure to disable public access to database

It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.

risk-label

azurerm_postgresql_firewall_rule

Ensure database firewalls do not permit public access

It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.

risk-label

azurerm_postgresql_server

Ensure to disable public access to database

It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.

risk-label

azurerm_sql_firewall_rule

Ensure database firewalls do not permit public access

It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.

risk-label

azurerm_sql_server

Ensure to enable auditing on Azure SQL databases

It is better to enable auditing on Azure SQL databases. It helps you maintain regulatory compliance, monitor the activities indicating unexpected incidents or suspected security violations.

Review your Azure Database settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Microsoft.Sql/servers/administrators (Azure Resource Manager)

The servers/administrators in Microsoft.Sql can be configured in Azure Resource Manager with the resource name Microsoft.Sql/servers/administrators. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

azurepolicy.json#L32
                    "type": "Microsoft.Sql/servers/administrators",
                    "existenceCondition": {
                        "allOf": [
                            {
                                "field": "Microsoft.Sql/servers/administrators/activeDirectory.administratorType",
                                "equals": "ActiveDirectory"
policy.rules.json#L9
      "type": "Microsoft.Sql/servers/administrators"
    }
  }
policy.rules.json#L9
      "type": "Microsoft.Sql/servers/administrators"
    }
  }
}
Security_-_SQL_DB_-_AuditServerADAdmins.json#L10
        "type": "Microsoft.Sql/servers/administrators"
      }
    }
  },
  "parameters": {}
administrators.json#L14
            "type": "Microsoft.Sql/servers/administrators",
            "apiVersion": "2019-06-01-preview",
            "properties": "[parameters('resourceObject').properties]"
        }
    ]
azuredeploy.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {},
    "variables": {},
AAD-admin-SQL-AINE.json
{
    "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
    },

Parameters

  • apiVersion required - string
  • name required - string

    Name of the server administrator resource.

  • properties required
      • administratorType required - string

        The type of administrator.

      • login required - string

        The server administrator login value.

      • sid required - string

        The server administrator Sid (Secure ID).

      • tenantId required - string

        The server Active Directory Administrator tenant id.

  • type required - string

Frequently asked questions

What is Azure Database SQL Active Directory ADMinistrator?

Azure Database SQL Active Directory ADMinistrator is a resource for Database of Microsoft Azure. Settings can be wrote in Terraform.

Where can I find the example code for the Azure Database SQL Active Directory ADMinistrator?

For Terraform, the edtroleis/azure-sqlserver2, Checkmarx/kics and Checkmarx/kics-github-action source code examples are useful. See the Terraform Example section for further details.

For Azure Resource Manager, the rjygraham/AzurePolicy, DPi30-Team/dpi30-source and AzureArchitecture/azure-deploy source code examples are useful. See the Azure Resource Manager Example section for further details.