|
| 1 | +--- |
| 2 | +title: Audit to storage account behind VNet and firewall |
| 3 | +description: Configure auditing to write database events on a storage account behind virtual network and firewall |
| 4 | +services: sql-database |
| 5 | +ms.service: sql-database |
| 6 | +ms.subservice: security |
| 7 | +ms.topic: conceptual |
| 8 | +author: DavidTrigano |
| 9 | +ms.author: datrigan |
| 10 | +ms.reviewer: vanto |
| 11 | +ms.date: 03/19/2020 |
| 12 | +ms.custom: azure-synapse |
| 13 | +--- |
| 14 | +# Write audit to a storage account behind VNet and firewall |
| 15 | + |
| 16 | +Auditing for [Azure SQL Database](sql-database-technical-overview.md) and [Azure Synapse Analytics](../sql-data-warehouse/sql-data-warehouse-overview-what-is.md) supports writing database events to an [Azure Storage account](../storage/common/storage-account-overview.md) behind a virtual network and firewall. |
| 17 | + |
| 18 | +This article explains two ways to configure Azure SQL Server and Azure storage account for this option. The first uses the Azure portal, the second uses REST. |
| 19 | + |
| 20 | +### Background |
| 21 | + |
| 22 | +[Azure Virtual Network (VNet)](../virtual-network/virtual-networks-overview.md) is the fundamental building block for your private network in Azure. VNet enables many types of Azure resources, such as Azure Virtual Machines (VM), to securely communicate with each other, the internet, and on-premises networks. VNet is similar to a traditional network in your own data center, but brings with it additional benefits of Azure infrastructure such as scale, availability, and isolation. |
| 23 | + |
| 24 | +To learn more about the VNet concepts, Best practices and many more, see [What is Azure Virtual Network](../virtual-network/virtual-networks-overview.md). |
| 25 | + |
| 26 | +To learn more about how to create a virtual network, see [Quickstart: Create a virtual network using the Azure portal](../virtual-network/quick-create-portal.md). |
| 27 | + |
| 28 | +## Prerequisites |
| 29 | + |
| 30 | +For audit to write to a storage account behind a VNet or firewall, the following prerequisites are required: |
| 31 | + |
| 32 | +> [!div class="checklist"] |
| 33 | +> * A general-purpose v2 storage account. If you have a general-purpose v1 or blob storage account, [upgrade to a general-purpose v2 storage account](../storage/common/storage-account-upgrade.md). For more information, see [Types of storage accounts](../storage/common/storage-account-overview.md#types-of-storage-accounts). |
| 34 | +> * The storage account must be on the same subscription and at the same location as the Azure SQL Database server. |
| 35 | +> * The Azure Storage account requires `Allow trusted Microsoft services to access this storage account`. Set this on the Storage Account **Firewalls and Virtual networks**. |
| 36 | +> * You must have `Microsoft.Authorization/roleAssignments/write` permission on the selected storage account. For more information, see [Azure built-in roles](../role-based-access-control/built-in-roles.md). |
| 37 | +
|
| 38 | +## Configure in Azure portal |
| 39 | + |
| 40 | +Connect to [Azure portal](https://portal.azure.com) with your subscription. Navigate to the resource group and Azure SQL database server. |
| 41 | + |
| 42 | +1. Click on **Auditing** under the Security heading. Select **On**. |
| 43 | + |
| 44 | +2. Select **Storage**. Select the storage account where logs will be saved. The storage account must comply with the requirements listed in [Prerequisites](#prerequisites). |
| 45 | + |
| 46 | +3. Open **Storage details** |
| 47 | + |
| 48 | + > [!NOTE] |
| 49 | + > If the selected Storage account is behind VNet, you will see the following message: |
| 50 | + > |
| 51 | + >`You have selected a storage account that is behind a firewall or in a virtual network. Using this storage: requires an Active Directory admin on the server; enables 'Allow trusted Microsoft services to access this storage account' on the storage account; and creates a server managed identity with 'storage blob data contributor' RBAC.` |
| 52 | + > |
| 53 | + >If you do not see this message, then storage account is not behind a VNet. |
| 54 | +
|
| 55 | +4. Select the number of days for the retention period. Then click **OK**. Logs older than the retention period are deleted. |
| 56 | + |
| 57 | +5. Select **Save** on your auditing settings. |
| 58 | + |
| 59 | +You have successfully configured audit to write to a storage account behind a VNet or firewall. |
| 60 | + |
| 61 | +## Configure with REST commands |
| 62 | + |
| 63 | +As an alternative to using the Azure portal, you can use REST commands to configure audit to write database events on a storage account behind a VNet and Firewall. |
| 64 | + |
| 65 | +The sample scripts in this section require you to update the script before you run them. Replace the following values in the scripts: |
| 66 | + |
| 67 | +|Sample value|Sample description| |
| 68 | +|:-----|:-----| |
| 69 | +|`<subscriptionId>`| Azure subscription ID| |
| 70 | +|`<resource group>`| Resource group| |
| 71 | +|`<sql database server>`| Azure SQL database server name| |
| 72 | +|`<administrator login>`| SQL database administrator account | |
| 73 | +|`<complex password>`| Complex password for the administrator account| |
| 74 | + |
| 75 | +To configure SQL Audit to write events to a storage account behind a VNet or Firewall: |
| 76 | + |
| 77 | +1. Register your Azure SQL Database server with Azure Active Directory (Azure AD). Use either PowerShell or REST API. |
| 78 | + |
| 79 | + **PowerShell** |
| 80 | + |
| 81 | + ```powershell |
| 82 | + Connect-AzAccount |
| 83 | + Select-AzSubscription -SubscriptionId <subscriptionId> |
| 84 | + Set-AzSqlServer -ResourceGroupName <your resource group> -ServerName <sql database server> -AssignIdentity |
| 85 | + ``` |
| 86 | + |
| 87 | + [**REST API**](https://docs.microsoft.com/rest/api/sql/servers/createorupdate): |
| 88 | + |
| 89 | + Sample request |
| 90 | + |
| 91 | + ```html |
| 92 | + PUT https://management.azure.com/subscriptions/<subscription ID>/resourceGroups/<resource group>/providers/Microsoft.Sql/servers/<sql database server>?api-version=2015-05-01-preview |
| 93 | + ``` |
| 94 | + |
| 95 | + Request body |
| 96 | + |
| 97 | + ```json |
| 98 | + { |
| 99 | + "identity": { |
| 100 | + "type": "SystemAssigned", |
| 101 | + }, |
| 102 | + "properties": { |
| 103 | + "fullyQualifiedDomainName": "<sql database server>.database.windows.net", |
| 104 | + "administratorLogin": "<administrator login>", |
| 105 | + "administratorLoginPassword": "<complex password>", |
| 106 | + "version": "12.0", |
| 107 | + "state": "Ready" |
| 108 | + } |
| 109 | + ``` |
| 110 | + |
| 111 | +2. Open [Azure portal](https://portal.azure.com). Navigate to your storage account. Locate **Access Control (IAM)**, and click **Add role assignment**. Assign **Storage Blob Data Contributor** RBAC role to your Azure SQL Server hosting your Azure SQL database that you registered with Azure Active Directory (Azure AD) as in the previous step. |
| 112 | + |
| 113 | + > [!NOTE] |
| 114 | + > Only members with Owner privilege can perform this step. For various built-in roles for Azure resources, refer to [Azure built-in roles](../role-based-access-control/built-in-roles.md). |
| 115 | + |
| 116 | +3. Configure [Azure SQL server's blob auditing policy](/rest/api/sql/server%20auditing%20settings/createorupdate), without specifying a *storageAccountAccessKey*: |
| 117 | + |
| 118 | + Sample request |
| 119 | + |
| 120 | + ```html |
| 121 | + PUT https://management.azure.com/subscriptions/<subscription ID>/resourceGroups/<resource group>/providers/Microsoft.Sql/servers/<azure sql database server>?api-version=2017-03-01-preview |
| 122 | + ``` |
| 123 | + |
| 124 | + Request body |
| 125 | + |
| 126 | + ```json |
| 127 | + { |
| 128 | + "properties": { |
| 129 | + "state": "Enabled", |
| 130 | + "storageEndpoint": "https://<storage account>.blob.core.windows.net" |
| 131 | + } |
| 132 | + } |
| 133 | + ``` |
| 134 | + |
| 135 | +## Next steps |
| 136 | + |
| 137 | +- [Use PowerShell to create a virtual network service endpoint, and then a virtual network rule for Azure SQL Database.](sql-database-vnet-service-endpoint-rule-powershell.md) |
| 138 | +- [Virtual Network Rules: Operations with REST APIs](/rest/api/sql/virtualnetworkrules) |
| 139 | +- [Use virtual network service endpoints and rules for database servers](sql-database-vnet-service-endpoint-rule-overview.md) |
0 commit comments