azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'

Open HansZimmer5000 opened this issue 4 years ago • 26 comments

Good day! On the way to look for noncompliant resources I executed 'az policy state list --all' which ended up in an error see below. I get the same error when I execute 'az rest' with the uri described here Azure Doc (of course with adjusted values, e.g. subscription id)

Describe the bug

Command Name az policy state list

Errors:

(ResourceTypeNotSupported) Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'.
Code: ResourceTypeNotSupported
Message: Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'.

To Reproduce:

  • az policy state list --all

Expected Behavior

  • successful output of result in json (as always)

Environment Summary

macOS-12.3.1-x86_64-i386-64bit, Darwin 21.4.0
Python 3.10.2
Installer: HOMEBREW

azure-cli 2.35.0

Extensions:
front-door 1.0.16
alertsmanagement 0.2.2
logic 0.1.5
resource-graph 2.1.0
sentinel 0.1.2
ssh 1.1.0
application-insights 0.1.14

Dependencies:
msal 1.17.0
azure-mgmt-resource 20.0.0

Additional Context

HansZimmer5000 avatar Apr 25 '22 06:04 HansZimmer5000

route to CXP team

yonzhan avatar Apr 25 '22 09:04 yonzhan

Hello @HansZimmer5000 thanks for reaching out no this issue!

Did you try this command from Windows OS PC or from the Azure Portal's cloud shell? I see you are using Mac OS, so wanted to check if this command works from your side on Windows or the cloud shell/

image

Did you try the command with the resource group parameter? az policy state list -g "myRg"

image

SatishBoddu-MSFT avatar Apr 25 '22 23:04 SatishBoddu-MSFT

Facing a similar issue with the Python SDK Code:

from azure.mgmt.policyinsights import PolicyInsightsClient
from azure.mgmt.policyinsights.models import PolicyStatesResource
from azure.identity import AzureCliCredential
 
creds = AzureCliCredential()
client = PolicyInsightsClient(credential=creds, subscription_id="Placeholder")
results = client.policy_states.list_query_results_for_management_group(
    management_group_name="Engineering",
    policy_states_resource=PolicyStatesResource.DEFAULT)
 
for result in results:
    pass

    Traceback:

Traceback (most recent call last):
  File "/Users/dhruv/Workspace/Projects/AEO0/security-policy/rbc/test.py", line 15, in <module>
    for result in results:
  File "/Users/dhruv/Workspace/Projects/AEO0/security-policy/.venv/lib/python3.7/site-packages/azure/core/paging.py", line 129, in __next__
    return next(self._page_iterator)
  File "/Users/dhruv/Workspace/Projects/AEO0/security-policy/.venv/lib/python3.7/site-packages/azure/core/paging.py", line 76, in __next__
    self._response = self._get_next(self.continuation_token)
  File "/Users/dhruv/Workspace/Projects/AEO0/security-policy/.venv/lib/python3.7/site-packages/azure/mgmt/policyinsights/operations/_policy_states_operations.py", line 158, in get_next
    map_error(status_code=response.status_code, response=response, error_map=error_map)
  File "/Users/dhruv/Workspace/Projects/AEO0/security-policy/.venv/lib/python3.7/site-packages/azure/core/exceptions.py", line 105, in map_error
    raise error
azure.core.exceptions.ResourceNotFoundError: (ResourceTypeNotSupported) Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'.
Code: ResourceTypeNotSupported
Message: Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'.

The issue occurs when the code tries to use skipToken

walking-appa avatar Apr 27 '22 17:04 walking-appa

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @josephkwchan, @jennyhunter-msft.

Issue Details

Good day! On the way to look for noncompliant resources I executed 'az policy state list --all' which ended up in an error see below. I get the same error when I execute 'az rest' with the uri described here Azure Doc (of course with adjusted values, e.g. subscription id)

Describe the bug

Command Name az policy state list

Errors:

(ResourceTypeNotSupported) Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'.
Code: ResourceTypeNotSupported
Message: Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'.

To Reproduce:

  • az policy state list --all

Expected Behavior

  • successful output of result in json (as always)

Environment Summary

macOS-12.3.1-x86_64-i386-64bit, Darwin 21.4.0
Python 3.10.2
Installer: HOMEBREW

azure-cli 2.35.0

Extensions:
front-door 1.0.16
alertsmanagement 0.2.2
logic 0.1.5
resource-graph 2.1.0
sentinel 0.1.2
ssh 1.1.0
application-insights 0.1.14

Dependencies:
msal 1.17.0
azure-mgmt-resource 20.0.0

Additional Context

Author: HansZimmer5000
Assignees: jiasli, zhoxing-ms
Labels:

Service Attention, ARM, customer-reported, needs-author-feedback, Auto-Assign

Milestone: Backlog

ghost avatar Apr 28 '22 04:04 ghost

Good morning from Amsterdam!

Thanks for the replies.

@SatishBoddu-MSFT

Did you try this command from Windows OS PC or from the Azure Portal's cloud shell?

Get the same error via Cloud Shells PowerShell:

PS /path/user> az policy state list
(ResourceTypeNotSupported) Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'.
Code: ResourceTypeNotSupported
Message: Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'.

Did you try the command with the resource group parameter?

Just yet, and indeed this one works without error.

HansZimmer5000 avatar Apr 28 '22 06:04 HansZimmer5000

This issue seems to be a service issue:

Request URL:

GET /subscriptions/{subscription}/providers/Microsoft.PolicyInsights/policyStates/default/queryResults?api-version=2019-10-01&$skipToken=xxx HTTP/1.1

Response:

{"error":{"code":"ResourceTypeNotSupported","message":"Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'."}}

This issue needs the service team to investigate the root cause of this error message

zhoxing-ms avatar Apr 28 '22 09:04 zhoxing-ms

Since https://github.com/Azure/azure-cli/pull/22043 is merged and addresses this issue, can I test this somehow? Would I need the full dev-setup or is there a dev branch version of the Azure CLI (e.g. that can be installed via brew)?

HansZimmer5000 avatar Jun 08 '22 12:06 HansZimmer5000

@HansZimmer5000 This PR https://github.com/Azure/azure-cli/pull/22043 has been released. You can install the latest version (2.37.0) of CLI and then try again

zhoxing-ms avatar Jun 08 '22 14:06 zhoxing-ms

This is still an issue.

I'm trying to extract data from the api using the queryResultsUri from the object returned by the az policy state command and I'm running into this exact issue.

$state = az policy state summarize | convertfrom-json
$uri = $state[0].policyAssignments[1].results.queryResultsUri
az rest --url $uri

Results in the following error: Not Found({"error":{"code":"ResourceTypeNotSupported","message":"Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'."}})

This also looks like a server side and not a cli issue, as the error is still present even if you bypass the cli and call the url directly.

Just for reference, the url we get back is:

https://management.azure.com/subscriptions/[sub-guid]/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2019-10-01&$from=2022-10-23 16:17:15Z&$to=2022-10-24 16:17:15Z&$filter=PolicyAssignmentId eq '/providers/microsoft.management/managementgroups/[name]/providers/microsoft.authorization/policyassignments/[assignmentId]'

BlakeWills avatar Oct 24 '22 16:10 BlakeWills

@najagasi Could you please take a look at the above issue?

zhoxing-ms avatar Oct 25 '22 02:10 zhoxing-ms

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @aperezcloud, @kenieva.

Issue Details

Good day! On the way to look for noncompliant resources I executed 'az policy state list --all' which ended up in an error see below. I get the same error when I execute 'az rest' with the uri described here Azure Doc (of course with adjusted values, e.g. subscription id)

Describe the bug

Command Name az policy state list

Errors:

(ResourceTypeNotSupported) Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'.
Code: ResourceTypeNotSupported
Message: Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'.

To Reproduce:

  • az policy state list --all

Expected Behavior

  • successful output of result in json (as always)

Environment Summary

macOS-12.3.1-x86_64-i386-64bit, Darwin 21.4.0
Python 3.10.2
Installer: HOMEBREW

azure-cli 2.35.0

Extensions:
front-door 1.0.16
alertsmanagement 0.2.2
logic 0.1.5
resource-graph 2.1.0
sentinel 0.1.2
ssh 1.1.0
application-insights 0.1.14

Dependencies:
msal 1.17.0
azure-mgmt-resource 20.0.0

Additional Context

Author: HansZimmer5000
Assignees: jiasli, zhoxing-ms
Labels:

Service Attention, customer-reported, Policy, needs-team-attention, Auto-Assign

Milestone: Backlog

ghost avatar Oct 25 '22 17:10 ghost

I have the same issue:

  • Connection #0 to host management.azure.com left intact { "error": { "code": "ResourceTypeNotSupported", "message": "Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'." } }

timzhang926 avatar Nov 20 '22 16:11 timzhang926

@zhoxing-ms az policy state list --all works for me now, no problems / warnings. Have az in version 2.42.0.

I didn't check the Rest API yet. Might do it tomorrow, but don't rely on it.

HansZimmer5000 avatar Nov 27 '22 22:11 HansZimmer5000

@HansZimmer5000 Thank you for your feedback! As we discussed before, this is a REST service-related problem. I guess the service team may have fixed this problem. @najagasi Could you please help confirm it?

zhoxing-ms avatar Nov 28 '22 01:11 zhoxing-ms

@zhoxing-ms Just checked via az rest, same error as reported by @BlakeWills earlier: Not Found({"error":{"code":"ResourceTypeNotSupported","message":"Unsupported resource type: 'Microsoft.PolicyInsights/policyStates/queryResults'."}})

Exact command used (executed once with "default", once with "latest"): az rest --url "https://management.azure.com/subscriptions/{subscription id}/providers/Microsoft.PolicyInsights/policyStates/{"default" or "latest"}/queryResults?api-version=2019-10-01"

HansZimmer5000 avatar Nov 28 '22 09:11 HansZimmer5000

We are also hitting this error completely out of the blue after using az policy state for several months now. Also, no idea how to solve this issue? Using the REST api directly also gives back the same error. Seeing this thread does not make us hopeful for fix soon :(

Tealons avatar May 16 '23 07:05 Tealons

@zhoxing-ms, I'm trying to apply some policy_definitions via terraform wrapped in an initiative. I'm also getting this error with latest version of terraform 1.4.6. Could you be so kind and verify with your colleague you tagged whether or not this is solved?

│ Error: creating/updating Policy Definition "no_inbound_private_endpoint_cross_subscription_Microsoft.Batch/batchAccounts": policy.DefinitionsClient#CreateOrUpdateAtManagementGroup: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceTypeNotSupported" Message="Unsupported resource type: 'Microsoft.Authorization/policyDefinitions/batchAccounts'." │ │ with module.policies.module.private_endpoint_initiative_definition.azurerm_policy_definition.policy_definition_no_inbound_pe["Microsoft.Batch/batchAccounts"], │ on policies/initiatives/private_endpoints/main.tf line 55, in resource "azurerm_policy_definition" "policy_definition_no_inbound_pe": │ 55: resource "azurerm_policy_definition" "policy_definition_no_inbound_pe" { │ ╵

╷ │ Error: creating/updating Policy Definition "no_inbound_private_endpoint_cross_subscription_Microsoft.Search/searchServices": policy.DefinitionsClient#CreateOrUpdateAtManagementGroup: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceTypeNotSupported" Message="Unsupported resource type: 'Microsoft.Authorization/policyDefinitions/searchServices'." │ │ with module.policies.module.private_endpoint_initiative_definition.azurerm_policy_definition.policy_definition_no_inbound_pe["Microsoft.Search/searchServices"], │ on policies/initiatives/private_endpoints/main.tf line 55, in resource "azurerm_policy_definition" "policy_definition_no_inbound_pe": │ 55: resource "azurerm_policy_definition" "policy_definition_no_inbound_pe"

CarstenHS avatar May 23 '23 14:05 CarstenHS

@CarstenHS I'm not sure if this is a service issue or Terraform usage related issue. @mybayern1974 Could you please let the right person help with the above issue?

zhoxing-ms avatar May 24 '23 01:05 zhoxing-ms

@CarstenHS with acknowledging I did not read through this long thread, if you believe this is Terraform AzureRM related, please file an issue to that repo thus TF specific engineers from either Hashicorp or Microsoft or the community could chime in there.

mybayern1974 avatar May 24 '23 04:05 mybayern1974

I figured out it was not so beneficial to have “/“ in the name as this goes into the resource id. Obvious thing, terraform ought to validate that input.

CarstenHS avatar May 29 '23 13:05 CarstenHS