-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for writing SQL Audit logs to storage account with firewall enabled #6906
Comments
Hi @sean-nixon , thanks for opening this issue. There is another way to set sql server logs into a storage account with firewall or vn, which is to set the current service principal as the administrator of the sql server. Currently in release 2.10.0, I have merged a PR #6822 to support set AAD admin of
|
@yupwei68 Thanks for the response. I guess I missed your PR and previously closed issue since I only searched open issues. I was wondering if you could point me to the documentation that describes the approach of using Azure AD Administrator credentials for this? Everything I can find now specifies using the server's managed identity. I vaguely remember reading something similar a while back though. As I linked above, this capability to send audit logs to storage accounts behind a firewall only recently became generally available. I'm wondering if it's possible that using the AAD administrator credentials was the pre-GA recommendation on how to do it prior to this latest announcement. I believe it's theoretically possible for us to just use the AAD admin approach, but we would like to do it the "official" way if possible. |
hi @sean-nixon , sorry that I currently could not find the document for it. But I have written this case into acctest in the PR above(test with pass), on the other hand, I have an error message on portal suggest that we shall assign sql server administrator before we audit it to a storage account behind firewall. |
@yupwei68 When and in what region did you perform the test associated with the screenshot? That doesn't match up with my experience. Just now, I created a new SQL server in East US, did not configure an AAD administrator on it, and successfully applied auditing settings configured to log to a storage account behind a firewall all through the Portal. In the role assignments on the storage account, it shows the server has having blob data contributor access: I think this is a more streamlined experience as it does not introduce the dependency of having AAD administrator configured. |
@yupwei68 thanks so much for your effort on this I spotted a few things and would like to ask you some questions
|
Hi @hashitop ,@sean-nixon ,Thanks for your comments. |
That's great news! Thank you @yupwei68 |
@yupwei68 thank you! |
@yupwei68 is similar feature (external resource |
Removed milestone as PR #7793 is only a partial fix for this issue and it will be resolved fully in a follow up PR shortly... |
Using AzureRM version 2.33.0 the terraform is completing successfully but the auditing is not being enabled in the Azure portal: My terraform resource
My storage account has a firewall enabled and I am able to successfully setup SQL auditing with that storage account using the Azure Portal, but running the terraform does not make any changes to the SQL auditing |
This is working for me on 2.33 and an azurerm_role_assignment of Storage Blob Data Contributor on the storage account.
|
Looks like you can set auditing at both the server level and the DB level. I was using I think this issue is resolved and can be closed |
@mleziva / @peteneville , Can you please share the full terraform code if it resolved your issues on this scenario. |
resource "azurerm_mssql_server" "Azure_sqlserver" { resource "azurerm_sql_database" "SQL_database01" { resource "azurerm_sql_active_directory_administrator" "sql_active_directory_administrator" { resource "azurerm_role_assignment" "data-contributor-role" { resource "azurerm_mssql_server_extended_auditing_policy" "database_server_main" { ################getting below error############## on main.tf line 185, in resource "azurerm_role_assignment" "data-contributor-role": Error: waiting for creation of MsSql Server "n0-server-sql" Extended Auditing Policy (Resource Group "n01-dev-rg-t"): Code="BlobAuditingInsufficientStorageAccountPermissions" Message="Insufficient read or write permissions on storage account 'nesdsda824'. " on main.tf line 191, in resource "azurerm_mssql_server_extended_auditing_policy" "database_server_main": |
@jayanthrajanna, looks like you are using an application instead of the managed identity of the sql server for the principal being assigned "Storage Blob Data Contributor" role. The resource snippet I used for the role is below:
|
Hello @mleziva , Thanks for your response. I applied the changes as you stated above, I am now able to create a role definition with system assigned managed identity. But the change is not applying. The code runs but at the end it displays below error. Error: waiting for creation of MsSql Server "" Extended Auditing Policy (Resource Group ""): Code="InternalServerError" Message="An unexpected error occured while processing the request. Tracking ID: ''" I tried to execute multiple times but i am getting same error. Can you please help what can be the solution for this. |
Hi @sean-nixon would you please close this issue because it has been solved? |
I am still hitting this and getting error with azure provider version 2.65.0 Terraform v0.13.5 , was it ever solved .
|
Hi @yupwei68 I am getting here is my codebase resource "azurerm_role_assignment" "audit_primary" {
scope = azurerm_storage_account.sqlserver_sa.id
role_definition_name = "Storage Blob Data Contributor"
principal_id = azurerm_sql_server.sqlserver_primary.identity[0].principal_id
}
resource "azurerm_mssql_server_extended_auditing_policy" "primary-audit-enable" {
depends_on = [
azurerm_role_assignment.audit_primary
]
server_id = azurerm_sql_server.sqlserver_primary.id
storage_endpoint = azurerm_storage_account.sqlserver_sa.primary_blob_endpoint
storage_account_access_key = azurerm_storage_account.sqlserver_sa.primary_access_key
storage_account_access_key_is_secondary = false
retention_in_days = 90
} If I enable the audit policy using the below AZ CLI command, it works fine without any issue.
any suggestions? EDIT |
I assigned resource "azurerm_role_assignment" "sqlserver01" {
scope = azurerm_storage_account.diagst.id
role_definition_name = "Owner"
principal_id = azurerm_mssql_server.sqlserver01.identity.0.principal_id
}
resource "azurerm_mssql_server_extended_auditing_policy" "auditing" {
server_id = azurerm_mssql_server.sqlserver01.id
storage_endpoint = azurerm_storage_account.diagst.primary_blob_endpoint
retention_in_days = 180
depends_on = [
azurerm_private_dns_a_record.diagrecord,
azurerm_role_assignment.sqlserver01
]
} Then, I got to know about this Azure/azure-rest-api-specs#10258. Not sure if this is the latest decision as well. |
Any update on this issue? |
Thanks for opening this issue. This was a problem in the 2.x version of the provider which is no longer actively maintained and should be solved by #8447. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Community Note
Description
The ability to configure Azure SQL Server to send server audit logs to a storage account with virtual network rules (firewall) enabled was recently announced to be generally available (see references for announcement link). The organization I am working with would like to enable this using Terraform to improve our security posture around audit log storage.
The procedure to enable this is as follows:
Currently, this workflow is impossible to accomplish with Terraform for the following reasons:
storage_account_access_key
is REQUIRED within theazurerm_mssql_server
resource. This should not be set in order to log to storage accounts with firewall enabledextended_auditing_policy
is an inline block of theazurerm_mssql_server
, requiring the auditing settings to be set at the same time as the server creation. Because the SystemAssigned identity won't be available until AFTER the server is created, it's impossible to satisfy the prerequisites of assigning the Blob Contributor role to the server identity without doing threeterraform apply
runs -- one to create the server, one to create the role assignment, and one to update the auditing settings on the server.I think a new dedicated resource for server auditing settings should be created to work around this. The
extended_auditing_policy
could then be either deprecated or maintained as an optional (incompatible) alternative. The new dedicated resource would allow the auditing settings to be configured after the server and role assignment are created naturally using Terraform dependencies.New or Affected Resource(s)
Potential Terraform Configuration
References
Announcement: https://azure.microsoft.com/en-us/updates/azure-sql-auditing-to-storage-account-behind-virtual-network-and-firewall-now-generally-available/
Documentation: https://docs.microsoft.com/en-us/azure/sql-database/create-auditing-storage-account-vnet-firewall
Auditing settings API doc: https://docs.microsoft.com/en-us/rest/api/sql/server%20auditing%20settings/createorupdate
The text was updated successfully, but these errors were encountered: