@@ -37,7 +37,7 @@ Rule 'Azure.AKS.PoolVersion' -Ref 'AZR-000016' -Type 'Microsoft.ContainerService
37
37
}
38
38
foreach ($agentPool in $agentPools ) {
39
39
$Assert.HasDefaultValue ($agentPool , ' orchestratorVersion' , $clusterVersion ).
40
- Reason($LocalizedData.AKSNodePoolVersion , $agentPool.name , $agentPool.orchestratorVersion );
40
+ Reason($LocalizedData.AKSNodePoolVersion , $agentPool.name , $agentPool.orchestratorVersion );
41
41
}
42
42
}
43
43
@@ -50,7 +50,7 @@ Rule 'Azure.AKS.PoolScaleSet' -Ref 'AZR-000017' -Type 'Microsoft.ContainerServic
50
50
}
51
51
foreach ($agentPool in $agentPools ) {
52
52
$Assert.HasFieldValue ($agentPool , ' type' , ' VirtualMachineScaleSets' ).
53
- Reason($LocalizedData.AKSNodePoolType , $agentPool.name );
53
+ Reason($LocalizedData.AKSNodePoolType , $agentPool.name );
54
54
}
55
55
}
56
56
@@ -99,11 +99,11 @@ Rule 'Azure.AKS.CNISubnetSize' -Ref 'AZR-000020' -If { IsExport } -With 'Azure.A
99
99
$subnetAddressPrefixSize = [int ]$subnet.Properties.addressPrefix.Split (' /' )[-1 ];
100
100
101
101
$Assert.LessOrEqual ($subnetAddressPrefixSize , ' .' , $configurationMinimumSubnetSize ).
102
- Reason(
103
- $LocalizedData.AKSAzureCNI ,
104
- $subnet.Name ,
105
- $configurationMinimumSubnetSize
106
- );
102
+ Reason(
103
+ $LocalizedData.AKSAzureCNI ,
104
+ $subnet.Name ,
105
+ $configurationMinimumSubnetSize
106
+ );
107
107
}
108
108
} - Configure @ { AZURE_AKS_CNI_MINIMUM_CLUSTER_SUBNET_SIZE = 23 }
109
109
@@ -134,7 +134,7 @@ Rule 'Azure.AKS.AvailabilityZone' -Ref 'AZR-000021' -Type 'Microsoft.ContainerSe
134
134
# Availability zones only available on virtual machine scale sets
135
135
if ($Assert.HasFieldValue ($agentPool , ' type' , ' VirtualMachineScaleSets' ).Result) {
136
136
$Assert.HasFieldValue ($agentPool , ' availabilityZones' ).
137
- Reason($LocalizedData.AKSAvailabilityZone , $agentPool.name , $TargetObject.Location , $joinedZoneString );
137
+ Reason($LocalizedData.AKSAvailabilityZone , $agentPool.name , $TargetObject.Location , $joinedZoneString );
138
138
}
139
139
else {
140
140
$Assert.Pass ();
@@ -150,15 +150,15 @@ Rule 'Azure.AKS.AuditLogs' -Ref 'AZR-000022' -Type 'Microsoft.ContainerService/m
150
150
151
151
foreach ($setting in $diagnosticLogs ) {
152
152
$kubeAuditEnabledLog = @ ($setting.Properties.logs | Where-Object {
153
- $_.category -in ' kube-audit' , ' kube-audit-admin' -and $_.enabled
154
- });
153
+ $_.category -in ' kube-audit' , ' kube-audit-admin' -and $_.enabled
154
+ });
155
155
156
156
$guardEnabledLog = @ ($setting.Properties.logs | Where-Object {
157
- $_.category -eq ' guard' -and $_.enabled
158
- });
157
+ $_.category -eq ' guard' -and $_.enabled
158
+ });
159
159
160
160
$auditLogsEnabled = $Assert.Greater ($kubeAuditEnabledLog , ' .' , 0 ).Result -and
161
- $Assert.Greater ($guardEnabledLog , ' .' , 0 ).Result;
161
+ $Assert.Greater ($guardEnabledLog , ' .' , 0 ).Result;
162
162
163
163
$Assert.Create ($auditLogsEnabled , $LocalizedData.AKSAuditLogs , $setting.name );
164
164
}
@@ -177,7 +177,7 @@ Rule 'Azure.AKS.PlatformLogs' -Ref 'AZR-000023' -Type 'Microsoft.ContainerServic
177
177
$Assert.Greater ($diagnosticLogs , ' .' , 0 ).Reason($LocalizedData.DiagnosticSettingsNotConfigured , $TargetObject.name );
178
178
179
179
$availableLogCategories = @ {
180
- Logs = @ (
180
+ Logs = @ (
181
181
' cluster-autoscaler' ,
182
182
' kube-apiserver' ,
183
183
' kube-controller-manager' ,
@@ -189,12 +189,12 @@ Rule 'Azure.AKS.PlatformLogs' -Ref 'AZR-000023' -Type 'Microsoft.ContainerServic
189
189
}
190
190
191
191
$configurationLogCategories = @ ($configurationLogCategoriesList | Where-Object {
192
- $_ -in $availableLogCategories.Logs
193
- });
192
+ $_ -in $availableLogCategories.Logs
193
+ });
194
194
195
195
$configurationMetricCategories = @ ($configurationLogCategoriesList | Where-Object {
196
- $_ -in $availableLogCategories.Metrics
197
- });
196
+ $_ -in $availableLogCategories.Metrics
197
+ });
198
198
199
199
$logCategoriesNeeded = [System.Math ]::Min(
200
200
$configurationLogCategories.Length ,
@@ -210,19 +210,19 @@ Rule 'Azure.AKS.PlatformLogs' -Ref 'AZR-000023' -Type 'Microsoft.ContainerServic
210
210
211
211
foreach ($setting in $diagnosticLogs ) {
212
212
$platformLogs = @ ($setting.Properties.logs | Where-Object {
213
- $_.enabled -and
214
- $_.category -in $configurationLogCategories -and
215
- $_.category -in $availableLogCategories.Logs
216
- });
213
+ $_.enabled -and
214
+ $_.category -in $configurationLogCategories -and
215
+ $_.category -in $availableLogCategories.Logs
216
+ });
217
217
218
218
$metricLogs = @ ($setting.Properties.metrics | Where-Object {
219
- $_.enabled -and
220
- $_.category -in $configurationMetricCategories -and
221
- $_.category -in $availableLogCategories.Metrics
222
- });
219
+ $_.enabled -and
220
+ $_.category -in $configurationMetricCategories -and
221
+ $_.category -in $availableLogCategories.Metrics
222
+ });
223
223
224
224
$platformLogsEnabled = $Assert.HasFieldValue ($platformLogs , ' Length' , $logCategoriesNeeded ).Result -and
225
- $Assert.HasFieldValue ($metricLogs , ' Length' , $metricCategoriesNeeded ).Result
225
+ $Assert.HasFieldValue ($metricLogs , ' Length' , $metricCategoriesNeeded ).Result
226
226
227
227
$Assert.Create (
228
228
$platformLogsEnabled ,
@@ -262,8 +262,8 @@ Rule 'Azure.AKS.MinNodeCount' -Ref 'AZR-000024' -Type 'Microsoft.ContainerServic
262
262
Rule ' Azure.AKS.MinUserPoolNodes' - Ref ' AZR-000412' - Type ' Microsoft.ContainerService/managedClusters' , ' Microsoft.ContainerService/managedClusters/agentPools' - Tag @ { release = ' GA' ; ruleSet = ' 2024_03' ; ' Azure.WAF/pillar' = ' Reliability' } {
263
263
$excludedPools = $Configuration.GetStringValues (' AZURE_AKS_CLUSTER_USER_POOL_EXCLUDED_FROM_MINIMUM_NODES' );
264
264
$agentPools = @ (GetAgentPoolProfiles | Where-Object {
265
- $_.mode -eq ' user' -and $_.name -notin $excludedPools -and $_.scaleSetPriority -ne ' Spot'
266
- })
265
+ $_.mode -eq ' user' -and $_.name -notin $excludedPools -and $_.scaleSetPriority -ne ' Spot'
266
+ })
267
267
268
268
if ($agentPools.Length -eq 0 ) {
269
269
return $Assert.Pass ();
@@ -305,6 +305,20 @@ Rule 'Azure.AKS.EphemeralOSDisk' -Ref 'AZR-000287' -Level Warning -Type 'Microso
305
305
}
306
306
}
307
307
308
+ # Synopsis: Use kube-audit-admin instead of kube-audit to capture administrative actions in AKS clusters.
309
+ Rule ' Azure.AKS.AuditAdmin' - Ref ' AZR-000445' - Type ' Microsoft.ContainerService/managedClusters' - Tag @ { release = ' GA' ; ruleSet = ' 2024_09' ; ' Azure.WAF/pillar' = ' Cost Optimization' ; } {
310
+ $kubeAuditLogs = @ (GetSubResources - ResourceType ' Microsoft.Insights/diagnosticSettings' |
311
+ Where-Object { $_.properties.logs | Where-Object { $_.category -eq ' kube-audit' -and $_.enabled } } )
312
+
313
+ if ($kubeAuditLogs.Count -eq 0 ) {
314
+ return $Assert.Pass ()
315
+ }
316
+
317
+ foreach ($kubeAuditLog in $kubeAuditLogs ) {
318
+ $Assert.Fail ().Reason($LocalizedData.AKSAuditAdmin , $kubeAuditLog.name )
319
+ }
320
+ }
321
+
308
322
# region Helper functions
309
323
310
324
function global :GetAgentPoolProfiles {
@@ -315,36 +329,36 @@ function global:GetAgentPoolProfiles {
315
329
if ($PSRule.TargetType -eq ' Microsoft.ContainerService/managedClusters' ) {
316
330
$TargetObject.Properties.agentPoolProfiles ;
317
331
@ (GetSubResources - ResourceType ' Microsoft.ContainerService/managedClusters/agentPools' | ForEach-Object {
318
- [PSCustomObject ]@ {
319
- name = $_.name
320
- type = $_.properties.type
321
- mode = $_.properties.mode
322
- maxPods = $_.properties.maxPods
323
- orchestratorVersion = $_.properties.orchestratorVersion
324
- enableAutoScaling = $_.properties.enableAutoScaling
325
- availabilityZones = $_.properties.availabilityZones
326
- osDiskType = $_.properties.osDiskType
327
- count = [int ]$_.properties.count
328
- minCount = [int ]$_.properties.minCount
329
- maxCount = [int ]$_.properties.maxCount
330
- scaleSetPriority = $_.properties.scaleSetPriority
331
- }
332
- });
332
+ [PSCustomObject ]@ {
333
+ name = $_.name
334
+ type = $_.properties.type
335
+ mode = $_.properties.mode
336
+ maxPods = $_.properties.maxPods
337
+ orchestratorVersion = $_.properties.orchestratorVersion
338
+ enableAutoScaling = $_.properties.enableAutoScaling
339
+ availabilityZones = $_.properties.availabilityZones
340
+ osDiskType = $_.properties.osDiskType
341
+ count = [int ]$_.properties.count
342
+ minCount = [int ]$_.properties.minCount
343
+ maxCount = [int ]$_.properties.maxCount
344
+ scaleSetPriority = $_.properties.scaleSetPriority
345
+ }
346
+ });
333
347
}
334
348
elseif ($PSRule.TargetType -eq ' Microsoft.ContainerService/managedClusters/agentPools' ) {
335
349
[PSCustomObject ]@ {
336
- name = $TargetObject.name
337
- type = $TargetObject.properties.type
338
- mode = $TargetObject.properties.mode
339
- maxPods = $TargetObject.properties.maxPods
350
+ name = $TargetObject.name
351
+ type = $TargetObject.properties.type
352
+ mode = $TargetObject.properties.mode
353
+ maxPods = $TargetObject.properties.maxPods
340
354
orchestratorVersion = $TargetObject.properties.orchestratorVersion
341
- enableAutoScaling = $TargetObject.properties.enableAutoScaling
342
- availabilityZones = $TargetObject.properties.availabilityZones
343
- osDiskType = $TargetObject.properties.osDiskType
344
- count = [int ]$TargetObject.properties.count
345
- minCount = [int ]$TargetObject.properties.minCount
346
- maxCount = [int ]$TargetObject.properties.maxCount
347
- scaleSetPriority = $TargetObject.properties.scaleSetPriority
355
+ enableAutoScaling = $TargetObject.properties.enableAutoScaling
356
+ availabilityZones = $TargetObject.properties.availabilityZones
357
+ osDiskType = $TargetObject.properties.osDiskType
358
+ count = [int ]$TargetObject.properties.count
359
+ minCount = [int ]$TargetObject.properties.minCount
360
+ maxCount = [int ]$TargetObject.properties.maxCount
361
+ scaleSetPriority = $TargetObject.properties.scaleSetPriority
348
362
}
349
363
}
350
364
}
0 commit comments