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
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,13 @@ public void TestApplicationGatewayCRUDRewriteRuleSetUrlConfiguration()
{
TestRunner.RunTestScript(string.Format("Test-ApplicationGatewayCRUDRewriteRuleSetWithUrlConfiguration -baseDir '{0}'", AppDomain.CurrentDomain.BaseDirectory));
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.nvadev)]
public void TestApplicationGatewayWithListenerHostNames()
{
TestRunner.RunTestScript(string.Format("Test-ApplicationGatewayWithListenerHostNames -baseDir '{0}'", AppDomain.CurrentDomain.BaseDirectory));
}
}
}
220 changes: 219 additions & 1 deletion src/Network/Network.Test/ScenarioTests/ApplicationGatewayTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2581,4 +2581,222 @@ function Test-ApplicationGatewayWithFirewallPolicy
# Cleanup
Clean-ResourceGroup $rgname
}
}
}

<#
.SYNOPSIS
This case tests the per-listener HostNames feature.
#>
function Test-ApplicationGatewayWithListenerHostNames
{
param
(
$basedir = "./"
)

# Setup
$location = Get-ProviderLocation "Microsoft.Network/applicationGateways" "West US 2"

$rgname = Get-ResourceGroupName
$appgwName = Get-ResourceName
$vnetName = Get-ResourceName
$gwSubnetName = Get-ResourceName
$vnetName2 = Get-ResourceName
$gwSubnetName2 = Get-ResourceName
$publicIpName = Get-ResourceName
$gipconfigname = Get-ResourceName

$frontendPort01Name = Get-ResourceName
$frontendPort02Name = Get-ResourceName
$fipconfigName = Get-ResourceName
$listener01Name = Get-ResourceName
$listener02Name = Get-ResourceName
$listener03Name = Get-ResourceName

$poolName = Get-ResourceName
$poolName02 = Get-ResourceName
$trustedRootCertName = Get-ResourceName
$poolSetting01Name = Get-ResourceName
$poolSetting02Name = Get-ResourceName
$probeName = Get-ResourceName

$rule01Name = Get-ResourceName
$rule02Name = Get-ResourceName

$customError403Url01 = "https://mycustomerrorpages.blob.core.windows.net/errorpages/403-another.htm"
$customError403Url02 = "http://mycustomerrorpages.blob.core.windows.net/errorpages/403-another.htm"

$urlPathMapName = Get-ResourceName
$urlPathMapName2 = Get-ResourceName
$PathRuleName = Get-ResourceName
$PathRule01Name = Get-ResourceName
$redirectName = Get-ResourceName
$sslCert01Name = Get-ResourceName

$rewriteRuleName = Get-ResourceName
$rewriteRuleSetName = Get-ResourceName

$wafPolicy = Get-ResourceName

try
{
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $location -Tags @{ testtag = "APPGw tag"}
# Create the Virtual Network
$gwSubnet = New-AzVirtualNetworkSubnetConfig -Name $gwSubnetName -AddressPrefix 10.0.0.0/24
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $gwSubnet
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
$gwSubnet = Get-AzVirtualNetworkSubnetConfig -Name $gwSubnetName -VirtualNetwork $vnet

$gwSubnet2 = New-AzVirtualNetworkSubnetConfig -Name $gwSubnetName2 -AddressPrefix 11.0.1.0/24
$vnet2 = New-AzVirtualNetwork -Name $vnetName2 -ResourceGroupName $rgname -Location $location -AddressPrefix 11.0.0.0/8 -Subnet $gwSubnet2
$vnet2 = Get-AzVirtualNetwork -Name $vnetName2 -ResourceGroupName $rgname
$gwSubnet2 = Get-AzVirtualNetworkSubnetConfig -Name $gwSubnetName2 -VirtualNetwork $vnet2

# Create public ip
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Static -sku Standard

# Create ip configuration
$gipconfig = New-AzApplicationGatewayIPConfiguration -Name $gipconfigname -Subnet $gwSubnet

$fipconfig = New-AzApplicationGatewayFrontendIPConfig -Name $fipconfigName -PublicIPAddress $publicip
$fp01 = New-AzApplicationGatewayFrontendPort -Name $frontendPort01Name -Port 80
$fp02 = New-AzApplicationGatewayFrontendPort -Name $frontendPort02Name -Port 443
$listener01 = New-AzApplicationGatewayHttpListener -Name $listener01Name -Protocol Http -FrontendIPConfiguration $fipconfig -FrontendPort $fp01 -RequireServerNameIndication false

$pool = New-AzApplicationGatewayBackendAddressPool -Name $poolName -BackendIPAddresses www.microsoft.com, www.bing.com
$poolSetting01 = New-AzApplicationGatewayBackendHttpSettings -Name $poolSetting01Name -Port 443 -Protocol Https -CookieBasedAffinity Enabled -PickHostNameFromBackendAddress

#rule
$rule01 = New-AzApplicationGatewayRequestRoutingRule -Name $rule01Name -RuleType basic -BackendHttpSettings $poolSetting01 -HttpListener $listener01 -BackendAddressPool $pool

# sku
$sku = New-AzApplicationGatewaySku -Name WAF_v2 -Tier WAF_v2

$autoscaleConfig = New-AzApplicationGatewayAutoscaleConfiguration -MinCapacity 3
Assert-AreEqual $autoscaleConfig.MinCapacity 3

$redirectConfig = New-AzApplicationGatewayRedirectConfiguration -Name $redirectName -RedirectType Permanent -TargetListener $listener01 -IncludePath $true -IncludeQueryString $true

$headerConfiguration = New-AzApplicationGatewayRewriteRuleHeaderConfiguration -HeaderName "abc" -HeaderValue "def"
$actionSet = New-AzApplicationGatewayRewriteRuleActionSet -RequestHeaderConfiguration $headerConfiguration
$rewriteRule = New-AzApplicationGatewayRewriteRule -Name $rewriteRuleName -ActionSet $actionSet
$rewriteRuleSet = New-AzApplicationGatewayRewriteRuleSet -Name $rewriteRuleSetName -RewriteRule $rewriteRule

$videoPathRule = New-AzApplicationGatewayPathRuleConfig -Name $PathRuleName -Paths "/video" -RedirectConfiguration $redirectConfig -RewriteRuleSet $rewriteRuleSet
Assert-AreEqual $videoPathRule.RewriteRuleSet.Id $rewriteRuleSet.Id
$imagePathRule = New-AzApplicationGatewayPathRuleConfig -Name $PathRule01Name -Paths "/image" -RedirectConfigurationId $redirectConfig.Id -RewriteRuleSetId $rewriteRuleSet.Id
Assert-AreEqual $imagePathRule.RewriteRuleSet.Id $rewriteRuleSet.Id
$urlPathMap = New-AzApplicationGatewayUrlPathMapConfig -Name $urlPathMapName -PathRules $videoPathRule -DefaultBackendAddressPool $pool -DefaultBackendHttpSettings $poolSetting01
$urlPathMap2 = New-AzApplicationGatewayUrlPathMapConfig -Name $urlPathMapName2 -PathRules $videoPathRule,$imagePathRule -DefaultRedirectConfiguration $redirectConfig -DefaultRewriteRuleSet $rewriteRuleSet
$probe = New-AzApplicationGatewayProbeConfig -Name $probeName -Protocol Http -Path "/path/path.htm" -Interval 89 -Timeout 88 -UnhealthyThreshold 8 -MinServers 1 -PickHostNameFromBackendHttpSettings

#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine")]
$pw01 = ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force
$sslCert01Path = $basedir + "/ScenarioTests/Data/ApplicationGatewaySslCert1.pfx"
$sslCert = New-AzApplicationGatewaySslCertificate -Name $sslCert01Name -CertificateFile $sslCert01Path -Password $pw01

# Create Application Gateway
$appgw = New-AzApplicationGateway -Name $appgwName -ResourceGroupName $rgname -Location $location -BackendAddressPools $pool -BackendHttpSettingsCollection $poolSetting01 -FrontendIpConfigurations $fipconfig -GatewayIpConfigurations $gipconfig -FrontendPorts $fp01,$fp02 -HttpListeners $listener01 -RequestRoutingRules $rule01 -Sku $sku -AutoscaleConfiguration $autoscaleConfig -UrlPathMap $urlPathMap,$urlPathMap2 -RedirectConfiguration $redirectConfig -Probe $probe -SslCertificate $sslCert -RewriteRuleSet $rewriteRuleSet

$certFilePath = $basedir + "/ScenarioTests/Data/ApplicationGatewayAuthCert.cer"
$certFilePath2 = $basedir + "/ScenarioTests/Data/TrustedRootCertificate.cer"

# Add
$listener01 = Get-AzApplicationGatewayHttpListener -ApplicationGateway $appgw -Name $listener01Name
Add-AzApplicationGatewayTrustedRootCertificate -ApplicationGateway $appgw -Name $trustedRootCertName -CertificateFile $certFilePath
Add-AzApplicationGatewayHttpListenerCustomError -HttpListener $listener01 -StatusCode HttpStatus403 -CustomErrorPageUrl $customError403Url01

# Add to test Remove
Add-AzApplicationGatewayBackendHttpSettings -ApplicationGateway $appgw -Name $poolSetting02Name -Port 1234 -Protocol Http -CookieBasedAffinity Enabled -RequestTimeout 42 -HostName test -Path /test -AffinityCookieName test
$fipconfig = Get-AzApplicationGatewayFrontendIPConfig -ApplicationGateway $appgw -Name $fipconfigName
Add-AzApplicationGatewayHttpListener -ApplicationGateway $appgw -Name $listener02Name -Protocol Https -FrontendIPConfiguration $fipconfig -FrontendPort $fp02 -HostNames "TestHostName" -SslCertificate $sslCert
$listener02 = Get-AzApplicationGatewayHttpListener -ApplicationGateway $appgw -Name $listener02Name
Add-AzApplicationGatewayHttpListener -ApplicationGateway $appgw -Name $listener03Name -Protocol Https -FrontendIPConfiguration $fipconfig -FrontendPort $fp02 -HostName TestName -SslCertificate $sslCert
$urlPathMap = Get-AzApplicationGatewayUrlPathMapConfig -ApplicationGateway $appgw -Name $urlPathMapName
Add-AzApplicationGatewayRequestRoutingRule -ApplicationGateway $appgw -Name $rule02Name -RuleType PathBasedRouting -HttpListener $listener02 -UrlPathMap $urlPathMap

# Add twice
Assert-ThrowsLike { Add-AzApplicationGatewayTrustedRootCertificate -ApplicationGateway $appgw -Name $trustedRootCertName -CertificateFile $certFilePath } "*already exists*"
Assert-ThrowsLike { Add-AzApplicationGatewayHttpListenerCustomError -HttpListener $listener01 -StatusCode HttpStatus403 -CustomErrorPageUrl $customError403Url01 } "*already exists*"

# Add unsupported
Assert-ThrowsLike { Add-AzApplicationGatewayBackendAddressPool -ApplicationGateway $appgw -Name $poolName02 -BackendIPAddresses www.microsoft.com -BackendFqdns www.bing.com } "*At most one of*can be specified*"

Add-AzApplicationGatewayBackendAddressPool -ApplicationGateway $appgw -Name $poolName02 -BackendFqdns www.bing.com,www.microsoft.com

$appgw = Set-AzApplicationGateway -ApplicationGateway $appgw

Assert-NotNull $appgw.HttpListeners[0].CustomErrorConfigurations
Assert-NotNull $appgw.TrustedRootCertificates
Assert-AreEqual $appgw.BackendHttpSettingsCollection.Count 2
Assert-AreEqual $appgw.HttpListeners.Count 3
Assert-AreEqual $appgw.RequestRoutingRules.Count 2

# Get
$trustedCert = Get-AzApplicationGatewayTrustedRootCertificate -ApplicationGateway $appgw -Name $trustedRootCertName
Assert-NotNull $trustedCert

# List
$trustedCerts = Get-AzApplicationGatewayTrustedRootCertificate -ApplicationGateway $appgw
Assert-NotNull $trustedCerts
Assert-AreEqual $trustedCerts.Count 1

# Set
$listener01 = Get-AzApplicationGatewayHttpListener -ApplicationGateway $appgw -Name $listener01Name
Set-AzApplicationGatewayAutoscaleConfiguration -ApplicationGateway $appgw -MinCapacity 2
Set-AzApplicationGatewayHttpListenerCustomError -HttpListener $listener01 -StatusCode HttpStatus403 -CustomErrorPageUrl $customError403Url02
$disabledRuleGroup1 = New-AzApplicationGatewayFirewallDisabledRuleGroupConfig -RuleGroupName "crs_41_sql_injection_attacks" -Rules 981318,981320
$disabledRuleGroup2 = New-AzApplicationGatewayFirewallDisabledRuleGroupConfig -RuleGroupName "crs_35_bad_robots"
$exclusion1 = New-AzApplicationGatewayFirewallExclusionConfig -Variable "RequestHeaderNames" -Operator "StartsWith" -Selector "xyz"
$exclusion2 = New-AzApplicationGatewayFirewallExclusionConfig -Variable "RequestArgNames" -Operator "Equals" -Selector "a"
Set-AzApplicationGatewayWebApplicationFirewallConfiguration -ApplicationGateway $appgw -Enabled $true -FirewallMode Prevention -RuleSetType "OWASP" -RuleSetVersion "2.2.9" -DisabledRuleGroups $disabledRuleGroup1,$disabledRuleGroup2 -RequestBodyCheck $true -MaxRequestBodySizeInKb 80 -FileUploadLimitInMb 70 -Exclusion $exclusion1,$exclusion2
Set-AzApplicationGatewayTrustedRootCertificate -ApplicationGateway $appgw -Name $trustedRootCertName -CertificateFile $certFilePath2
$appgw = Set-AzApplicationGateway -ApplicationGateway $appgw

# Get Application Gateway
$appgw = Get-AzApplicationGateway -Name $appgwName -ResourceGroupName $rgname

# First Check firewall configuraiton
Assert-AreEqual $appgw.WebApplicationFirewallConfiguration.Enabled $true
Assert-AreEqual $appgw.WebApplicationFirewallConfiguration.FirewallMode "Prevention"
Assert-AreEqual $appgw.WebApplicationFirewallConfiguration.RuleSetType "OWASP"
Assert-AreEqual $appgw.WebApplicationFirewallConfiguration.RuleSetVersion "2.2.9"
Assert-AreEqual $appgw.WebApplicationFirewallConfiguration.DisabledRuleGroups.Count 2
Assert-AreEqual $appgw.WebApplicationFirewallConfiguration.RequestBodyCheck $true
Assert-AreEqual $appgw.WebApplicationFirewallConfiguration.MaxRequestBodySizeInKb 80
Assert-AreEqual $appgw.WebApplicationFirewallConfiguration.FileUploadLimitInMb 70
Assert-AreEqual $appgw.WebApplicationFirewallConfiguration.Exclusions.Count 2

# Set non-exiting
Assert-ThrowsLike { Set-AzApplicationGatewayHttpListenerCustomError -HttpListener $listener01 -StatusCode HttpStatus408 -CustomErrorPageUrl $customError403Url02 } "*does not exist*"
Assert-ThrowsLike { Set-AzApplicationGatewayTrustedRootCertificate -ApplicationGateway $appgw -Name "fakeName" -CertificateFile $certFilePath } "*does not exist*"

# Get Application Gateway backend health with expanded resource
$job = Get-AzApplicationGatewayBackendHealth -Name $appgwName -ResourceGroupName $rgname -ExpandResource "backendhealth/applicationgatewayresource" -AsJob
$job | Wait-Job
$backendHealth = $job | Receive-Job
Assert-NotNull $backendHealth.BackendAddressPools[0].BackendAddressPool.Name

$appgw = Set-AzApplicationGateway -ApplicationGateway $appgw

Assert-AreEqual $appgw.AutoscaleConfiguration.MinCapacity 2

# Remove
Remove-AzApplicationGatewayTrustedRootCertificate -ApplicationGateway $appgw -Name $trustedRootCertName
Remove-AzApplicationGatewayBackendHttpSettings -ApplicationGateway $appgw -Name $poolSetting02Name
Remove-AzApplicationGatewayRequestRoutingRule -ApplicationGateway $appgw -Name $rule02Name
Remove-AzApplicationGatewayHttpListener -ApplicationGateway $appgw -Name $listener02Name

$appgw = Set-AzApplicationGateway -ApplicationGateway $appgw

Assert-Null $appgw.TrustedRootCertificates
Assert-AreEqual $appgw.BackendHttpSettingsCollection.Count 1
Assert-AreEqual $appgw.RequestRoutingRules.Count 1
Assert-AreEqual $appgw.HttpListeners.Count 2
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public class AzureApplicationGatewayHttpListenerBase : NetworkBaseCmdlet
[ValidateNotNullOrEmpty]
public string HostName { get; set; }

[Parameter(
HelpMessage = "Host names")]
[ValidateNotNullOrEmpty]
public string[] HostNames { get; set; }

[Parameter(
HelpMessage = "RequireServerNameIndication")]
[ValidateSet("true", "false", IgnoreCase = true)]
Expand Down Expand Up @@ -170,6 +175,11 @@ public PSApplicationGatewayHttpListener NewObject()
httpListener.FirewallPolicy.Id = this.FirewallPolicyId;
}

if (this.HostNames != null)
{
httpListener.HostNames = this.HostNames?.ToList();
}

if (this.CustomErrorConfiguration != null)
{
httpListener.CustomErrorConfigurations = this.CustomErrorConfiguration?.ToList();
Expand Down
4 changes: 4 additions & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
- Cmdlets updated with optional parameters:
- New-AzApplicationGatewayHttpListener : added parameter FirewallPolicy, FirewallPolicyId
- New-AzApplicationGatewayPathRuleConfig : added parameter FirewallPolicy, FirewallPolicyId
* Added support for perListener HostNames
- Cmdlets updated with optional parameters:
- New-AzApplicationGatewayHttpListener : added parameter HostNames
- Add-AzApplicationGatewayHttpListener : added parameter HostNames
* Fix required subnet with name AzureBastionSubnet in `PSBastion` can be case insensitive
* Support for Destination FQDNs in Network Rules and Translated FQDN in NAT Rules for Azure Firewall
* Add support for top level resource RouteTables of IpGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class PSApplicationGatewayHttpListener : PSChildResource
public string Protocol { get; set; }
[Ps1Xml(Target = ViewControl.Table)]
public string HostName { get; set; }
[Ps1Xml(Target = ViewControl.Table)]
public List<string> HostNames { get; set; }
public PSResourceId SslCertificate { get; set; }
[Ps1Xml(Target = ViewControl.Table)]
public bool RequireServerNameIndication { get; set; }
Expand Down
63 changes: 60 additions & 3 deletions src/Network/Network/help/Add-AzApplicationGatewayHttpListener.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Adds an HTTP listener to an application gateway.
```
Add-AzApplicationGatewayHttpListener -ApplicationGateway <PSApplicationGateway> -Name <String>
[-FrontendIPConfigurationId <String>] [-FrontendPortId <String>] [-SslCertificateId <String>]
[-HostName <String>] [-RequireServerNameIndication <String>] -Protocol <String>
[-FirewallPolicyId <String>] [-HostName <String>] [-HostNames <String[]>]
[-RequireServerNameIndication <String>] -Protocol <String>
[-CustomErrorConfiguration <PSApplicationGatewayCustomError[]>] [-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
```
Expand All @@ -26,8 +27,10 @@ Add-AzApplicationGatewayHttpListener -ApplicationGateway <PSApplicationGateway>
```
Add-AzApplicationGatewayHttpListener -ApplicationGateway <PSApplicationGateway> -Name <String>
[-FrontendIPConfiguration <PSApplicationGatewayFrontendIPConfiguration>]
[-FrontendPort <PSApplicationGatewayFrontendPort>] [-SslCertificate <PSApplicationGatewaySslCertificate>]
[-HostName <String>] [-RequireServerNameIndication <String>] -Protocol <String>
[-FrontendPort <PSApplicationGatewayFrontendPort>]
[-FirewallPolicy <PSApplicationGatewayWebApplicationFirewallPolicy>]
[-SslCertificate <PSApplicationGatewaySslCertificate>] [-HostName <String>] [-HostNames <String[]>]
[-RequireServerNameIndication <String>] -Protocol <String>
[-CustomErrorConfiguration <PSApplicationGatewayCustomError[]>] [-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
```
Expand All @@ -54,6 +57,15 @@ PS C:\> $AppGw = Add-AzApplicationGatewayHttpListener -ApplicationGateway $AppGw
The first command gets the application gateway and stores it in the $AppGw variable.
The second command adds the listener, which uses the HTTPS protocol, to the application gateway.

### Example 3: Add a HTTPS listener with SSL and HostNames
```
PS C:\>$AppGw = Get-AzApplicationGateway -Name "ApplicationGateway01" -ResourceGroupName "ResourceGroup01"
PS C:\> $AppGw = Add-AzApplicationGatewayHttpListener -ApplicationGateway $AppGw -Name "Listener01" -Protocol "Https" -FrontendIpConfiguration $FIP01 -FrontendPort $FP01 -SslCertificate $SSLCert01 -HostNames "*.contoso.com,www.microsoft.com"
```

The first command gets the application gateway and stores it in the $AppGw variable.
The second command adds the listener, which uses the HTTPS protocol, with SSL Certificates and HostNames, to the application gateway.

## PARAMETERS

### -ApplicationGateway
Expand Down Expand Up @@ -101,6 +113,36 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -FirewallPolicy
FirewallPolicy

```yaml
Type: Microsoft.Azure.Commands.Network.Models.PSApplicationGatewayWebApplicationFirewallPolicy
Parameter Sets: SetByResource
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -FirewallPolicyId
FirewallPolicyId

```yaml
Type: System.String
Parameter Sets: SetByResourceId
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -FrontendIPConfiguration
Specifies the application gateway front-end IP resource object.

Expand Down Expand Up @@ -176,6 +218,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -HostNames
Host names

```yaml
Type: System.String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Name
Specifies the name of the front-end port that this command adds.

Expand Down
Loading