Azure / template-analyzer

Template scanner for security misconfiguration and best practices
MIT License
125 stars 38 forks source link

[Built-in Rule] SQL managed instances should use customer-managed keys to encrypt data at rest #95

Open yane3628 opened 3 years ago

yane3628 commented 3 years ago

Azure Policy link: https://github.com/Azure/azure-policy/blob/master/built-in-policies/policyDefinitions/SQL/SqlManagedInstance_EnsureServerTDEisEncryptedWithYourOwnKey_Audit.json

{
  "name": "Sql_ManagedInstance_EnsureServerTDEisEncryptedWithYourOwnKey",
  "description": "SQL managed instances should use customer-managed keys to encrypt data at rest",
  "recommendation": "Implement Transparent Data Encryption (TDE) with your own key",
  "helpUri": "https://github.com/Azure/template-analyzer/docs/built-in-bpa-rules.md/#sql-managed-instances-should-use-customer-managed-keys-to-encrypt-data-at-rest",
  "evaluation": {
    "where": {
      "resourceType": "Microsoft.Sql/managedInstances",
      "path": "name",
      "hasValue": true
    },
    "evaluate": {
      "resourceType": "Microsoft.Sql/managedInstances/encryptionProtector",
      "anyOf": [
        {
          "path": "properties.serverKeyType",
          "notEquals": "AzureKeyVault"
        },
        {
          "path": "properties.uri",
          "equals": ""
        },
        {
          "field": "properties.uri",
          "exists": false
        }
      ]
    }
  }
}
yane3628 commented 3 years ago

uri is not part of the properties according to the Template schema docs. https://docs.microsoft.com/en-us/azure/templates/microsoft.sql/managedinstances/encryptionprotector?tabs=json#managedinstanceencryptionprotectorproperties-object

JohnathonMohr commented 3 years ago

I wonder if it's supposed to look at this schema instead: https://docs.microsoft.com/en-us/azure/templates/microsoft.sql/managedinstances/keys?tabs=json

JohnathonMohr commented 3 years ago

Looking at the schemas of encryptionProtector and keys, I wonder if it's supposed to be a combination of both. encryptionProtector might reference a key that's defined in the keys schema.

yane3628 commented 3 years ago

I'm not sure. I find it unlike the type is wrong in the Policy...

yane3628 commented 3 years ago

@JohnathonMohr This is likely a case of aliasing in action...