Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft PR: Private endpoint support for container apps #2322

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions infra/core/search/search-services.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ resource search 'Microsoft.Search/searchServices@2023-11-01' = {
}
sku: sku

// https://github.com/Azure/bicep-types-az/issues/2421
resource sharedPrivateLinkResource 'sharedPrivateLinkResources@2023-11-01' = [for (resourceId, i) in sharedPrivateLinkStorageAccounts: {
name: 'search-shared-private-link-${i}'
properties: {
Expand Down
23 changes: 11 additions & 12 deletions infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ module backend 'core/host/appservice.bicep' = if (deploymentTarget == 'appservic
appCommandLine: 'python3 -m gunicorn main:app'
scmDoBuildDuringDeployment: true
managedIdentity: true
virtualNetworkSubnetId: isolation.outputs.appSubnetId
virtualNetworkSubnetId: usePrivateEndpoint ? isolation.outputs.appSubnetId : ''
publicNetworkAccess: publicNetworkAccess
allowedOrigins: allowedOrigins
clientAppId: clientAppId
Expand Down Expand Up @@ -472,6 +472,7 @@ module containerApps 'core/host/container-apps.bicep' = if (deploymentTarget ==
containerAppsEnvironmentName: acaManagedEnvironmentName
containerRegistryName: '${containerRegistryName}${resourceToken}'
logAnalyticsWorkspaceResourceId: useApplicationInsights ? monitoring.outputs.logAnalyticsWorkspaceId : ''
virtualNetworkSubnetId: usePrivateEndpoint ? isolation.outputs.appSubnetId : ''
}
}

Expand Down Expand Up @@ -700,7 +701,7 @@ module searchService 'core/search/search-services.bicep' = {
publicNetworkAccess: publicNetworkAccess == 'Enabled'
? 'enabled'
: (publicNetworkAccess == 'Disabled' ? 'disabled' : null)
sharedPrivateLinkStorageAccounts: usePrivateEndpoint ? [storage.outputs.id] : []
sharedPrivateLinkStorageAccounts: (usePrivateEndpoint && useIntegratedVectorization) ? [storage.outputs.id] : []
}
}

Expand Down Expand Up @@ -1047,23 +1048,21 @@ module cosmosDbRoleBackend 'core/security/documentdb-sql-role.bicep' = if (useAu
}
}

module isolation 'network-isolation.bicep' = {
module isolation 'network-isolation.bicep' = if (usePrivateEndpoint) {
name: 'networks'
scope: resourceGroup
params: {
deploymentTarget: deploymentTarget
location: location
tags: tags
vnetName: '${abbrs.virtualNetworks}${resourceToken}'
// Need to check deploymentTarget due to https://github.com/Azure/bicep/issues/3990
appServicePlanName: deploymentTarget == 'appservice' ? appServicePlan.outputs.name : ''
usePrivateEndpoint: usePrivateEndpoint
containerAppsEnvName: acaManagedEnvironmentName
}
}

var environmentData = environment()

var openAiPrivateEndpointConnection = (isAzureOpenAiHost && deployAzureOpenAi && deploymentTarget == 'appservice')
var openAiPrivateEndpointConnection = (isAzureOpenAiHost && deployAzureOpenAi)
? [
{
groupId: 'account'
Expand All @@ -1076,7 +1075,7 @@ var openAiPrivateEndpointConnection = (isAzureOpenAiHost && deployAzureOpenAi &&
}
]
: []
var otherPrivateEndpointConnections = (usePrivateEndpoint && deploymentTarget == 'appservice')
var otherPrivateEndpointConnections = (usePrivateEndpoint)
? [
{
groupId: 'blob'
Expand All @@ -1089,9 +1088,9 @@ var otherPrivateEndpointConnections = (usePrivateEndpoint && deploymentTarget ==
resourceIds: [searchService.outputs.id]
}
{
groupId: 'sites'
dnsZoneName: 'privatelink.azurewebsites.net'
resourceIds: [backend.outputs.id]
groupId: 'managedEnvironments'
dnsZoneName: 'privatelink.${location}.azurecontainerapps.io'
resourceIds: [containerApps.outputs.environmentId]
}
{
groupId: 'cosmosdb'
Expand All @@ -1103,7 +1102,7 @@ var otherPrivateEndpointConnections = (usePrivateEndpoint && deploymentTarget ==

var privateEndpointConnections = concat(otherPrivateEndpointConnections, openAiPrivateEndpointConnection)

module privateEndpoints 'private-endpoints.bicep' = if (usePrivateEndpoint && deploymentTarget == 'appservice') {
module privateEndpoints 'private-endpoints.bicep' = if (usePrivateEndpoint) {
name: 'privateEndpoints'
scope: resourceGroup
params: {
Expand Down
39 changes: 12 additions & 27 deletions infra/network-isolation.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ param location string = resourceGroup().location
@description('The tags to apply to all resources')
param tags object = {}

@description('The name of an existing App Service Plan to connect to the VNet')
param appServicePlanName string

param usePrivateEndpoint bool = false

@allowed(['appservice', 'containerapps'])
param deploymentTarget string
param containerAppsEnvName string

resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' existing = if (deploymentTarget == 'appservice') {
name: appServicePlanName
resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' existing = {
name: containerAppsEnvName
}


module vnet './core/networking/vnet.bicep' = if (usePrivateEndpoint) {
name: 'vnet'
params: {
Expand All @@ -36,42 +33,30 @@ module vnet './core/networking/vnet.bicep' = if (usePrivateEndpoint) {
privateLinkServiceNetworkPolicies: 'Enabled'
}
}
{
name: 'AzureBastionSubnet'
properties: {
addressPrefix: '10.0.2.0/24'
privateEndpointNetworkPolicies: 'Enabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
}
{
{ // App Service / Container Apps specific subnet
name: 'app-int-subnet'
properties: {
addressPrefix: '10.0.3.0/24'
addressPrefix: '10.0.4.0/23'
privateEndpointNetworkPolicies: 'Enabled'
privateLinkServiceNetworkPolicies: 'Enabled'
delegations: [
{
id: appServicePlan.id
name: appServicePlan.name
id: containerAppsEnvironment.id
name: containerAppsEnvironment.name
properties: {
serviceName: 'Microsoft.Web/serverFarms'
serviceName: 'Microsoft.App/environments'
}
}
]
}
}
{
name: 'vm-subnet'
properties: {
addressPrefix: '10.0.4.0/24'
}
}
]
}
}


output appSubnetId string = usePrivateEndpoint ? vnet.outputs.vnetSubnets[2].id : ''
output appSubnetId string = usePrivateEndpoint ? vnet.outputs.vnetSubnets[1].id : ''
output backendSubnetId string = usePrivateEndpoint ? vnet.outputs.vnetSubnets[0].id : ''
output bastionSubnetId string = usePrivateEndpoint ? vnet.outputs.vnetSubnets[2].id : ''
output vmSubnetId string = usePrivateEndpoint ? vnet.outputs.vnetSubnets[3].id : ''
output vnetName string = usePrivateEndpoint ? vnet.outputs.name : ''
7 changes: 4 additions & 3 deletions infra/private-endpoints.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ module monitorDnsZones './core/networking/private-dns-zones.bicep' = [for monito
}
}]
// Get blob DNS zone index for monitor private link
var dnsZoneBlobIndex = filter(flatten(privateEndpointInfo), info => info.groupId == 'blob')[0].dnsZoneIndex
var blobEndpointInfo = filter(flatten(privateEndpointInfo), info => info.groupId == 'blob')
var dnsZoneBlobIndex = empty(blobEndpointInfo) ? 0 : blobEndpointInfo[0].dnsZoneIndex

// Azure Monitor Private Link Scope
// https://learn.microsoft.com/azure/azure-monitor/logs/private-link-security
Expand Down Expand Up @@ -150,9 +151,9 @@ module monitorPrivateEndpoint './core/networking/private-endpoint.bicep' = {
}
}
{
name: dnsZones[dnsZoneBlobIndex].name
name: 'blob-dnszone' // dnsZones[dnsZoneBlobIndex].name
properties: {
privateDnsZoneId: dnsZones[dnsZoneBlobIndex].outputs.id
privateDnsZoneId: '/subscriptions/77d8a3d0-8b18-47e9-b773-08bee327bb4a/resourceGroups/rg-pf-ragprivate/providers/Microsoft.Network/privateDnsZones/privatelink.blob.core.windows.net' // dnsZones[dnsZoneBlobIndex].outputs.id
}
}
]
Expand Down
Loading