Gallery › Data Factory › Azure built-in policies
Azure Data Factory linked services should use Key Vault for storing secrets
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
To ensure secrets (such as connection strings) are managed securely, require users to provide secrets using an Azure Key Vault instead of specifying them inline in linked services.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONLinkedService_InlineSecrets_Audit.json · 233 lines
{
"properties": {
"displayName": "Azure Data Factory linked services should use Key Vault for storing secrets",
"policyType": "BuiltIn",
"mode": "All",
"description": "To ensure secrets (such as connection strings) are managed securely, require users to provide secrets using an Azure Key Vault instead of specifying them inline in linked services.",
"metadata": {
"version": "1.0.0",
"category": "Data Factory"
},
"version": "1.0.0",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"defaultValue": "Audit"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.DataFactory/factories/linkedservices"
},
{
"anyOf": [
{
"allOf": [
{
"field": "Microsoft.DataFactory/factories/linkedservices/typeProperties.connectionString",
"exists": "true"
},
{
"anyOf": [
{
"field": "Microsoft.DataFactory/factories/linkedservices/typeProperties.connectionString",
"contains": "AccountKey="
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/typeProperties.connectionString",
"contains": "PWD="
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/typeProperties.connectionString",
"contains": "Password="
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/typeProperties.connectionString",
"contains": "CredString="
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/typeProperties.connectionString",
"contains": "pwd="
}
]
}
]
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/SqlServer.typeProperties.password.type",
"equals": "SecureString"
},
{
"allOf": [
{
"field": "Microsoft.DataFactory/factories/linkedservices/SqlServer.typeProperties.password",
"exists": "true"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/SqlServer.typeProperties.password.type",
"exists": "false"
}
]
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/AzureSqlDW.typeProperties.servicePrincipalKey.type",
"equals": "SecureString"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/AzureSearch.typeProperties.key.type",
"equals": "SecureString"
},
{
"allOf": [
{
"field": "Microsoft.DataFactory/factories/linkedservices/AzureStorage.typeProperties.sasUri",
"exists": "true"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/AzureStorage.typeProperties.sasUri.type",
"notEquals": "AzureKeyVaultSecret"
}
]
},
{
"allOf": [
{
"field": "Microsoft.DataFactory/factories/linkedservices/AzureBlobStorage.typeProperties.servicePrincipalKey",
"exists": "true"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/AzureBlobStorage.typeProperties.servicePrincipalKey.type",
"notEquals": "AzureKeyVaultSecret"
}
]
},
{
"allOf": [
{
"field": "Microsoft.DataFactory/factories/linkedservices/AzureStorage.typeProperties.accountKey",
"exists": "true"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/CosmosDb.typeProperties.accountKey.type",
"notEquals": "AzureKeyVaultSecret"
}
]
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/typeProperties.encryptedCredential",
"exists": "true"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/AmazonMWS.typeProperties.mwsAuthToken.type",
"equals": "SecureString"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/AmazonMWS.typeProperties.secretKey.type",
"equals": "SecureString"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/AmazonS3.typeProperties.secretAccessKey.type",
"equals": "SecureString"
},
{
"allOf": [
{
"field": "Microsoft.DataFactory/factories/linkedservices/Dynamics.typeProperties.servicePrincipalCredential",
"exists": "true"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/Dynamics.typeProperties.servicePrincipalCredential.type",
"equals": "SecureString"
}
]
},
{
"allOf": [
{
"field": "Microsoft.DataFactory/factories/linkedservices/Hubspot.typeProperties.accessToken",
"exists": "true"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/Hubspot.typeProperties.accessToken.type",
"equals": "SecureString"
}
]
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/Odbc.typeProperties.credential.type",
"equals": "SecureString"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/GoogleAdWords.typeProperties.developerToken.type",
"equals": "SecureString"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/GoogleBigQuery.typeProperties.clientSecret.type",
"equals": "SecureString"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/GoogleBigQuery.typeProperties.refreshToken.type",
"equals": "SecureString"
},
{
"allOf": [
{
"field": "Microsoft.DataFactory/factories/linkedservices/type",
"in": [
"MongoDbAtlas",
"MongoDbV2"
]
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/typeProperties.connectionString.type",
"notEquals": "AzureKeyVaultSecret"
}
]
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/OData.typeProperties.servicePrincipalEmbeddedCert.type",
"equals": "SecureString"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/OData.typeProperties.servicePrincipalEmbeddedCertPassword.type",
"equals": "SecureString"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/Sftp.typeProperties.privateKeyContent.type",
"equals": "SecureString"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/Sftp.typeProperties.passPhrase.type",
"equals": "SecureString"
},
{
"field": "Microsoft.DataFactory/factories/linkedservices/Salesforce.typeProperties.securityToken.type",
"equals": "SecureString"
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"versions": [
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/127ef6d7-242f-43b3-9eef-947faf1725d0",
"name": "127ef6d7-242f-43b3-9eef-947faf1725d0"
}Bylaw127ef6d7-242f-43b3-9eef-947faf1725d0.bylaw.ps1 · 150 lines
# Converted from LinkedService_InlineSecrets_Audit.json by ConvertTo-Bylaw.
Policy '127ef6d7-242f-43b3-9eef-947faf1725d0' {
Properties @{
DisplayName = 'Azure Data Factory linked services should use Key Vault for storing secrets'
Description = 'To ensure secrets (such as connection strings) are managed securely, require users to provide secrets using an Azure Key Vault instead of specifying them inline in linked services.'
Version = '1.0.0'
Category = 'Data Factory'
PolicyVersion = '1.0.0'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('Audit', 'Deny', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Resource 'Microsoft.DataFactory/factories/linkedservices' {
Require 'typeProperties.connectionString is as required' {
AnyOf {
Field typeProperties.connectionString | Must -Not -Exist
AllOf {
Field typeProperties.connectionString | Must -Not -ContainText 'AccountKey=' -IfPresent
Field typeProperties.connectionString | Must -Not -ContainText 'PWD=' -IfPresent
Field typeProperties.connectionString | Must -Not -ContainText 'Password=' -IfPresent
Field typeProperties.connectionString | Must -Not -ContainText 'CredString=' -IfPresent
Field typeProperties.connectionString | Must -Not -ContainText 'pwd=' -IfPresent
}
}
}
Require 'SqlServer.typeProperties.password.type is not SecureString' {
Field SqlServer.typeProperties.password.type | Must -Not -Be 'SecureString' -IfPresent
}
Require 'SqlServer.typeProperties.password and SqlServer.typeProperties.password.type are as required' {
AnyOf {
Field SqlServer.typeProperties.password | Must -Not -Exist
Field SqlServer.typeProperties.password.type | Must -Exist
}
}
Require 'AzureSqlDW.typeProperties.servicePrincipalKey.type is not SecureString' {
Field AzureSqlDW.typeProperties.servicePrincipalKey.type | Must -Not -Be 'SecureString' -IfPresent
}
Require 'AzureSearch.typeProperties.key.type is not SecureString' {
Field AzureSearch.typeProperties.key.type | Must -Not -Be 'SecureString' -IfPresent
}
Require 'AzureStorage.typeProperties.sasUri and AzureStorage.typeProperties.sasUri.type are as required' {
AnyOf {
Field AzureStorage.typeProperties.sasUri | Must -Not -Exist
Field AzureStorage.typeProperties.sasUri.type | Must -Be 'AzureKeyVaultSecret'
}
}
Require 'AzureBlobStorage.typeProperties.servicePrincipalKey and AzureBlobStorage.typeProperties.servicePrincipalKey.type are as required' {
AnyOf {
Field AzureBlobStorage.typeProperties.servicePrincipalKey | Must -Not -Exist
Field AzureBlobStorage.typeProperties.servicePrincipalKey.type | Must -Be 'AzureKeyVaultSecret'
}
}
Require 'AzureStorage.typeProperties.accountKey and CosmosDb.typeProperties.accountKey.type are as required' {
AnyOf {
Field AzureStorage.typeProperties.accountKey | Must -Not -Exist
Field CosmosDb.typeProperties.accountKey.type | Must -Be 'AzureKeyVaultSecret'
}
}
Require 'typeProperties.encryptedCredential does not exist' {
Field typeProperties.encryptedCredential | Must -Not -Exist
}
Require 'AmazonMWS.typeProperties.mwsAuthToken.type is not SecureString' {
Field AmazonMWS.typeProperties.mwsAuthToken.type | Must -Not -Be 'SecureString' -IfPresent
}
Require 'AmazonMWS.typeProperties.secretKey.type is not SecureString' {
Field AmazonMWS.typeProperties.secretKey.type | Must -Not -Be 'SecureString' -IfPresent
}
Require 'AmazonS3.typeProperties.secretAccessKey.type is not SecureString' {
Field AmazonS3.typeProperties.secretAccessKey.type | Must -Not -Be 'SecureString' -IfPresent
}
Require 'Dynamics.typeProperties.servicePrincipalCredential and Dynamics.typeProperties.servicePrincipalCredential.type are as required' {
AnyOf {
Field Dynamics.typeProperties.servicePrincipalCredential | Must -Not -Exist
Field Dynamics.typeProperties.servicePrincipalCredential.type | Must -Not -Be 'SecureString' -IfPresent
}
}
Require 'Hubspot.typeProperties.accessToken and Hubspot.typeProperties.accessToken.type are as required' {
AnyOf {
Field Hubspot.typeProperties.accessToken | Must -Not -Exist
Field Hubspot.typeProperties.accessToken.type | Must -Not -Be 'SecureString' -IfPresent
}
}
Require 'Odbc.typeProperties.credential.type is not SecureString' {
Field Odbc.typeProperties.credential.type | Must -Not -Be 'SecureString' -IfPresent
}
Require 'GoogleAdWords.typeProperties.developerToken.type is not SecureString' {
Field GoogleAdWords.typeProperties.developerToken.type | Must -Not -Be 'SecureString' -IfPresent
}
Require 'GoogleBigQuery.typeProperties.clientSecret.type is not SecureString' {
Field GoogleBigQuery.typeProperties.clientSecret.type | Must -Not -Be 'SecureString' -IfPresent
}
Require 'GoogleBigQuery.typeProperties.refreshToken.type is not SecureString' {
Field GoogleBigQuery.typeProperties.refreshToken.type | Must -Not -Be 'SecureString' -IfPresent
}
Require 'type and typeProperties.connectionString.type are as required' {
AnyOf {
Field 'Microsoft.DataFactory/factories/linkedservices/type' | Must -Not -BeIn @('MongoDbAtlas', 'MongoDbV2') -IfPresent
Field typeProperties.connectionString.type | Must -Be 'AzureKeyVaultSecret'
}
}
Require 'OData.typeProperties.servicePrincipalEmbeddedCert.type is not SecureString' {
Field OData.typeProperties.servicePrincipalEmbeddedCert.type | Must -Not -Be 'SecureString' -IfPresent
}
Require 'OData.typeProperties.servicePrincipalEmbeddedCertPassword.type is not SecureString' {
Field OData.typeProperties.servicePrincipalEmbeddedCertPassword.type | Must -Not -Be 'SecureString' -IfPresent
}
Require 'Sftp.typeProperties.privateKeyContent.type is not SecureString' {
Field Sftp.typeProperties.privateKeyContent.type | Must -Not -Be 'SecureString' -IfPresent
}
Require 'Sftp.typeProperties.passPhrase.type is not SecureString' {
Field Sftp.typeProperties.passPhrase.type | Must -Not -Be 'SecureString' -IfPresent
}
Require 'Salesforce.typeProperties.securityToken.type is not SecureString' {
Field Salesforce.typeProperties.securityToken.type | Must -Not -Be 'SecureString' -IfPresent
}
}
Effect (Param Effect)
}Source: built-in-policies/policyDefinitions/Data Factory/LinkedService_InlineSecrets_Audit.json in Azure/azure-policy, under the MIT licence.
Bylaw