> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/appsec-rules/iac-security/storage/appsec2-azure-16.md).

# MySQL server does not enable customer-managed key for encryption misconfiguration detected in code

## Rule Details

|                        |                           |
| ---------------------- | ------------------------- |
| Cortex AppSec Rule ID  | APPSEC2\_AZURE\_16        |
| Category - Subcategory | Storage - Encryption      |
| Provider               | AZURE                     |
| Severity               | LOW                       |
| Framework              | Terraform, Terraform Plan |

## Impact

Use customer-managed keys to manage the encryption at rest of your MySQL servers. By default, the data is encrypted at rest with service-managed keys, but customer-managed keys are commonly required to meet regulatory compliance standards. Customer-managed keys enable the data to be encrypted with an Azure Key Vault key created and owned by you. You have full control and responsibility for the key lifecycle, including rotation and management.

## How to Fix

## *Resource:* azurerm\_resource\_group,azurerm\_key\_vault, azurerm\_key\_vault\_access\_policy, azurerm\_key\_vault\_key, azurerm\_mysql\_server, azurerm\_mysql\_server\_key \[source,go]

{ "resource "azurerm\_resource\_group" "ok" { name = "ok-resources" location = "West Europe" }

resource "azurerm\_key\_vault" "ok" { name = "okkv" location = azurerm\_resource\_group.ok.location resource\_group\_name = azurerm\_resource\_group.ok.name tenant\_id = data.azurerm\_client\_config.current.tenant\_id sku\_name = "premium" purge\_protection\_enabled = true }

resource "azurerm\_key\_vault\_access\_policy" "server" { key\_vault\_id = azurerm\_key\_vault.ok.id tenant\_id = data.azurerm\_client\_config.current.tenant\_id object\_id = azurerm\_mysql\_server.ok.identity.0.principal\_id key\_permissions = \["get", "unwrapkey", "wrapkey"] secret\_permissions = \["get"] }

resource "azurerm\_key\_vault\_access\_policy" "client" { key\_vault\_id = azurerm\_key\_vault.ok.id tenant\_id = data.azurerm\_client\_config.current.tenant\_id object\_id = data.azurerm\_client\_config.current.object\_id key\_permissions = \["get", "create", "delete", "list", "restore", "recover", "unwrapkey", "wrapkey", "purge", "encrypt", "decrypt", "sign", "verify"] secret\_permissions = \["get"] }

resource "azurerm\_key\_vault\_key" "ok" { name = "tfex-key" key\_vault\_id = azurerm\_key\_vault.ok.id key\_type = "RSA" key\_size = 2048 key\_opts = \["decrypt", "encrypt", "sign", "unwrapKey", "verify", "wrapKey"] depends\_on = \[ azurerm\_key\_vault\_access\_policy.client, azurerm\_key\_vault\_access\_policy.server, ] }

resource "azurerm\_mysql\_server" "ok" { name = "ok-mysql-server" location = azurerm\_resource\_group.ok.location resource\_group\_name = azurerm\_resource\_group.ok.name sku\_name = "GP\_Gen5\_2" administrator\_login = "acctestun" administrator\_login\_password = "H\@Sh1CoR3!" ssl\_enforcement\_enabled = true ssl\_minimal\_tls\_version\_enforced = "TLS1\_1" storage\_mb = 51200 version = "5.6"

identity { type = "SystemAssigned" }

}

resource "azurerm\_mysql\_server\_key" "ok" { server\_id = azurerm\_mysql\_server.ok.id key\_vault\_key\_id = azurerm\_key\_vault\_key.ok.id }

## ", }


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://cortex-docs.paloaltonetworks.com/appsec-rules/iac-security/storage/appsec2-azure-16.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
