Skip to content

Export-AzRuleData fails with HTTP 400 for DefenderForStorageSettings due to deprecated API version #3865

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:

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfeature: in-flight-exportIssues that related to exporting resource data for in-flight analysis.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions