You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: This article provides an overview of how to set up Auditing and storing those audits to an Azure storage account, Log Analytics workspace, or Event Hubs destination.
5
5
author: sravanisaluru
6
6
ms.author: srsaluru
7
-
ms.reviewer: mathoma
8
-
ms.date: 04/26/2023
7
+
ms.reviewer: mathoma, vanto
8
+
ms.date: 09/17/2024
9
9
ms.service: azure-sql-database
10
10
ms.subservice: security
11
11
ms.topic: conceptual
12
12
---
13
13
# Set up Auditing for Azure SQL Database and Azure Synapse Analytics
In this article, we go over setting up Auditing for your logical server or database in [Azure SQL Database](sql-database-paas-overview.md) and [Azure Synapse Analytics](/azure/synapse-analytics/sql-data-warehouse/sql-data-warehouse-overview-what-is).
18
18
@@ -24,9 +24,9 @@ The default auditing policy includes the following set of action groups, which a
24
24
- SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP
25
25
- FAILED_DATABASE_AUTHENTICATION_GROUP
26
26
27
-
To configure auditing for different types of actions and action groups using PowerShell, see [Manage Azure SQL Database Auditing](auditing-manage-using-api.md).
27
+
To configure auditing for different types of actions and action groups using PowerShell, see [Manage Azure SQL Database Auditing using APIs](auditing-manage-using-api.md).
28
28
29
-
Azure SQL Database and Azure Synapse Analytics Audit can store 4000 characters of data for character fields in an audit record. When the **statement** or the **data_sensitivity_information** values returned from an auditable action contain more than 4000 characters, any data beyond the first 4000 characters are **truncated and not audited**.
29
+
Azure SQL Database and Azure Synapse Analytics Audit can store 4,000 characters of data for character fields in an audit record. When the **statement** or the **data_sensitivity_information** values returned from an auditable action contain more than 4000 characters, any data beyond the first 4000 characters are **truncated and not audited**.
30
30
31
31
The following section describes the Auditing configuration using the Azure portal.
32
32
@@ -39,19 +39,19 @@ The following section describes the Auditing configuration using the Azure porta
39
39
1. Navigate to **Auditing** under the **Security** heading in your **SQL database** or **SQL server** pane.
40
40
1. If you prefer to set up a server auditing policy, you can select the **View server settings** link on the database auditing page. You can then view or modify the server auditing settings. Server auditing policies apply to all existing and newly created databases on this server.
41
41
42
-
:::image type="content" source="./media/auditing-overview/2_auditing_get_started_server_inherit.png" alt-text="Screenshot that shows the View server settings link highlighted on the database auditing page.":::
42
+
:::image type="content" source="media/auditing-setup/auditing-get-started-server-inherit.png" alt-text="Screenshot that shows the View server settings link highlighted on the database auditing page." lightbox="media/auditing-setup/auditing-get-started-server-inherit.png":::
43
43
44
44
1. If you prefer to enable auditing on the database level, switch **Auditing** to **ON**. If server auditing is enabled, the database-configured audit exists side-by-side with the server audit.
45
45
46
46
1. You have multiple options for configuring where audit logs are stored. You can write logs to an Azure storage account, to a Log Analytics workspace for consumption by Azure Monitor logs, or to event hub for consumption using event hub. You can configure any combination of these options, and audit logs are written to each.
47
47
48
-
:::image type="content" source="./media/auditing-overview/auditing-select-destination.png" alt-text="Screenshot that shows the storage options for Auditing.":::
48
+
:::image type="content" source="media/auditing-setup/auditing-select-destination.png" alt-text="Screenshot that shows the storage options for Auditing.":::
49
49
50
50
## Audit to storage destination
51
51
52
52
To configure writing audit logs to a storage account, select **Storage** when you get to the **Auditing** section. Select the Azure storage account where you want to save your logs. You can use the following two storage authentication types: **Managed Identity** and **Storage Access Keys**. For managed identity, system-assigned and user-assigned managed identity is supported. By default, the primary user identity assigned to the server is selected. If there's no user identity, then a system-assigned managed identity is created and used for authentication purposes. After you have chosen an authentication type, select a retention period by opening **Advanced properties** and selecting **Save**. Logs older than the retention period are deleted.
53
53
54
-
:::image type="content" source="./media/auditing-overview/auditing_select_storage.png" alt-text="Screenshot that shows storage account authentication types for Auditing.":::
54
+
:::image type="content" source="media/auditing-setup/auditing-select-storage.png" alt-text="Screenshot that shows storage account authentication types for Auditing." lightbox="media/auditing-setup/auditing-select-storage.png":::
55
55
56
56
> [!NOTE]
57
57
> If you are deploying from the Azure portal, make sure that the storage account is in the same region as your database and server. If you are deploying through other methods, the storage account can be in any region.
@@ -63,25 +63,25 @@ To configure writing audit logs to a storage account, select **Storage** when yo
63
63
64
64
To configure writing audit logs to a Log Analytics workspace, select **Log Analytics** and open **Log Analytics details**. Select the Log Analytics workspace where logs you want logs stored, and then select **OK**. If you haven't created a Log Analytics workspace, see [Create a Log Analytics workspace in the Azure portal](/azure/azure-monitor/logs/quick-create-workspace).
65
65
66
-
:::image type="content" source="./media/auditing-overview/auditing_select_oms.png" alt-text="Screenshot showing the Log Analytics workspace.":::
To configure writing audit logs to an event hub, select **Event Hub**. Select the event hub where you want logs stored, and then select **Save**. Be sure that the event hub is in the same region as your database and server.
71
71
72
-
:::image type="content" source="./media/auditing-overview/auditing_select_event_hub.png" alt-text="Screenshot showing the Event hub.":::
72
+
:::image type="content" source="media/auditing-setup/auditing-select-event-hub.png" alt-text="Screenshot showing the Event hub." lightbox="media/auditing-setup/auditing-select-event-hub.png":::
73
73
74
-
> [!NOTE]
75
-
> If you are using multiple targets like storage account , log analytics or event hub , make sure you have permissions for all the targets else saving audit configuration would fail as it will try to save the settings for all targets.
74
+
> [!NOTE]
75
+
> If you are using multiple targets like storage account , log analytics or event hub , make sure you have permissions for all the targets else saving audit configuration would fail as it will try to save the settings for all targets.
76
76
77
77
## Next steps
78
78
79
79
> [!div class="nextstepaction"]
80
80
> [Use Auditing to analyze audit logs and reports](auditing-analyze-audit-logs.md)
81
81
82
-
## See also
82
+
## Related content
83
83
84
-
-[Auditing overview](auditing-overview.md)
85
-
-Data Exposed episode [What's New in Azure SQL Auditing](/Shows/Data-Exposed/Whats-New-in-Azure-SQL-Auditing)
86
-
-[Auditing for SQL Managed Instance](../managed-instance/auditing-configure.md)
84
+
-[Auditing for Azure SQL Database and Azure Synapse Analytics](auditing-overview.md)
85
+
-[What's New in Azure SQL Auditing](/Shows/Data-Exposed/Whats-New-in-Azure-SQL-Auditing)
86
+
-[Get started with Azure SQL Managed Instance auditing](../managed-instance/auditing-configure.md)
87
87
-[Auditing for SQL Server](/sql/relational-databases/security/auditing/sql-server-audit-database-engine)
This quickstart describes how to connect an application to a database in Azure SQL Database and perform queries using .NET and the [Microsoft.Data.SqlClient](https://www.nuget.org/packages/Microsoft.Data.SqlClient) library. This quickstart follows the recommended passwordless approach to connect to the database. You can learn more about passwordless connections on the [passwordless hub](/azure/developer/intro/passwordless-overview).
19
20
20
21
## Prerequisites
21
22
22
-
* An [Azure subscription](https://azure.microsoft.com/free/dotnet/).
23
-
* An Azure SQL database configured for authentication with Microsoft Entra ID ([formerly Azure Active Directory](/entra/fundamentals/new-name)). You can create one using the [Create database quickstart](./single-database-create-quickstart.md).
24
-
* The latest version of the [Azure CLI](/cli/azure/get-started-with-azure-cli).
25
-
*[Visual Studio](https://visualstudio.microsoft.com/vs/) or later with the **ASP.NET and web development** workload.
26
-
*[.NET 7.0](https://dotnet.microsoft.com/download) or later.
23
+
- An [Azure subscription](https://azure.microsoft.com/free/dotnet/).
24
+
- An Azure SQL database configured for authentication with Microsoft Entra ID ([formerly Azure Active Directory](/entra/fundamentals/new-name)). You can create one using the [Create database quickstart](single-database-create-quickstart.md).
25
+
- The latest version of the [Azure CLI](/cli/azure/get-started-with-azure-cli).
26
+
-[Visual Studio](https://visualstudio.microsoft.com/vs/) or later with the **ASP.NET and web development** workload.
27
+
-[.NET 7.0](https://dotnet.microsoft.com/download) or later.
27
28
28
29
## Configure the database
29
30
@@ -41,7 +42,7 @@ For the steps ahead, create a .NET Minimal Web API using either the .NET CLI or
41
42
42
43
1. For the **Project Name**, enter *DotNetSQL*. Leave the default values for the rest of the fields and select **Next**.
43
44
44
-
1. For the **Framework**, select .NET 7.0 and uncheck **Use controllers (uncheck to use minimal APIs)**. This quickstart uses a Minimal API template to streamline endpoint creation and configuration.
45
+
1. For the **Framework**, select .NET 7.0 and uncheck **Use controllers (uncheck to use minimal APIs)**. This quickstart uses a Minimal API template to streamline endpoint creation and configuration.
45
46
46
47
1. Choose **Create**. The new project opens inside the Visual Studio environment.
47
48
@@ -61,7 +62,7 @@ For the steps ahead, create a .NET Minimal Web API using either the .NET CLI or
61
62
62
63
To connect to Azure SQL Database by using .NET, install `Microsoft.Data.SqlClient`. This package acts as a data provider for connecting to databases, executing commands, and retrieving results.
63
64
64
-
> [!NOTE]
65
+
> [!NOTE]
65
66
> Make sure to install `Microsoft.Data.SqlClient` and not `System.Data.SqlClient`. `Microsoft.Data.SqlClient` is a newer version of the SQL client library that provides additional capabilities.
66
67
67
68
## [Visual Studio](#tab/visual-studio)
@@ -96,7 +97,7 @@ The passwordless connection string sets a configuration value of `Authentication
96
97
97
98
For example, when the app runs locally, `DefaultAzureCredential` authenticates via the user you're signed into Visual Studio with, or other local tools like the Azure CLI. Once the app deploys to Azure, the same code discovers and applies the managed identity that is associated with the hosted app, which you'll configure later. The [Azure Identity library overview](/dotnet/api/overview/azure/Identity-readme#defaultazurecredential) explains the order and locations in which `DefaultAzureCredential` looks for credentials.
98
99
99
-
> [!NOTE]
100
+
> [!NOTE]
100
101
> Passwordless connection strings are safe to commit to source control, since they don't contain secrets such as usernames, passwords, or access keys.
101
102
102
103
## [SQL Authentication](#tab/sql-auth)
@@ -109,7 +110,7 @@ For local development with SQL Authentication to Azure SQL Database, add the fol
109
110
}
110
111
```
111
112
112
-
> [!WARNING]
113
+
> [!WARNING]
113
114
> Use caution when managing connection strings that contain secrets such as usernames, passwords, or access keys. These secrets shouldn't be committed to source control or placed in unsecure locations where they might be accessed by unintended users. During local development, on a real app, you'll generally connect to a local database that doesn't require storing secrets or connecting directly to Azure.
114
115
115
116
---
@@ -118,10 +119,10 @@ For local development with SQL Authentication to Azure SQL Database, add the fol
118
119
119
120
Replace the contents of the `Program.cs` file with the following code, which performs the following important steps:
120
121
121
-
* Retrieves the passwordless connection string from `appsettings.json`
122
-
* Creates a `Persons` table in the database during startup (for testing scenarios only)
123
-
* Creates an HTTP GET endpoint to retrieve all records stored in the `Persons` table
124
-
* Creates an HTTP POST endpoint to add new records to the `Persons` table
122
+
- Retrieves the passwordless connection string from `appsettings.json`
123
+
- Creates a `Persons` table in the database during startup (for testing scenarios only)
124
+
- Creates an HTTP GET endpoint to retrieve all records stored in the `Persons` table
125
+
- Creates an HTTP POST endpoint to add new records to the `Persons` table
125
126
126
127
```csharp
127
128
usingMicrosoft.Data.SqlClient;
@@ -221,9 +222,9 @@ The app is ready to be tested locally. Make sure you're signed in to Visual Stud
221
222
222
223
1) On the Swagger UI page, expand the POST method and select **Try it**.
223
224
224
-
1) Modify the sample JSON to include values for the first and last name. Select **Execute** to add a new record to the database. The API returns a successful response.
225
+
1) Modify the sample JSON to include values for the `first` and `last` name. Select **Execute** to add a new record to the database. The API returns a successful response.
225
226
226
-
:::image type="content" source="media/passwordless-connections/api-testing-small.png" lightbox="media/passwordless-connections/api-testing.png" alt-text="A screenshot showing how to test the API.":::
227
+
:::image type="content" source="media/passwordless-connections/api-testing-small.png" alt-text="Screenshot showing how to test the API." lightbox="media/passwordless-connections/api-testing.png":::
227
228
228
229
1) Expand the **GET** method on the Swagger UI page and select **Try it**. Choose **Execute**, and the person you just created is returned.
229
230
@@ -243,11 +244,11 @@ The app is ready to be deployed to Azure. Visual Studio can create an Azure App
243
244
***Hosting Plan**: Select **New** to open the hosting plan dialog. Leave the default values and select **OK**.
244
245
* Select **Create** to close the original dialog. Visual Studio creates the App Service resource in Azure.
245
246
246
-
:::image type="content" source="media/passwordless-connections/create-app-service-small.png" lightbox="media/passwordless-connections/create-app-service.png" alt-text="A screenshot showing how to deploy with Visual Studio.":::
247
+
:::image type="content" source="media/passwordless-connections/create-app-service-small.png" alt-text="Screenshot showing how to deploy with Visual Studio." lightbox="media/passwordless-connections/create-app-service.png":::
247
248
248
249
1. Once the resource is created, make sure it's selected in the list of app services, and then select **Next**.
249
250
1. On the **API Management** step, select the **Skip this step** checkbox at the bottom and then choose **Finish**.
250
-
1. On the Finish step, select **Close** if the dialog does not close automatically.
251
+
1. On the Finish step, select **Close** if the dialog doesn't close automatically.
251
252
252
253
1. Select **Publish** in the upper right of the publishing profile summary to deploy the app to Azure.
253
254
@@ -273,9 +274,13 @@ When the deployment finishes, Visual Studio launches the browser to display the
273
274
274
275
3) Execute test GET and POST requests to verify that the endpoints work as expected.
275
276
276
-
> [!TIP]
277
-
> If you receive a 500 Internal Server error while testing, it may be due to your database networking configurations. Verify that your logical server is configured with the settings outlined in the [Configure the database](/azure/azure-sql/database/azure-sql-dotnet-quickstart#configure-the-database) section.
277
+
> [!TIP]
278
+
> If you receive a 500 Internal Server error while testing, it might be due to your database networking configurations. Verify that your logical server is configured with the settings outlined in the [Configure the database](/azure/azure-sql/database/azure-sql-dotnet-quickstart#configure-the-database) section.
278
279
279
-
Congratulations! Your application is now connected to Azure SQL Database in both local and hosted environments.
280
+
Your application is now connected to Azure SQL Database in both local and hosted environments.
0 commit comments