Azure / Azure/PSRule.Rules.Azure
Export-AzRuleData fails with HTTP 400 for DefenderForStorageSettings due to deprecated API version
- Dominant language
- PowerShell
- Stars
- 447
- Forks
- 109
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 23
Description
When running `Export-AzRuleData`, the following warning is emitted for every storage account in a subscription:
```
WARNING: Failed to get '.../Microsoft.Security/DefenderForStorageSettings
?api-version=2022-12-01-preview': status=400
{"error":{"code":"UnsupportedApiVersion","message":"The HTTP resource ...
does not support the API version '2022-12-01-preview'."}}
```
**Root cause:**
https://github.com/Azure/PSRule.Rules.Azure/tree/main/src/PSRule.Rules.Azure/Pipeline/Export/ResourceExpandVisitor.cs hardcodes `"2022-12-01-preview"` for the `DefenderForStorageSettings` sub-resource fetch:
```cs
AddSubResource(resource, await GetSubResourcesByProvider(
context, resourceId,
PROVIDER_TYPE_DEFENDER_FOR_STORAGE_SETTINGS,
"2022-12-01-preview", // deprecated
ignoreNotFound: true));
```
Microsoft has since retired this preview version on the regional Defender for Storage endpoint (`*.storageav.azure.com`). The repo's own `data/providers/microsoft.security/types.json` already lists `2024-08-01-preview` as the current version.
**Suggested fix:** Update the hardcoded version in https://github.com/Azure/PSRule.Rules.Azure/tree/main/src/PSRule.Rules.Azure/Pipeline/Export/ResourceExpandVisitor.cs from `"2022-12-01-preview"` to `"2024-08-01-preview"`.
**Environment:** PSRule.Rules.Azure v1.47.0, Az.Accounts v5.5.1
Contributor guide
Research direction
Open src/PSRule.Rules.Azure/Pipeline/Export/ResourceExpandVisitor.cs and locate the DefenderForStorageSettings sub-resource fetch. Compare its API version with data/providers/microsoft.security/types.json, update the deprecated version, and verify that Export-AzRuleData no longer emits the HTTP 400 warning for storage accounts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, powershell
- Domain
- cloud
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 90/100