Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.25k stars 3.85k forks source link

Get-AzSecurityContact gives Unable to deserialize the response error #23499

Open JoranSlingerland opened 11 months ago

JoranSlingerland commented 11 months ago

Description

In the az.security 1.5.0 in combination with ps 7 the command Get-AzSecurityContact gives a unable to deserialize the response error

Issue script & Debug output

PS C:\Users> Get-AzSecurityContact
DEBUG: Got version 0 of Az
DEBUG: Got version 0 of Az.Accounts
DEBUG: 2:17:59 PM - GetSecurityContacts begin processing with ParameterSet 'SubscriptionScope'.
DEBUG: 2:17:59 PM - using account id 'xxx'...
DEBUG: 2:17:59 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: [Common.Authentication]: Authenticating using Account: 'xxxl', environment: 'AzureCloud', tenant: 'xxx'
DEBUG: 2:17:59 PM - [ConfigManager] Got nothing from [EnableLoginByWam], Module = [], Cmdlet = []. Returning default value [False].
DEBUG: 2:17:59 PM - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - TenantId:'xxx', Scopes:'https://management.core.windows.net//.default', AuthorityHost:'https://login.microsoftonline.com/', UserId:'xxx'
DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId:
=== Request Data ===
Authority Provided? - True
Scopes - https://management.core.windows.net//.default
Extra Query Params Keys (space separated) -
ApiId - AcquireTokenSilent
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId - 19044434-9785-45b4-9390-0f9867334dcf
UserAssertion set: False
LongRunningOboCacheKey set: False
Region configured:

        === Token Acquisition finished successfully:
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: 'xxx', UserId: 'xxx'
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/xxx/providers/Microsoft.Security/securityContacts?api-version=2020-01-01-preview

Headers:
x-ms-client-request-id        : 701adfdf-cd23-4d6e-9cd9-9173b5c78cf3
Accept-Language               : en-US

Body:

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

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
x-ms-ratelimit-remaining-subscription-resource-requests: 749
api-supported-versions        : 2020-01-01-preview
Server                        : Kestrel
x-ms-request-id               : a83c99d3-306b-4e05-b74c-cba7fbf21267
x-ms-correlation-request-id   : a83c99d3-306b-4e05-b74c-cba7fbf21267
x-ms-routing-request-id       : WESTEUROPE:20231120T131759Z:a83c99d3-306b-4e05-b74c-cba7fbf21267
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Date                          : Mon, 20 Nov 2023 13:17:59 GMT

Body:
[{"properties":{"alertNotifications":{"state":"On","minimalSeverity":"High"},"notificationsByRole":{"state":"On","roles":["Owner"]},"emails":"xxx","phone":""},"id":"/subscriptions/xxxproviders/Microsoft.Security/securityContacts/default","name":"default","type":"Microsoft.Security/securityContacts","etag":"\xxx\"","location":"West Europe"}]

DEBUG: 2:17:59 PM - [ConfigManager] Got nothing from [DisableErrorRecordsPersistence], Module = [], Cmdlet = []. Returning default value [False].
DEBUG: 2:17:59 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
Get-AzSecurityContact: Unable to deserialize the response.
DEBUG: 2:17:59 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 2:17:59 PM - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 2:17:59 PM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: AzureQoSEvent:  Module: az.security:1.5.0; CommandName: Get-AzSecurityContact; PSVersion: 7.2.8; IsSuccess: False; Duration: 00:00:01.2235137; Exception: Unable to deserialize the response.;
DEBUG: 2:18:00 PM - GetSecurityContacts end processing.

Environment data

PS C:\Users> $psversiontable

Name                           Value
----                           -----
PSVersion                      7.2.8
PSEdition                      Core
GitCommitId                    7.2.8
OS                             Microsoft Windows 10.0.14393
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                             
---------- -------    ---------- ----                               
Script     2.13.2                Az.Accounts                         
Script     1.5.0                 az.security

Error output

No response

dutt0 commented 8 months ago

Is there a solution for this? I am facing the same issue for az.security version 1.5.1 with runtime ps 5.1 . The command Get-AzSecurityContact gives a 'unable to deserialize the response' error

JoranSlingerland commented 8 months ago

@dutt0 , We eventually implemented the following workaround:


# Temporary solution due to a bug in az.security 1.5.0 with the command Get-AzSecurityContact. See: https://github.com/Azure/azure-powershell/issues/23499
$azContext = Get-AzContext
$token = Get-AzAccessToken -TenantId $azContext.Subscription.TenantId
$authHeader = @{
    'Content-Type'  = 'application/json'
    'Authorization' = 'Bearer ' + $token.Token
}
$restUri = "https://management.azure.com/subscriptions/$($azContext.Subscription.Id)/providers/Microsoft.Security/securityContacts?api-version=2020-01-01-preview"
$response = Invoke-RestMethod -Uri $restUri -Method Get -Headers $authHeader
$response.properties.phone

# (Get-AzSecurityContact).Phone
dutt0 commented 8 months ago

@JoranSlingerland It worked! Thanks so much!

o-l-a-v commented 8 months ago

Still a problem with Az.Account v2.16.0 and Az.Security v1.6.0.


An even easier workaround to what @JoranSlingerland posted is using the Az built in Invoke-AzRestMethod. :)

Invoke-AzRestMethod -Method 'Get' -Path (
  '/subscriptions/{0}/providers/Microsoft.Security/securityContacts?api-version=2020-01-01-preview' -f $Subscription.'Id'
)
isra-fel commented 2 months ago

The edit history of this issue was deleted.

microsoft-github-policy-service[bot] commented 2 months ago

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