Gallery › Cognitive Services › Azure built-in policies
[Preview]: Azure AI Services RAI egress headers should use safe operations, references, and HTTPS
Converted Policy Audit Deny Disabled Mode All Version 1.0.0-preview Preview
Require safe header operations, reference-based header values, valid secret or managed identity references, and HTTPS for credential-bearing RAI egress rewrites. Does not validate runtime mode or network destination restrictions.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONRaiPolicyEgressHeaderCredentialSafety_Audit.json · 158 lines
{
"properties": {
"displayName": "[Preview]: Azure AI Services RAI egress headers should use safe operations, references, and HTTPS",
"policyType": "BuiltIn",
"mode": "All",
"description": "Require safe header operations, reference-based header values, valid secret or managed identity references, and HTTPS for credential-bearing RAI egress rewrites. Does not validate runtime mode or network destination restrictions.",
"metadata": {
"version": "1.0.0-preview",
"category": "Cognitive Services",
"preview": true
},
"version": "1.0.0-preview",
"parameters": {
"effect": {
"type": "String",
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"defaultValue": "Audit",
"metadata": {
"displayName": "Effect",
"description": "Audit, deny, or disable these authoring checks. Does not change runtime egress mode."
}
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.CognitiveServices/accounts/raiPolicies"
},
{
"count": {
"field": "Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*]",
"where": {
"allOf": [
{
"field": "Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.actionType",
"in": [
"Transform",
"Rewrite"
]
},
{
"anyOf": [
{
"count": {
"field": "Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*]",
"where": {
"anyOf": [
{
"field": "Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].operation",
"notIn": [
"Set",
"Insert",
"Remove"
]
},
{
"value": "[empty(trim(string(current('Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].name'))))]",
"equals": true
},
{
"value": "[not(equals(tryGet(current('Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*]'), 'value'), json('null')))]",
"equals": true
},
{
"allOf": [
{
"field": "Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].operation",
"equals": "Remove"
},
{
"value": "[not(equals(tryGet(current('Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*]'), 'valueRef'), json('null')))]",
"equals": true
}
]
},
{
"allOf": [
{
"field": "Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].operation",
"in": [
"Set",
"Insert"
]
},
{
"anyOf": [
{
"value": "[equals(equals(tryGet(coalesce(current('Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef'), json('{}')), 'secretRef'), json('null')), equals(tryGet(coalesce(current('Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef'), json('{}')), 'managedIdentityRef'), json('null')))]",
"equals": true
},
{
"value": "[if(equals(tryGet(coalesce(current('Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef'), json('{}')), 'secretRef'), json('null')), false(), not(and(equals(tryGet(coalesce(tryGet(coalesce(current('Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef'), json('{}')), 'secretRef'), json('{}')), 'secretId'), string(tryGet(coalesce(tryGet(coalesce(current('Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef'), json('{}')), 'secretRef'), json('{}')), 'secretId'))), not(empty(trim(string(tryGet(coalesce(tryGet(coalesce(current('Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef'), json('{}')), 'secretRef'), json('{}')), 'secretId'))))))))]",
"equals": true
},
{
"value": "[if(equals(tryGet(coalesce(current('Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef'), json('{}')), 'managedIdentityRef'), json('null')), false(), not(and(equals(tryGet(coalesce(tryGet(coalesce(current('Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef'), json('{}')), 'managedIdentityRef'), json('{}')), 'resource'), string(tryGet(coalesce(tryGet(coalesce(current('Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef'), json('{}')), 'managedIdentityRef'), json('{}')), 'resource'))), not(empty(trim(string(tryGet(coalesce(tryGet(coalesce(current('Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef'), json('{}')), 'managedIdentityRef'), json('{}')), 'resource'))))))))]",
"equals": true
}
]
}
]
}
]
}
},
"greater": 0
},
{
"allOf": [
{
"field": "Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.actionType",
"equals": "Rewrite"
},
{
"count": {
"field": "Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*]",
"where": {
"field": "Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].operation",
"in": [
"Set",
"Insert"
]
}
},
"greater": 0
},
{
"field": "Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.rewrite.scheme",
"notEquals": "https"
}
]
}
]
}
]
}
},
"greater": 0
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"versions": [
"1.0.0-PREVIEW"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/29be091c-88f9-419b-8ad9-82ce5dc452d3",
"name": "29be091c-88f9-419b-8ad9-82ce5dc452d3"
}Bylaw29be091c-88f9-419b-8ad9-82ce5dc452d3.bylaw.ps1 · 61 lines
# Converted from RaiPolicyEgressHeaderCredentialSafety_Audit.json by ConvertTo-Bylaw.
Policy '29be091c-88f9-419b-8ad9-82ce5dc452d3' {
Properties @{
DisplayName = '[Preview]: Azure AI Services RAI egress headers should use safe operations, references, and HTTPS'
Description = 'Require safe header operations, reference-based header values, valid secret or managed identity references, and HTTPS for credential-bearing RAI egress rewrites. Does not validate runtime mode or network destination restrictions.'
Version = '1.0.0-preview'
Category = 'Cognitive Services'
Preview = $true
PolicyVersion = '1.0.0-preview'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('Audit', 'Deny', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Audit, deny, or disable these authoring checks. Does not change runtime egress mode.'
}
Resource 'Microsoft.CognitiveServices/accounts/raiPolicies' {
Require 'egressPolicy.rules, action.actionType, action.headers and 2 more are as required' {
Each 'egressPolicy.rules[*]' {
AnyOf {
Field action.actionType | Must -Not -BeIn @('Transform', 'Rewrite')
AllOf {
Count 'action.headers[*]' -Where {
AnyOf {
Field operation | Must -Not -BeIn @('Set', 'Insert', 'Remove')
Arm '[empty(trim(string(current(''Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].name''))))]' | Must -Be $true
Arm '[not(equals(tryGet(current(''Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*]''), ''value''), json(''null'')))]' | Must -Be $true
AllOf {
Field operation | Must -Be 'Remove'
Arm '[not(equals(tryGet(current(''Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*]''), ''valueRef''), json(''null'')))]' | Must -Be $true
}
AllOf {
Field operation | Must -BeIn @('Set', 'Insert')
AnyOf {
Arm '[equals(equals(tryGet(coalesce(current(''Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef''), json(''{}'')), ''secretRef''), json(''null'')), equals(tryGet(coalesce(current(''Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef''), json(''{}'')), ''managedIdentityRef''), json(''null'')))]' | Must -Be $true
Arm '[if(equals(tryGet(coalesce(current(''Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef''), json(''{}'')), ''secretRef''), json(''null'')), false(), not(and(equals(tryGet(coalesce(tryGet(coalesce(current(''Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef''), json(''{}'')), ''secretRef''), json(''{}'')), ''secretId''), string(tryGet(coalesce(tryGet(coalesce(current(''Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef''), json(''{}'')), ''secretRef''), json(''{}'')), ''secretId''))), not(empty(trim(string(tryGet(coalesce(tryGet(coalesce(current(''Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef''), json(''{}'')), ''secretRef''), json(''{}'')), ''secretId''))))))))]' | Must -Be $true
Arm '[if(equals(tryGet(coalesce(current(''Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef''), json(''{}'')), ''managedIdentityRef''), json(''null'')), false(), not(and(equals(tryGet(coalesce(tryGet(coalesce(current(''Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef''), json(''{}'')), ''managedIdentityRef''), json(''{}'')), ''resource''), string(tryGet(coalesce(tryGet(coalesce(current(''Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef''), json(''{}'')), ''managedIdentityRef''), json(''{}'')), ''resource''))), not(empty(trim(string(tryGet(coalesce(tryGet(coalesce(current(''Microsoft.CognitiveServices/accounts/raiPolicies/egressPolicy.rules[*].action.headers[*].valueRef''), json(''{}'')), ''managedIdentityRef''), json(''{}'')), ''resource''))))))))]' | Must -Be $true
}
}
}
} | Must -Be 0
AnyOf {
Field action.actionType | Must -Not -Be 'Rewrite'
Each 'action.headers[*]' {
Field operation | Must -Not -BeIn @('Set', 'Insert')
}
Field action.rewrite.scheme | Must -Be 'https' -Strict
}
}
}
}
}
}
Effect (Param Effect)
}Source: built-in-policies/policyDefinitions/Cognitive Services/RaiPolicyEgressHeaderCredentialSafety_Audit.json in Azure/azure-policy, under the MIT licence.
Bylaw