Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.26k stars 3.86k forks source link

Get-AzResourceGroup returns false positive #15612

Open florinangelescu opened 3 years ago

florinangelescu commented 3 years ago

Description

When using unconventional names for the resource group value (URLs), the cmdlet doesn't return anything as result.

Steps to reproduce

Resource group RG1 exists. Resource group RG2 does not exists.

Get-AzResourceGroup -Name "RG1"

Returns the details of the resource group.

Get-AzResourceGroup -Name "RG2"

Fails and says the provided resource group does not exist.

Get-AzResourceGroup -Name "https://RG1?default"

Doesn't return anything, but it also doesn't fail. In an automation we have, we are validating the resource group name and you can imagine this leads to false positive results (when the cmdlet doesn't fail). Also, logically, this doesn't have any sense. It should either return the results of the resource group details or fail. How can it be that it has a 3rd option?

Environment data

Name                           Value                                                            
----                           -----                                                            
PSVersion                      5.1.19041.1151                                                   
PSEdition                      Desktop                                                          
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                          
BuildVersion                   10.0.19041.1151                                                  
CLRVersion                     4.0.30319.42000                                                  
WSManStackVersion              3.0                                                              
PSRemotingProtocolVersion      2.3                                                              
SerializationVersion           1.1.0.1  

Module versions

ModuleType Version    Name                                ExportedCommands                      
---------- -------    ----                                ----------------                      
Script     2.5.2      Az.Accounts                         {Add-AzEnvironment, Clear-AzContext...
Script     4.3.0      Az.Resources                        {Add-AzADGroupMember, Export-AzReso...
Script     0.0        cdsa.azure                          {Add-cdsaAzureNetworkSecurityGroupR...
Script     0.0        cdsa.devops                         {Copy-cdsaAzureDevOpsBaseAppModifie...
Script     1.0.0.0    ISE                                 {Get-IseSnippet, Import-IseSnippet,...
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpo...
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertT...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variab...
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSS...

Debug output

Error output

dingmeng-xue commented 3 years ago

It is a very popular cmdlet and should not have issue. @florinangelescu , please share the debug message of cmdlet execution. You can turn on it via $DebugPreference = "Continue"

dingmeng-xue commented 3 years ago

We have reproduce this issue. When the name is invalid, it goes through all resource groups and return null if no hit. It should be a bug and will be fixed.

ghost commented 3 years ago

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

Issue Details
## Description When using unconventional names for the resource group value (URLs), the cmdlet doesn't return anything as result. ## Steps to reproduce Resource group RG1 exists. Resource group RG2 does not exists. ```powershell Get-AzResourceGroup -Name "RG1" ``` Returns the details of the resource group. ```powershell Get-AzResourceGroup -Name "RG2" ``` Fails and says the provided resource group does not exist. ```powershell Get-AzResourceGroup -Name "https://RG1?default" ``` Doesn't return anything, but it also doesn't fail. In an automation we have, we are validating the resource group name and you can imagine this leads to false positive results (when the cmdlet doesn't fail). Also, logically, this doesn't have any sense. It should either return the results of the resource group details or fail. How can it be that it has a 3rd option? ## Environment data ``` Name Value ---- ----- PSVersion 5.1.19041.1151 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.19041.1151 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 ``` ## Module versions ```powershell ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Script 2.5.2 Az.Accounts {Add-AzEnvironment, Clear-AzContext... Script 4.3.0 Az.Resources {Add-AzADGroupMember, Export-AzReso... Script 0.0 cdsa.azure {Add-cdsaAzureNetworkSecurityGroupR... Script 0.0 cdsa.devops {Copy-cdsaAzureDevOpsBaseAppModifie... Script 1.0.0.0 ISE {Get-IseSnippet, Import-IseSnippet,... Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpo... Manifest 3.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertT... Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variab... Manifest 3.0.0.0 Microsoft.WSMan.Management {Connect-WSMan, Disable-WSManCredSS... ``` ## Debug output ``` ``` ## Error output ``` ```
Author: florinangelescu
Assignees: -
Labels: `Service Attention`, `bug`, `question`, `ARM - Core`, `customer-reported`
Milestone: -
dingmeng-xue commented 3 years ago

According to current implementation https://github.com/Azure/azure-powershell/blob/5794114e0bc8c0639c4e8905528a10520743da3e/src/Resources/ResourceManager/SdkClient/ResourceManagerSdkClient.cs#L883, the parameter -Name has 2 usages. If it is just the normal string, cmdlet gets resource group by that name. If the value contains wildcard characters, it executes query and compares the return result. Get-AzResourceGroup -Name "https://RG1?default" is the second case that it triggers the query and return null because there is no matched result.

florinangelescu commented 3 years ago

Even with the wildcard, the returned result is still not correct. Also, there is no statement whatsoever in the official documentation on this behavior. The outcome of the cmdlet should be consistent no matter what the input. So I still go with the fact that it is a bug and needs to be addressed.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Dingmeng Xue @.> Sent: Thursday, August 12, 2021 8:39:42 AM To: Azure/azure-powershell @.> Cc: Florin Angelescu @.>; Mention @.> Subject: Re: [Azure/azure-powershell] Get-AzResourceGroup returns false positive (#15612)

According to current implementation https://github.com/Azure/azure-powershell/blob/5794114e0bc8c0639c4e8905528a10520743da3e/src/Resources/ResourceManager/SdkClient/ResourceManagerSdkClient.cs#L883https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAzure%2Fazure-powershell%2Fblob%2F5794114e0bc8c0639c4e8905528a10520743da3e%2Fsrc%2FResources%2FResourceManager%2FSdkClient%2FResourceManagerSdkClient.cs%23L883&data=04%7C01%7C%7C35d094d3e1eb4752273008d95d53961b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637643435844945669%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=SRRyEN98NevaKiOIytTMivSj1Pr%2BbKfUAIcxCSBE1Ck%3D&reserved=0, the parameter -Name has 2 usages. If it is just the normal string, cmdlet gets resource group by that name. If the value contains wildcard characters, it executes query and compares the return result. Get-AzResourceGroup -Name "https://RG1?default" is the second case that it triggers the query and return null because there is no matched result.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAzure%2Fazure-powershell%2Fissues%2F15612%23issuecomment-897363499&data=04%7C01%7C%7C35d094d3e1eb4752273008d95d53961b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637643435844955664%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Wve98%2FZtJ0Z15DNWe7F58kb4bIENa%2BM%2FH3bi%2Fx2E%2FP4%3D&reserved=0, or unsubscribehttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAK64RBD24YS4IKLKYHMOKT3T4NNB5ANCNFSM5BQ5AVOQ&data=04%7C01%7C%7C35d094d3e1eb4752273008d95d53961b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637643435844965660%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=9X0sapxRFpqMZkF7fQih4rS6pXCzjJofGkNkDXMs39A%3D&reserved=0. Triage notifications on the go with GitHub Mobile for iOShttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fapps.apple.com%2Fapp%2Fapple-store%2Fid1477376905%3Fct%3Dnotification-email%26mt%3D8%26pt%3D524675&data=04%7C01%7C%7C35d094d3e1eb4752273008d95d53961b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637643435844965660%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=jpHZu0W%2F9hGZVI7JNG56LeuH%2BWGwZMgQjk9oTEEN5Mk%3D&reserved=0 or Androidhttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.github.android%26utm_campaign%3Dnotification-email&data=04%7C01%7C%7C35d094d3e1eb4752273008d95d53961b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637643435844975654%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=TvcjA9rfluNwuUXFAnkMckPvsdLTPOHVXK2Ih3AUv8Y%3D&reserved=0.

KranthiPakala-MSFT commented 3 years ago

@armleads-azure, @dingmeng-xue Following up to see if there is any update on this issue? - Thank you

ghost commented 2 years ago

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

Issue Details
## Description When using unconventional names for the resource group value (URLs), the cmdlet doesn't return anything as result. ## Steps to reproduce Resource group RG1 exists. Resource group RG2 does not exists. ```powershell Get-AzResourceGroup -Name "RG1" ``` Returns the details of the resource group. ```powershell Get-AzResourceGroup -Name "RG2" ``` Fails and says the provided resource group does not exist. ```powershell Get-AzResourceGroup -Name "https://RG1?default" ``` Doesn't return anything, but it also doesn't fail. In an automation we have, we are validating the resource group name and you can imagine this leads to false positive results (when the cmdlet doesn't fail). Also, logically, this doesn't have any sense. It should either return the results of the resource group details or fail. How can it be that it has a 3rd option? ## Environment data ``` Name Value ---- ----- PSVersion 5.1.19041.1151 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.19041.1151 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 ``` ## Module versions ```powershell ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Script 2.5.2 Az.Accounts {Add-AzEnvironment, Clear-AzContext... Script 4.3.0 Az.Resources {Add-AzADGroupMember, Export-AzReso... Script 0.0 cdsa.azure {Add-cdsaAzureNetworkSecurityGroupR... Script 0.0 cdsa.devops {Copy-cdsaAzureDevOpsBaseAppModifie... Script 1.0.0.0 ISE {Get-IseSnippet, Import-IseSnippet,... Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpo... Manifest 3.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertT... Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variab... Manifest 3.0.0.0 Microsoft.WSMan.Management {Connect-WSMan, Disable-WSManCredSS... ``` ## Debug output ``` ``` ## Error output ``` ```
Author: florinangelescu
Assignees: -
Labels: `Service Attention`, `question`, `ARM - Core`, `customer-reported`
Milestone: -
navba-MSFT commented 2 years ago

@florinangelescu Apologies for the late reply. Thanks for your feedback. We will update this thread once we have more details.

@armleads-azure Could you please provide an update on this once you get a chance ? Awaiting your reply.