Skip to content

Commit ad11533

Browse files
authored
Merge fixes from v1.33.2 (Azure#2694)
* Fixed false positive Azure.Resource.AllowedRegions Azure#2687 (Azure#2690) * Release v1.33.2 (Azure#2693)
1 parent 1d69c62 commit ad11533

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

docs/CHANGELOG-v1.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ See [upgrade notes][1] for helpful information when upgrading from previous vers
3232

3333
## Unreleased
3434

35-
What's changed since v1.33.1:
35+
What's changed since v1.33.2:
3636

3737
- Engineering:
3838
- Bump Microsoft.NET.Test.Sdk to v17.9.0.
@@ -42,6 +42,14 @@ What's changed since v1.33.1:
4242
- Bump xunit.runner.visualstudio to v2.5.7.
4343
[#2689](https://github.com/Azure/PSRule.Rules.Azure/pull/2689)
4444

45+
## v1.33.2
46+
47+
What's changed since v1.33.1:
48+
49+
- Bug fixes:
50+
- Fixed false positive of `Azure.Resource.AllowedRegions` raised during assertion call by @BernieWhite.
51+
[#2687](https://github.com/Azure/PSRule.Rules.Azure/issues/2687)
52+
4553
## v1.33.1
4654

4755
What's changed since v1.33.0:

docs/en/rules/Azure.Resource.AllowedRegions.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
reviewed: 2023-09-10
2+
reviewed: 2024-02-17
33
severity: Important
44
pillar: Security
5-
category: Design
5+
category: SE:01 Security baseline
66
resource: All resources
77
online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.Resource.AllowedRegions/
88
---
@@ -27,15 +27,15 @@ Some resources, particularly those related to preview services or features, may
2727
## RECOMMENDATION
2828

2929
Consider deploying resources to allowed regions to align with your organizational requirements.
30-
Also consider using Azure Policy to enforce allowed regions.
30+
Also consider using Azure Policy to enforce allowed regions at runtime.
3131

3232
## EXAMPLES
3333

3434
### Configure with Azure template
3535

3636
To deploy resources that pass this rule:
3737

38-
- Set the `location` property to an allowed region. OR
38+
- Set the `location` property to an allowed region. _OR_
3939
- Instead of hard coding the location, use a parameter to allow the location to be specified at deployment time.
4040

4141
For example:
@@ -67,7 +67,7 @@ For example:
6767

6868
To deploy resources that pass this rule:
6969

70-
- Set the `location` property to an allowed region. OR
70+
- Set the `location` property to an allowed region. _OR_
7171
- Instead of hard coding the location, use a parameter to allow the location to be specified at deployment time.
7272

7373
For example:
@@ -101,6 +101,10 @@ resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {
101101
This rule requires one or more allowed regions to be configured.
102102
By default, all regions are allowed.
103103

104+
### Rule configuration
105+
106+
<!-- module:config rule AZURE_RESOURCE_ALLOWED_LOCATIONS -->
107+
104108
To configure this rule set the `AZURE_RESOURCE_ALLOWED_LOCATIONS` configuration value to a set of allowed regions.
105109

106110
For example:
@@ -125,6 +129,6 @@ configuration:
125129

126130
## LINKS
127131

128-
- [Regulatory compliance](https://learn.microsoft.com/azure/well-architected/security/design-regulatory-compliance)
132+
- [SE:01 Security baseline](https://learn.microsoft.com/azure/well-architected/security/establish-baseline)
129133
- [Data residency in Azure](https://azure.microsoft.com/explore/global-infrastructure/data-residency/#overview)
130134
- [Azure geographies](https://azure.microsoft.com/explore/global-infrastructure/geographies/#geographies)

src/PSRule.Rules.Azure/rules/Azure.Resource.Rule.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Rule 'Azure.Resource.UseTags' -Ref 'AZR-000166' -With 'Azure.Resource.SupportsTa
1717
Rule 'Azure.Resource.AllowedRegions' -Ref 'AZR-000167' -If { (SupportsRegions) -and $PSRule.TargetType -ne 'Microsoft.Resources/deployments' -and $Assert.HasFieldValue($TargetObject, 'location').Result } -Tag @{ release = 'GA'; ruleSet = '2020_06'; 'Azure.WAF/pillar' = 'Security'; } {
1818
$context = $PSRule.GetService('Azure.Context');
1919
$location = $TargetObject.location;
20-
$Assert.Create($context.IsAllowedLocation($location), $LocalizedData.LocationNotAllowed, $location);
20+
$Assert.Create('location', [bool]$context.IsAllowedLocation($location), $LocalizedData.LocationNotAllowed, @($location));
2121
}
2222

2323
# Synopsis: Use Resource Group naming requirements

tests/PSRule.Rules.Azure.Tests/Azure.Resource.Tests.ps1

+8
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ Describe 'Azure.Resource' -Tag 'Resource' {
6868
$ruleResult | Should -Not -BeNullOrEmpty;
6969
$ruleResult.Length | Should -Be 1;
7070
$ruleResult.TargetName | Should -Be 'registry-B';
71+
$ruleResult[0].Reason | Should -BeExactly "Path location: The location 'region-B' is not in the allowed set of resource locations.";
72+
$ruleResult[0].Detail.Reason.Path | Should -Be 'location';
7173

7274
# Pass
7375
$ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' });
@@ -161,6 +163,12 @@ Describe 'Azure.Resource' -Tag 'Resource' {
161163
$ruleResult | Should -Not -BeNullOrEmpty;
162164
$ruleResult.Length | Should -Be 5;
163165
$ruleResult.TargetName | Should -BeIn 'route-subnet1', 'route-subnet2', 'nsg-subnet1', 'nsg-subnet2', 'nsg-extra';
166+
$ruleResult[0].Reason | Should -BeExactly "Path location: The location 'eastus' is not in the allowed set of resource locations.";
167+
$ruleResult[1].Reason | Should -BeExactly "Path location: The location 'eastus' is not in the allowed set of resource locations.";
168+
$ruleResult[2].Reason | Should -BeExactly "Path location: The location 'eastus' is not in the allowed set of resource locations.";
169+
$ruleResult[3].Reason | Should -BeExactly "Path location: The location 'eastus' is not in the allowed set of resource locations.";
170+
$ruleResult[4].Reason | Should -BeExactly "Path location: The location 'eastus' is not in the allowed set of resource locations.";
171+
$ruleResult[0..4].Detail.Reason.Path | Should -BeIn @('location');
164172

165173
# Pass
166174
$ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' });

0 commit comments

Comments
 (0)