Skip to content

Commit 4fcb021

Browse files
Merge pull request #563 from microsoft/psl-macae-networkmodule
fix: optimize the network module for Macae
2 parents 9651a5a + d023557 commit 4fcb021

File tree

2 files changed

+385
-333
lines changed

2 files changed

+385
-333
lines changed

infra/main.bicep

Lines changed: 11 additions & 333 deletions
Original file line numberDiff line numberDiff line change
@@ -328,339 +328,17 @@ module userAssignedIdentity 'br/public:avm/res/managed-identity/user-assigned-id
328328
}
329329
}
330330

331-
// ========== Network Security Groups ========== //
332-
// WAF best practices for virtual networks: https://learn.microsoft.com/en-us/azure/well-architected/service-guides/virtual-network
333-
// WAF recommendations for networking and connectivity: https://learn.microsoft.com/en-us/azure/well-architected/security/networking
334-
var networkSecurityGroupBackendResourceName = 'nsg-${solutionSuffix}-backend'
335-
module networkSecurityGroupBackend 'br/public:avm/res/network/network-security-group:0.5.1' = if (enablePrivateNetworking) {
336-
name: take('avm.res.network.network-security-group.${networkSecurityGroupBackendResourceName}', 64)
337-
params: {
338-
name: networkSecurityGroupBackendResourceName
339-
location: location
340-
tags: tags
341-
enableTelemetry: enableTelemetry
342-
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
343-
securityRules: [
344-
{
345-
name: 'deny-hop-outbound'
346-
properties: {
347-
access: 'Deny'
348-
destinationAddressPrefix: '*'
349-
destinationPortRanges: [
350-
'22'
351-
'3389'
352-
]
353-
direction: 'Outbound'
354-
priority: 200
355-
protocol: 'Tcp'
356-
sourceAddressPrefix: 'VirtualNetwork'
357-
sourcePortRange: '*'
358-
}
359-
}
360-
]
361-
}
362-
}
363-
364-
var networkSecurityGroupBastionResourceName = 'nsg-${solutionSuffix}-bastion'
365-
module networkSecurityGroupBastion 'br/public:avm/res/network/network-security-group:0.5.1' = if (enablePrivateNetworking) {
366-
name: take('avm.res.network.network-security-group.${networkSecurityGroupBastionResourceName}', 64)
367-
params: {
368-
name: networkSecurityGroupBastionResourceName
369-
location: location
370-
tags: tags
371-
enableTelemetry: enableTelemetry
372-
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
373-
securityRules: [
374-
{
375-
name: 'AllowHttpsInBound'
376-
properties: {
377-
protocol: 'Tcp'
378-
sourcePortRange: '*'
379-
sourceAddressPrefix: 'Internet'
380-
destinationPortRange: '443'
381-
destinationAddressPrefix: '*'
382-
access: 'Allow'
383-
priority: 100
384-
direction: 'Inbound'
385-
}
386-
}
387-
{
388-
name: 'AllowGatewayManagerInBound'
389-
properties: {
390-
protocol: 'Tcp'
391-
sourcePortRange: '*'
392-
sourceAddressPrefix: 'GatewayManager'
393-
destinationPortRange: '443'
394-
destinationAddressPrefix: '*'
395-
access: 'Allow'
396-
priority: 110
397-
direction: 'Inbound'
398-
}
399-
}
400-
{
401-
name: 'AllowLoadBalancerInBound'
402-
properties: {
403-
protocol: 'Tcp'
404-
sourcePortRange: '*'
405-
sourceAddressPrefix: 'AzureLoadBalancer'
406-
destinationPortRange: '443'
407-
destinationAddressPrefix: '*'
408-
access: 'Allow'
409-
priority: 120
410-
direction: 'Inbound'
411-
}
412-
}
413-
{
414-
name: 'AllowBastionHostCommunicationInBound'
415-
properties: {
416-
protocol: '*'
417-
sourcePortRange: '*'
418-
sourceAddressPrefix: 'VirtualNetwork'
419-
destinationPortRanges: [
420-
'8080'
421-
'5701'
422-
]
423-
destinationAddressPrefix: 'VirtualNetwork'
424-
access: 'Allow'
425-
priority: 130
426-
direction: 'Inbound'
427-
}
428-
}
429-
{
430-
name: 'DenyAllInBound'
431-
properties: {
432-
protocol: '*'
433-
sourcePortRange: '*'
434-
sourceAddressPrefix: '*'
435-
destinationPortRange: '*'
436-
destinationAddressPrefix: '*'
437-
access: 'Deny'
438-
priority: 1000
439-
direction: 'Inbound'
440-
}
441-
}
442-
{
443-
name: 'AllowSshRdpOutBound'
444-
properties: {
445-
protocol: 'Tcp'
446-
sourcePortRange: '*'
447-
sourceAddressPrefix: '*'
448-
destinationPortRanges: [
449-
'22'
450-
'3389'
451-
]
452-
destinationAddressPrefix: 'VirtualNetwork'
453-
access: 'Allow'
454-
priority: 100
455-
direction: 'Outbound'
456-
}
457-
}
458-
{
459-
name: 'AllowAzureCloudCommunicationOutBound'
460-
properties: {
461-
protocol: 'Tcp'
462-
sourcePortRange: '*'
463-
sourceAddressPrefix: '*'
464-
destinationPortRange: '443'
465-
destinationAddressPrefix: 'AzureCloud'
466-
access: 'Allow'
467-
priority: 110
468-
direction: 'Outbound'
469-
}
470-
}
471-
{
472-
name: 'AllowBastionHostCommunicationOutBound'
473-
properties: {
474-
protocol: '*'
475-
sourcePortRange: '*'
476-
sourceAddressPrefix: 'VirtualNetwork'
477-
destinationPortRanges: [
478-
'8080'
479-
'5701'
480-
]
481-
destinationAddressPrefix: 'VirtualNetwork'
482-
access: 'Allow'
483-
priority: 120
484-
direction: 'Outbound'
485-
}
486-
}
487-
{
488-
name: 'AllowGetSessionInformationOutBound'
489-
properties: {
490-
protocol: '*'
491-
sourcePortRange: '*'
492-
sourceAddressPrefix: '*'
493-
destinationAddressPrefix: 'Internet'
494-
destinationPortRanges: [
495-
'80'
496-
'443'
497-
]
498-
access: 'Allow'
499-
priority: 130
500-
direction: 'Outbound'
501-
}
502-
}
503-
{
504-
name: 'DenyAllOutBound'
505-
properties: {
506-
protocol: '*'
507-
sourcePortRange: '*'
508-
destinationPortRange: '*'
509-
sourceAddressPrefix: '*'
510-
destinationAddressPrefix: '*'
511-
access: 'Deny'
512-
priority: 1000
513-
direction: 'Outbound'
514-
}
515-
}
516-
]
517-
}
518-
}
519-
520-
var networkSecurityGroupAdministrationResourceName = 'nsg-${solutionSuffix}-administration'
521-
module networkSecurityGroupAdministration 'br/public:avm/res/network/network-security-group:0.5.1' = if (enablePrivateNetworking) {
522-
name: take('avm.res.network.network-security-group.${networkSecurityGroupAdministrationResourceName}', 64)
523-
params: {
524-
name: networkSecurityGroupAdministrationResourceName
525-
location: location
526-
tags: tags
527-
enableTelemetry: enableTelemetry
528-
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
529-
securityRules: [
530-
{
531-
name: 'deny-hop-outbound'
532-
properties: {
533-
access: 'Deny'
534-
destinationAddressPrefix: '*'
535-
destinationPortRanges: [
536-
'22'
537-
'3389'
538-
]
539-
direction: 'Outbound'
540-
priority: 200
541-
protocol: 'Tcp'
542-
sourceAddressPrefix: 'VirtualNetwork'
543-
sourcePortRange: '*'
544-
}
545-
}
546-
]
547-
}
548-
}
549-
550-
var networkSecurityGroupContainersResourceName = 'nsg-${solutionSuffix}-containers'
551-
module networkSecurityGroupContainers 'br/public:avm/res/network/network-security-group:0.5.1' = if (enablePrivateNetworking) {
552-
name: take('avm.res.network.network-security-group.${networkSecurityGroupContainersResourceName}', 64)
553-
params: {
554-
name: networkSecurityGroupContainersResourceName
555-
location: location
556-
tags: tags
557-
enableTelemetry: enableTelemetry
558-
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
559-
securityRules: [
560-
{
561-
name: 'deny-hop-outbound'
562-
properties: {
563-
access: 'Deny'
564-
destinationAddressPrefix: '*'
565-
destinationPortRanges: [
566-
'22'
567-
'3389'
568-
]
569-
direction: 'Outbound'
570-
priority: 200
571-
protocol: 'Tcp'
572-
sourceAddressPrefix: 'VirtualNetwork'
573-
sourcePortRange: '*'
574-
}
575-
}
576-
]
577-
}
578-
}
579-
580-
var networkSecurityGroupWebsiteResourceName = 'nsg-${solutionSuffix}-website'
581-
module networkSecurityGroupWebsite 'br/public:avm/res/network/network-security-group:0.5.1' = if (enablePrivateNetworking) {
582-
name: take('avm.res.network.network-security-group.${networkSecurityGroupWebsiteResourceName}', 64)
583-
params: {
584-
name: networkSecurityGroupWebsiteResourceName
585-
location: location
586-
tags: tags
587-
enableTelemetry: enableTelemetry
588-
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
589-
securityRules: [
590-
{
591-
name: 'deny-hop-outbound'
592-
properties: {
593-
access: 'Deny'
594-
destinationAddressPrefix: '*'
595-
destinationPortRanges: [
596-
'22'
597-
'3389'
598-
]
599-
direction: 'Outbound'
600-
priority: 200
601-
protocol: 'Tcp'
602-
sourceAddressPrefix: 'VirtualNetwork'
603-
sourcePortRange: '*'
604-
}
605-
}
606-
]
607-
}
608-
}
609-
610-
// ========== Virtual Network ========== //
611-
// WAF best practices for virtual networks: https://learn.microsoft.com/en-us/azure/well-architected/service-guides/virtual-network
612-
// WAF recommendations for networking and connectivity: https://learn.microsoft.com/en-us/azure/well-architected/security/networking
613331
var virtualNetworkResourceName = 'vnet-${solutionSuffix}'
614-
module virtualNetwork 'br/public:avm/res/network/virtual-network:0.7.0' = if (enablePrivateNetworking) {
615-
name: take('avm.res.network.virtual-network.${virtualNetworkResourceName}', 64)
332+
module virtualNetwork 'modules/virtualNetwork.bicep' = if (enablePrivateNetworking) {
333+
name: take('module.virtualNetwork.${solutionSuffix}', 64)
616334
params: {
617-
name: virtualNetworkResourceName
618-
location: location
335+
name: 'vnet-${solutionSuffix}'
619336
tags: tags
620337
enableTelemetry: enableTelemetry
621338
addressPrefixes: ['10.0.0.0/8']
622-
subnets: [
623-
{
624-
name: 'backend'
625-
addressPrefix: '10.0.0.0/27'
626-
//defaultOutboundAccess: false TODO: check this configuration for a more restricted outbound access
627-
networkSecurityGroupResourceId: networkSecurityGroupBackend!.outputs.resourceId
628-
}
629-
{
630-
name: 'administration'
631-
addressPrefix: '10.0.0.32/27'
632-
networkSecurityGroupResourceId: networkSecurityGroupAdministration!.outputs.resourceId
633-
//defaultOutboundAccess: false TODO: check this configuration for a more restricted outbound access
634-
//natGatewayResourceId: natGateway.outputs.resourceId
635-
}
636-
{
637-
// For Azure Bastion resources deployed on or after November 2, 2021, the minimum AzureBastionSubnet size is /26 or larger (/25, /24, etc.).
638-
// https://learn.microsoft.com/en-us/azure/bastion/configuration-settings#subnet
639-
name: 'AzureBastionSubnet' //This exact name is required for Azure Bastion
640-
addressPrefix: '10.0.0.64/26'
641-
networkSecurityGroupResourceId: networkSecurityGroupBastion!.outputs.resourceId
642-
}
643-
{
644-
// If you use your own vnw, you need to provide a subnet that is dedicated exclusively to the Container App environment you deploy. This subnet isn't available to other services
645-
// https://learn.microsoft.com/en-us/azure/container-apps/networking?tabs=workload-profiles-env%2Cazure-cli#custom-vnw-configuration
646-
name: 'containers'
647-
addressPrefix: '10.0.2.0/23' //subnet of size /23 is required for container app
648-
delegation: 'Microsoft.App/environments'
649-
networkSecurityGroupResourceId: networkSecurityGroupContainers!.outputs.resourceId
650-
privateEndpointNetworkPolicies: 'Enabled'
651-
privateLinkServiceNetworkPolicies: 'Enabled'
652-
}
653-
{
654-
// If you use your own vnw, you need to provide a subnet that is dedicated exclusively to the App Environment you deploy. This subnet isn't available to other services
655-
// https://learn.microsoft.com/en-us/azure/app-service/overview-vnet-integration#subnet-requirements
656-
name: 'webserverfarm'
657-
addressPrefix: '10.0.4.0/27' //When you're creating subnets in Azure portal as part of integrating with the virtual network, a minimum size of /27 is required
658-
delegation: 'Microsoft.Web/serverfarms'
659-
networkSecurityGroupResourceId: networkSecurityGroupWebsite!.outputs.resourceId
660-
privateEndpointNetworkPolicies: 'Enabled'
661-
privateLinkServiceNetworkPolicies: 'Enabled'
662-
}
663-
]
339+
location: location
340+
logAnalyticsWorkspaceId: logAnalyticsWorkspaceResourceId
341+
resourceSuffix: solutionSuffix
664342
}
665343
}
666344

@@ -908,7 +586,7 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:0.17.0' = if (e
908586
ipConfigurations: [
909587
{
910588
name: '${virtualMachineResourceName}-nic01-ipconfig01'
911-
subnetResourceId: virtualNetwork!.outputs.subnetResourceIds[1]
589+
subnetResourceId: virtualNetwork!.outputs.administrationSubnetResourceId
912590
diagnosticSettings: enableMonitoring //WAF aligned configuration for Monitoring
913591
? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }]
914592
: null
@@ -1138,7 +816,7 @@ module aiFoundryAiServices 'br:mcr.microsoft.com/bicep/avm/res/cognitive-service
1138816
{
1139817
name: 'pep-${aiFoundryAiServicesResourceName}'
1140818
customNetworkInterfaceName: 'nic-${aiFoundryAiServicesResourceName}'
1141-
subnetResourceId: virtualNetwork!.outputs.subnetResourceIds[0]
819+
subnetResourceId: virtualNetwork!.outputs.backendSubnetResourceId
1142820
privateDnsZoneGroup: {
1143821
privateDnsZoneGroupConfigs: [
1144822
{
@@ -1246,7 +924,7 @@ module cosmosDb 'br/public:avm/res/document-db/database-account:0.15.0' = {
1246924
]
1247925
}
1248926
service: 'Sql'
1249-
subnetResourceId: virtualNetwork!.outputs.subnetResourceIds[0]
927+
subnetResourceId: virtualNetwork!.outputs.backendSubnetResourceId
1250928
}
1251929
]
1252930
: []
@@ -1291,7 +969,7 @@ module containerAppEnvironment 'br/public:avm/res/app/managed-environment:0.11.2
1291969
// WAF aligned configuration for Private Networking
1292970
publicNetworkAccess: 'Enabled' // Always enabling the publicNetworkAccess for Container App Environment
1293971
internal: false // Must be false when publicNetworkAccess is'Enabled'
1294-
infrastructureSubnetResourceId: enablePrivateNetworking ? virtualNetwork.?outputs.?subnetResourceIds[3] : null
972+
infrastructureSubnetResourceId: enablePrivateNetworking ? virtualNetwork.?outputs.?containerSubnetResourceId : null
1295973
// WAF aligned configuration for Monitoring
1296974
appLogsConfiguration: enableMonitoring
1297975
? {
@@ -1518,7 +1196,7 @@ module webSite 'modules/web-sites.bicep' = {
15181196
// WAF aligned configuration for Private Networking
15191197
vnetRouteAllEnabled: enablePrivateNetworking ? true : false
15201198
vnetImagePullEnabled: enablePrivateNetworking ? true : false
1521-
virtualNetworkSubnetId: enablePrivateNetworking ? virtualNetwork!.outputs.subnetResourceIds[4] : null
1199+
virtualNetworkSubnetId: enablePrivateNetworking ? virtualNetwork!.outputs.webserverfarmSubnetResourceId : null
15221200
publicNetworkAccess: 'Enabled' // Always enabling the public network access for Web App
15231201
e2eEncryptionEnabled: true
15241202
}

0 commit comments

Comments
 (0)