Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ of deployment capacity (20,000 for `gpt-latest` and `gpt-6-sol`; 200,000 for
`gpt-mini-latest`), a `$10.00/month` `costLimit` per caller identity
(`monthly-caller-budget`), and `Medium` `contentSafety` thresholds for Hate,
Self-Harm, Sexual, and Violence. The same content-safety thresholds are applied
to the `toolServers/github` MCP server. The `gpt-latest` alias fails over across
`gpt-6.1-sol` (priority 0), `gpt-6-sol` (priority 1), and `gpt-5.4-mini`
(priority 2). See the [AI Gateway module README](ai-gateway/README.md) for
module usage and configuration.
to the `toolServers/github` MCP server. You can also pass optional
`backendSubnetResourceId` (`properties.backend.subnet.id`, delegated to
`Microsoft.App/environments`) for outbound VNet integration and
`allowedCallerCidrRanges` for inbound caller IP filtering (`ipFilter`). The
`gpt-latest` alias fails over across `gpt-6.1-sol` (priority 0), `gpt-6-sol`
(priority 1), and `gpt-5.4-mini` (priority 2). See the [AI Gateway module
README](ai-gateway/README.md) for module usage and configuration.

## Deploy the full stack

Expand Down
9 changes: 7 additions & 2 deletions infra/ai-gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ deployment capacity per minute. With the sample capacities, `gpt-latest` and
identity (`id: monthly-caller-budget`) and `Medium` `contentSafety` thresholds
for Hate, Self-Harm, Sexual, and Violence. The postprovision configuration adds
the same `Medium` content-safety thresholds to the `toolServers/github` MCP
server. The `gpt-latest` alias routes through `gpt-6.1-sol` (priority 0),
`gpt-6-sol` (priority 1), and `gpt-5.4-mini` (priority 2).
server. You can optionally pass `allowedCallerCidrRanges` (for example
`['10.0.0.0/8']`) to add an inline `ipFilter` policy (`action: Allow`) to each
model registration, and `backendSubnetResourceId` (pointing to a subnet in the
same subscription and region delegated to `Microsoft.App/environments`) to
enable outbound VNet integration (`properties.backend.subnet.id`). The
`gpt-latest` alias routes through `gpt-6.1-sol` (priority 0), `gpt-6-sol`
(priority 1), and `gpt-5.4-mini` (priority 2).

## Gateway without a Foundry provider

Expand Down
78 changes: 51 additions & 27 deletions infra/ai-gateway/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ param foundryAgentsProjectPrincipalId string = ''
param principalId string = ''
param useManagedIdentityForFoundryConnections bool = true
param aiGatewayAudience string = 'https://azure-api.net/aigateway'
@description('Optional resource ID of an existing subnet in the same subscription and region, delegated to Microsoft.App/environments, for outbound VNet integration.')
param backendSubnetResourceId string = ''
@description('Optional CIDR ranges allowed to call registered models via an inline ipFilter policy. Leave empty to allow all caller IPs.')
param allowedCallerCidrRanges array = []
@secure()
param toolServerConfigs object = {}

Expand All @@ -34,6 +38,15 @@ var logAnalyticsApiVersion = '2023-09-01'
var telemetryWorkspaceName = 'default'
var aiGatewayUserRoleDefinitionId = 'caad7a21-134e-43f4-a550-c5ffc17e051c'
var normalizedFoundryEndpoint = endsWith(foundryEndpoint, '/') ? foundryEndpoint : '${foundryEndpoint}/'
var optionalIpFilterPolicies = empty(allowedCallerCidrRanges)
? []
: [
{
type: 'ipFilter'
action: 'Allow'
cidrRanges: allowedCallerCidrRanges
}
]
#disable-next-line BCP081
resource aiGateway 'Microsoft.ApiManagement/aigateways@2025-09-01-preview' = if (deployApimGatewayViaBicep) {
name: gatewayName
Expand All @@ -45,7 +58,15 @@ resource aiGateway 'Microsoft.ApiManagement/aigateways@2025-09-01-preview' = if
sku: {
name: 'Premium'
}
properties: {}
properties: empty(backendSubnetResourceId)
? {}
: {
backend: {
subnet: {
id: backendSubnetResourceId
}
}
}
}

#disable-next-line BCP081
Expand Down Expand Up @@ -130,32 +151,35 @@ resource foundryCatalogModels 'Microsoft.ApiManagement/aigateways/workspaces/mod
modelName: last(split(model.resourceId, '/'))
modelVersion: model.?modelVersion ?? null
}
policies: model.?policies ?? [
{
type: 'tokenLimit'
period: 'minute'
count: model.?tokenLimit ?? 10000
counterKey: [
'identity'
]
}
{
id: 'monthly-caller-budget'
type: 'costLimit'
period: 'month'
amount: model.?costLimit ?? 10
counterKey: [
'identity'
]
}
{
type: 'contentSafety'
hateSeverity: model.?contentSafetySeverity ?? 'Medium'
selfHarmSeverity: model.?contentSafetySeverity ?? 'Medium'
sexualSeverity: model.?contentSafetySeverity ?? 'Medium'
violenceSeverity: model.?contentSafetySeverity ?? 'Medium'
}
]
policies: model.?policies ?? concat(
[
{
type: 'tokenLimit'
period: 'minute'
count: model.?tokenLimit ?? 10000
counterKey: [
'identity'
]
}
{
id: 'monthly-caller-budget'
type: 'costLimit'
period: 'month'
amount: model.?costLimit ?? 10
counterKey: [
'identity'
]
}
{
type: 'contentSafety'
hateSeverity: model.?contentSafetySeverity ?? 'Medium'
selfHarmSeverity: model.?contentSafetySeverity ?? 'Medium'
sexualSeverity: model.?contentSafetySeverity ?? 'Medium'
violenceSeverity: model.?contentSafetySeverity ?? 'Medium'
}
],
optionalIpFilterPolicies
)
}
}]

Expand Down
37 changes: 28 additions & 9 deletions infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ param agentLogAnalyticsWorkspaceName string = ''
@description('AI Gateway resource name. Defaults to a deterministic name.')
param aiGatewayName string = ''

@description('Optional resource ID of an existing subnet in the same subscription and region, delegated to Microsoft.App/environments, for AI Gateway outbound VNet integration.')
param backendSubnetResourceId string = ''

@description('Optional CIDR ranges allowed to call registered models and MCP tool servers via an inline ipFilter policy. Leave empty to allow all caller IPs.')
param allowedCallerCidrRanges array = []

@description('Default GitHub repository for the daily digest automation.')
param githubRepository string = 'microsoft/agent-framework'

Expand Down Expand Up @@ -272,6 +278,8 @@ module aiGateway './ai-gateway/main.bicep' = {
foundryAgentsAccountPrincipalId: foundryAgents.outputs.aiServicesPrincipalId
foundryAgentsProjectPrincipalId: foundryAgents.outputs.aiProjectPrincipalId
principalId: principalId
backendSubnetResourceId: backendSubnetResourceId
allowedCallerCidrRanges: allowedCallerCidrRanges
tags: tags
enableMonitoring: enableMonitoring
deployApimGatewayViaBicep: true
Expand Down Expand Up @@ -326,15 +334,26 @@ module aiGateway './ai-gateway/main.bicep' = {
description: 'Read-only GitHub tools for repository digests.'
type: 'mcp'
failureMode: 'failClosed'
policies: [
{
type: 'contentSafety'
hateSeverity: 'Medium'
selfHarmSeverity: 'Medium'
sexualSeverity: 'Medium'
violenceSeverity: 'Medium'
}
]
policies: concat(
[
{
type: 'contentSafety'
hateSeverity: 'Medium'
selfHarmSeverity: 'Medium'
sexualSeverity: 'Medium'
violenceSeverity: 'Medium'
}
],
empty(allowedCallerCidrRanges)
? []
: [
{
type: 'ipFilter'
action: 'Allow'
cidrRanges: allowedCallerCidrRanges
}
]
)
endpoints: [
{
namespace: 'github'
Expand Down
10 changes: 10 additions & 0 deletions tests/test-ai-gateway-model-registration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@ if ! jq -e '
exit 1
fi

if ! jq -e '
.parameters.backendSubnetResourceId.defaultValue == ""
and .parameters.allowedCallerCidrRanges.defaultValue == []
and (.variables.optionalIpFilterPolicies | tostring | contains("ipFilter") and contains("allowedCallerCidrRanges"))
and (.resources[] | select(.type == "Microsoft.ApiManagement/aigateways") | .properties | tostring | contains("backend") and contains("subnet") and contains("backendSubnetResourceId"))
' "$compiled_template" >/dev/null; then
echo "AI Gateway module must expose optional backendSubnetResourceId (properties.backend.subnet.id) and allowedCallerCidrRanges (ipFilter policy)." >&2
exit 1
fi

for hook in "$repo_root/infra/scripts/configure-ai-gateway.sh" "$repo_root/infra/scripts/configure-ai-gateway.ps1"; do
if grep -Eq 'azd[[:space:]]+ai[[:space:]]+connection[[:space:]]+create|--custom-key' "$hook"; then
echo "Postprovision must not create the Bicep-owned connection or pass its key to a connection command." >&2
Expand Down
Loading