{
  "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-preview",
      "category": "Data Factory",
      "preview": true
    },
    "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')]"
      }
    }
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/127ef6d7-242f-43b3-9eef-947faf1725d0",
  "name": "127ef6d7-242f-43b3-9eef-947faf1725d0"
}