PSRule.Rules.Azure icon indicating copy to clipboard operation
PSRule.Rules.Azure copied to clipboard

Application gateway: properties.redirectConfiguration.properties check

Open Dylan-Prins opened this issue 3 years ago • 2 comments

Description of the issue

I think there should be a check on properties as well:

Rule 'Azure.AppGw.UseHTTPS' -Ref 'AZR-000059' -Type 'Microsoft.Network/applicationGateways' -Tag @{ release = 'GA'; ruleSet = '2021_09'; } {
    $listeners = @($TargetObject.properties.httpListeners | Where-Object { $_.properties.protocol -eq 'http' });
    $requestRoutingRules = @($TargetObject.properties.requestRoutingRules);
    if ($listeners.Length -eq 0 -or $requestRoutingRules.Length -eq 0) {
        return $Assert.Pass();
    }
    foreach ($requestRoutingRule in $requestRoutingRules) {
        $listener = $listeners | Where-Object { $_.name -eq $requestRoutingRule.properties.httpListener.id.Split('/')[-1] };
        if ($Null -eq $listener) {
            $Assert.Pass();
        }
        else {
            $Assert.HasFieldValue($requestRoutingRule, 'properties.redirectConfiguration.id');
        }
        elseif {
            $Assert.HasFieldValue($requestRoutingRule, 'properties.redirectConfiguration.properties');
        }
    }
}

Module in use and version:

  • Module: PSRule.Rules.Azure
  • Version: [e.g. 1.17.1]

Captured output from $PSVersionTable:


Additional context

Dylan-Prins avatar Jul 11 '22 07:07 Dylan-Prins

@Dylan-Prins Thanks for reporting the issue.

BernieWhite avatar Jul 16 '22 09:07 BernieWhite

@Dylan-Prins Are you able to provide an example of the configuration that specifies properties.redirectConfiguration.properties.

From what I can find, properties.redirectConfiguration.properties might be a runtime property that doesn't exist in infrastructure as code but properties.redirectConfiguration.id must always exist regardless if it has been set via infrastructure as code or from an export.

But happy to be corrected.

https://docs.microsoft.com/azure/templates/microsoft.network/applicationgateways?tabs=bicep#applicationgatewayrequestroutingrulepropertiesformat

BernieWhite avatar Jul 20 '22 03:07 BernieWhite