Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

armresourcegraph: Inconsistent casing causes resources not to be found from graph API #23446

Open
TBeijen opened this issue Sep 17, 2024 · 4 comments
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Resource Graph Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@TBeijen
Copy link

TBeijen commented Sep 17, 2024

Inconsistent casing, combined with ids being case-sensitive, causes resources not to be found from graph API.

Note: This seems to originate from the graph api itself, since https://portal.azure.com/#view/HubsExtension/ArgQueryBlade shows the same results.

I have a list of resource ids that originate from armauthorization.RoleAssignmentsClient, which I take from the responses Properties.Scope. I then use armresourcegraph to load the various types of resources to obtain tags.

This works in most cases, however, not for redis. The casing of the ID returned by armauthorization differs from what is expected by the graph API.

# ID as returned by armauthorization SDK.
# Does not return result in graph
Resources | where id == '/subscriptions/<my-sub>/resourceGroups/<my-rg>/providers/Microsoft.Cache/redis/<my-redis>' | project id, name, type, resourceGroup, tags

# Fixing casing to the exact type returned when fetching from cli (az resource show --ids "<the-id>")
* Note: redis -> Redis
Resources | where id == '/subscriptions/<my-sub>/resourceGroups/<my-rg>/providers/Microsoft.Cache/Redis/<my-redis>' | project id, name, type, resourceGroup, tags

I run use these queries via:

// *armresourcegraph.Client
ResourceGraphClient.Resources(context.Background(), armresourcegraph.QueryRequest{
			Query: to.Ptr(q),
		}, nil)

Some inconsistencies can be observed throughout the Azure landscape that make the graph API hard to navigate.

  • Inconsistent strictness of id casing: When using cli az resource show --ids "<id-with-lowercase-redis"> this gives the result. The graph API does not. The az resource cli command uses dedicated per-resource APIs under the hood. Nevertheless confusing

  • Inconsistent casing of types in ids: In id Microsoft.Cache/redis is incorrect, however Microsoft.KeyVault/vaults is correct

  • Inconsistent response casing: The graph response type values are casted to lowercase, unlike the JSON response of az resource show. Querying the graph API by type requires this lower case. So querying by id and by type both use strict casing, but require a differently cased value.

I can imagine strict casing is important for all naming entered by users (rg names, resource names, tags, etc.). However the type attribute has a limited and well-defined set of values. Not checking for exact casing would make the armresources SDK and the graph API a lot easier to navigate.

To illustrate, I now have this code fragment to work around this issue:

fixedResourceID := strings.Replace(resourceID, "Microsoft.Cache/redis", "Microsoft.Cache/Redis", -1)
@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Sep 17, 2024
@lirenhe lirenhe added the Mgmt This issue is related to a management-plane library. label Sep 30, 2024
@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Sep 30, 2024
@lirenhe
Copy link
Member

lirenhe commented Sep 30, 2024

@tadelesh, could you provide some suggestion on this issue? thanks

@tadelesh tadelesh added Resource Graph Service Attention Workflow: This issue is responsible by Azure service team. labels Sep 30, 2024
@github-actions github-actions bot added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Sep 30, 2024
Copy link

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

@tadelesh
Copy link
Member

@chiragg4u is it by design that resource type is case sensitive? @JeffreyRichter could you also help to take a look? is their any standard for azure resource id/resource type of the casing?

@JeffreyRichter
Copy link
Member

According to the industry standard RFC for URLs (https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2.1), URLs are supposed to be case-sensitive except for the scheme and host name).

Azure services should honor this, but (unfortunately) some do not, and this causes these kinds of problems. And because some engineers are not aware of the RFC, they think URLs are case-insensitive and so one engineer might return "redis" while another engineer writes code requiring "Redis".

So, case-sensitive comparisons are the correct thing. The team needs to agree on "redis" vs "Redis" and then stick to it consistently. This may require code changes. As a "quick-fix", a service could treat "redis" and "Redis" as the same (and maybe "REDIS" too) but this can lead to more problems in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Resource Graph Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

4 participants