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

Resources/GetAzureResourceCmdlet.cs incorrectly uses 'DefaultApiVersion' with parameter set -ResourceGroupName -Name -ResourceType -ExpandProperties #11267

Closed
jagilber opened this issue Mar 8, 2020 · 3 comments
Labels
ARM Service Attention This issue is responsible by Azure service team.

Comments

@jagilber
Copy link
Member

jagilber commented Mar 8, 2020

Description

Resources/GetAzureResourceCmdlet.cs ShouldConstructResourceId incorrectly uses 'DefaultApiVersion' with parameter set -ResourceGroupName -Name -ResourceType -ExpandProperties
This can cause missing data in returned resources.
This does not occur when using parameters -ResourceGroupName -Name -ExpandProperties

submitting PR with potential fix in ShouldConstructResourceId

Steps to reproduce

Good Output / apiVersion without -ResourceType

# works as GET request uses apiVersion 2019-03-01
# response contains resources (addonFeatures) only implemented in newer apiVersions that DefaultApiVersion 2016-03-01
<#
"addonFeatures": [
      "DnsService",
      "RepairManager"
    ],
#>
$resource = get-azresource -ResourceGroupName $resourceGroupName -name $clusterName -ExpandProperties

<#
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/{{subscription}}/resourceGroups/{{resourceGroupName}}/resources?$filter=name EQ '{{resourceGroupName}}'&api-version=2016-09-01

DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/{{subscription}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.ServiceFabric/clusters/{{resourceGroupName}}?api-version=2019-03-01
#>

Bad output / default apiVersion with -ResourceType

# does not work
# one get for ResourceType
# one get for resource using 'DefaultApiVersion' for resourceType (=2016-09-01) even though provided parameters build the resourceuri
# result is missing resource information (addonFeatures) as resourceType was built with apiVersion (2019-03-01)

$resource = get-azresource -ResourceGroupName $resourceGroupName -name $clusterName -ExpandProperties -ResourceType Microsoft.ServiceFabric/clusters

<#
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/{{subscription}}/providers/Microsoft.ServiceFabric?api-version=2019-07-01

DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com//subscriptions/{{subscription}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.ServiceFabric/clusters/{{resourceGroupName}}?api-version=2016-09-01
#>

Environment data

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Manifest   1.7.3                 az.accounts                         {Add-AzEnvironment, Clear-AzContext, Clear-AzDefau…
Manifest   1.12.0                az.Resources                        {Add-AzADGroupMember, Export-AzResourceGroup, Get-

Debug output

Bad output with ResourceType

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/{{subscription}}/providers/Microsoft.ServiceFabric?api-version=2019-07-01

Headers:
x-ms-client-request-id        : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Accept-Language               : en-US

Body:


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
x-ms-ratelimit-remaining-subscription-reads: 11998
x-ms-request-id               : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
x-ms-correlation-request-id   : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
x-ms-routing-request-id       : NORTHCENTRALUS:20200308T200517Z:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Date                          : Sun, 08 Mar 2020 20:05:17 GMT

Body:
{
  "id": "/subscriptions/{{subscription}}/providers/Microsoft.ServiceFabric",
  "namespace": "Microsoft.ServiceFabric",
  "authorization": {
    "applicationId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "roleDefinitionId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "managedByRoleDefinitionId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  },
  "resourceTypes": [
    {
      "resourceType": "clusters",
      "locations": [
      ],
      "apiVersions": [
        "2019-06-01-preview",
        "2019-03-01-privatepreview",
        "2019-03-01-preview",
        "2019-03-01",
        "2018-02-01-privatepreview",
        "2018-02-01",
        "2017-07-01-privatepreview",
        "2017-07-01-preview",
        "2016-09-01",
        "2016-03-01"
      ],
      "capabilities": "CrossResourceGroupResourceMove, CrossSubscriptionResourceMove, SupportsTags, SupportsLocation"
    },
    {
      "resourceType": "clusters/applications",
      "locations": [
      ],
      "apiVersions": [
        "2019-06-01-preview",
        "2019-03-01-privatepreview",
        "2019-03-01-preview",
        "2019-03-01",
        "2017-07-01-preview",
        "2016-09-01",
        "2016-03-01"
      ],
      "capabilities": "SystemAssignedResourceIdentity"
    },
    {
      "resourceType": "locations",
      "locations": [],
      "apiVersions": [
        "2019-06-01-preview",
        "2019-03-01-privatepreview",
        "2019-03-01-preview",
        "2019-03-01",
        "2018-02-01-privatepreview",
        "2018-02-01",
        "2017-07-01-privatepreview",
        "2017-07-01-preview",
        "2016-09-01",
        "2016-03-01"
      ],
      "capabilities": "None"
    },
    {
      "resourceType": "locations/clusterVersions",
      "locations": [
      ],
      "apiVersions": [
        "2019-03-01-privatepreview",
        "2019-03-01-preview",
        "2019-03-01",
        "2018-02-01-privatepreview",
        "2018-02-01",
        "2017-07-01-privatepreview",
        "2017-07-01-preview",
        "2016-09-01",
        "2016-03-01"
      ],
      "capabilities": "None"
    },
    {
      "resourceType": "locations/environments",
      "locations": [
      ],
      "apiVersions": [
        "2019-06-01-preview",
        "2019-03-01-privatepreview",
        "2019-03-01-preview",
        "2019-03-01",
        "2018-02-01-privatepreview",
        "2018-02-01",
        "2017-07-01-privatepreview",
        "2017-07-01-preview",
        "2016-09-01",
        "2016-03-01"
      ],
      "capabilities": "None"
    },
    {
      "resourceType": "locations/operations",
      "locations": [
      ],
      "apiVersions": [
        "2019-06-01-preview",
        "2019-03-01-privatepreview",
        "2019-03-01-preview",
        "2019-03-01",
        "2018-02-01-privatepreview",
        "2018-02-01",
        "2017-07-01-privatepreview",
        "2017-07-01-preview",
        "2016-09-01",
        "2016-03-01"
      ],
      "capabilities": "None"
    },
    {
      "resourceType": "locations/operationResults",
      "locations": [
      ],
      "apiVersions": [
        "2019-06-01-preview",
        "2019-03-01-privatepreview",
        "2019-03-01-preview",
        "2019-03-01",
        "2018-02-01-privatepreview",
        "2018-02-01",
        "2017-07-01-privatepreview",
        "2017-07-01-preview",
        "2016-09-01",
        "2016-03-01"
      ],
      "capabilities": "None"
    },
    {
      "resourceType": "operations",
      "locations": [],
      "apiVersions": [
        "2019-03-01-privatepreview",
        "2019-03-01-preview",
        "2019-03-01",
        "2018-02-01-privatepreview",
        "2018-02-01",
        "2017-07-01-privatepreview",
        "2017-07-01-preview",
        "2016-09-01",
        "2016-03-01"
      ],
      "capabilities": "None"
    }
  ],
  "registrationState": "Registered",
  "registrationPolicy": "RegistrationRequired"
}

HTTP Method:
GET

Absolute Uri:
https://management.azure.com//subscriptions/{{subscription}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.ServiceFabric/clusters/{{resourceGroupName}}?api-version=2016-09-01

Headers:
x-ms-client-request-id        : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Accept-Language               : en-US

Body:


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Server                        : Microsoft-HTTPAPI/2.0,Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-reads: 11997
x-ms-request-id               : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
x-ms-correlation-request-id   : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
x-ms-routing-request-id       : NORTHCENTRALUS:20200308T200517Z:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Date                          : Sun, 08 Mar 2020 20:05:17 GMT

Body:
{
  "type": "Microsoft.ServiceFabric/clusters",
  "location": "{{location}}",
  "id": "/subscriptions/{{subscription}}/resourcegroups/{{resourceGroupName}}/providers/Microsoft.ServiceFabric/clusters/{{resourceGroupName}}",
  "name": "{{resourceGroupName}}",
  "tags": {
    "clusterName": "{{resourceGroupName}}",
    "resource-patch": "0302-2",
    "resourceType": "Service Fabric"
  },
  "etag": "W/\"637187697825195681\"",
  "properties": {
    "provisioningState": "Succeeded",
    "clusterId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "clusterCodeVersion": "7.0.466.9590",
    "clusterState": "Ready",
    "managementEndpoint": "https://{{resourceGroupName}}.{{location}}.cloudapp.azure.com:19080",
    "clusterEndpoint": "https://{{location}}.servicefabric.azure.com/runtime/clusters/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "certificate": {
      "thumbprint": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "thumbprintSecondary": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "x509StoreName": "My"
    },
    "clientCertificateThumbprints": [],
    "clientCertificateCommonNames": [],
    "fabricSettings": [
      {
        "name": "ApplicationGateway/Http",
        "parameters": [
          {
            "name": "ApplicationCertificateValidationPolicy",
            "value": "ServiceCertificateThumbprints"
          },
          {
            "name": "ServiceCertificateThumbprints",
            "value": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
          }
        ]
      },
      {
        "name": "Security",
        "parameters": [
          {
            "name": "ClusterProtectionLevel",
            "value": "EncryptAndSign"
          }
        ]
      },
      {
        "name": "Management",
        "parameters": [
          {
            "name": "CleanupApplicationPackageOnProvisionSuccess",
            "value": "true"
          },
          {
            "name": "CleanupUnusedApplicationTypes",
            "value": "true"
          },
          {
            "name": "PeriodicCleanupUnusedApplicationTypes",
            "value": "true"
          },
          {
            "name": "TriggerAppTypeCleanupOnProvisionSuccess",
            "value": "true"
          },
          {
            "name": "MaxUnusedAppTypeVersionsToKeep",
            "value": "3"
          }
        ]
      }
    ],
    "vmImage": "Windows",
    "reliabilityLevel": "Bronze",
    "nodeTypes": [
      {
        "name": "{{Microsoft.Compute/virtualMachineScaleSets}}",
        "vmInstanceCount": 3,
        "clientConnectionEndpointPort": 19000,
        "httpGatewayEndpointPort": 19080,
        "applicationPorts": {
          "startPort": 20000,
          "endPort": 30000
        },
        "ephemeralPorts": {
          "startPort": 49152,
          "endPort": 65534
        },
        "isPrimary": true,
        "reverseProxyEndpointPort": 19081,
        "durabilityLevel": "Bronze"
      }
    ],
    "diagnosticsStorageAccountConfig": {
      "storageAccountName": "{{Microsoft.Storage/storageAccounts}}",
      "primaryAccessKey": "",
      "secondaryAccessKey": "",
      "protectedAccountKeyName": "StorageAccountKey1",
      "blobEndpoint": "https://{{Microsoft.Storage/storageAccounts}}.blob.core.windows.net/",
      "queueEndpoint": "https://{{Microsoft.Storage/storageAccounts}}.queue.core.windows.net/",
      "tableEndpoint": "https://{{Microsoft.Storage/storageAccounts}}.table.core.windows.net/"
    },
    "upgradeMode": "Automatic",
    "availableClusterVersions": [
      {
        "codeVersion": "7.0.466.9590",
        "supportExpiryUtc": "9999-12-31T23:59:59.9999999",
        "environment": "Windows"
      }
    ]
  }
}

DEBUG: 16:05:16 - GetAzureResourceCmdlet end processing.

Error output

(see above)
@jagilber jagilber added the triage label Mar 8, 2020
@dingmeng-xue dingmeng-xue added customer-reported ARM Service Attention This issue is responsible by Azure service team. and removed triage customer-reported labels Mar 9, 2020
@ghost
Copy link

ghost commented Mar 9, 2020

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

@dingmeng-xue
Copy link
Member

Thanks for reporting. Involve ARM team to check server side API version.

@jagilber
Copy link
Member Author

jagilber commented Mar 9, 2020

updated issue with http response debug output with apiversions from servicefabric. if thats issue, then pr #11268 not needed though would handle that type of scenario i think

without fix:
this.ApiVersion is null
this.DefaultApiVersion is 2016-09-01 constant
this.DefaultApiVersion = string.IsNullOrWhiteSpace(this.ApiVersion) ? Constants.ResourcesApiVersion : this.ApiVersion;

calls getbyid(resourceid, this.DefaultApiVersion)

function getbyid(resourceid, apiVersion)
if (resourceType != null)
{
apiVersion = resourceType.ApiVersions.Contains(apiVersion) ? apiVersion : resourceType.ApiVersions.FirstOrDefault();
if (!string.IsNullOrEmpty(apiVersion))
{
return new PSResource(ResourceManagementClient.Resources.GetById(resourceId, apiVersion));
}
}

dingmeng-xue pushed a commit to dingmeng-xue/azure-powershell that referenced this issue Mar 29, 2020
…t-cs

Resources/GetAzureResourceCmdlet.cs fix Azure#11267 get-azresource to use actual apiVersion of resource with parameter set -ResourceGroupName -Name -ExpandProperties -ResourceType
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ARM Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

2 participants