Closed AmrutaKawade closed 4 years ago
@AmrutaKawade
Get-AzureStorageAccount
seems are not from the current Azure Powershell, and in old Azure Powershell module AzureRM.Storage, the cmdlet name is also different "Get-AzureRmStorageAccount".
After search, seems the cmdlet is from module "Azure.Service" https://docs.microsoft.com/en-us/powershell/module/servicemanagement/azure.service/get-azurestorageaccount?view=azuresmps-4.0.0. But I don't see this module imported on your machine. would you please run Get-Command Get-AzureStorageAccount
and see where the cmdlet come from.
And, Azure Powershell has moved to new Az module more than 1.5 years, please use the new module:
With the new module , first use Connect-AzAccount
to login your Azure account, then use Get-AzStorageAccount
to get account.
@dingmeng-xue , @erich-wang Does Azure Powershell still support PublishsettingsFile in Az module?
Get-Command Get-AzureStorageAccount
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Get-AzureStorageAccount 5.3.0 Azure
I am from AzureDevOps team and many customer who were using this command with Azure Classic resources has reported this issue. Its difficult to ask all customers to move to Az Module. As this was working till couple of weeks back. we want to know route cause of it.
I'm not sure if it's specifically related to Get-AzureStorageAccount command. We're getting the same SSL/TLS error with Get-AzureDeployment command.
2020-09-29T23:18:47.7917287Z ##[debug]7:18:47 PM - Begin Operation: Get-AzureDeployment
2020-09-29T23:18:48.2113173Z ##[debug]Error record:
2020-09-29T23:18:48.3668812Z ##[debug]get-azuredeployment : An error occurred while sending the request.
2020-09-29T23:18:48.3682720Z ##[debug]At C:\Users\build_service\AppData\Local\Temp\tmp31D8.ps1:12 char:1
2020-09-29T23:18:48.3695750Z ##[debug]+ get-azuredeployment -servicename $servicename -slot production
2020-09-29T23:18:48.3709285Z ##[debug]+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020-09-29T23:18:48.3730774Z ##[debug] + CategoryInfo : CloseError: (:) [Get-AzureDeployment], HttpRequestException
2020-09-29T23:18:48.3744048Z ##[debug] + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.HostedServices.GetAzureDeploymentCommand
2020-09-29T23:18:48.3757016Z ##[debug]
2020-09-29T23:18:48.3948450Z ##[debug]Exception:
2020-09-29T23:18:48.4025448Z ##[debug]System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
2020-09-29T23:18:48.4047120Z ##[debug] at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
2020-09-29T23:18:48.4081135Z ##[debug] at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
2020-09-29T23:18:48.4083524Z ##[debug] --- End of inner exception stack trace ---
2020-09-29T23:18:48.4096869Z ##[debug] at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
2020-09-29T23:18:48.4109780Z ##[debug] at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
2020-09-29T23:18:48.4122903Z ##[debug] at Microsoft.WindowsAzure.Management.Compute.DeploymentOperationsExtensions.GetBySlot(IDeploymentOperations operations, String serviceName, DeploymentSlot deploymentSlot)
2020-09-29T23:18:48.4138308Z ##[debug] at Microsoft.WindowsAzure.Commands.Utilities.Common.ServiceManagementBaseCmdlet.ExecuteClientActionNewSM[TResult](Object input, String operationDescription, Func`1 action, Func`3 contextFactory)
@rhythmnewt , this is a general issue recently. It seems an issue from Azure Portal because Azure cmdlets have no change for 2 years. . Do you still have previous workable publish setting files?
Couple workarounds below
PS C:\> Clear-AzureProfile
PS C:\> $cert = Get-Item Cert:\CurrentUser\My\<cert-thumbprint>
PS C:\ > Set-AzureSubscription -SubscriptionName "<name of subscription>" -SubscriptionId <sub-id> -Certificate $cert
PS C:\> Select-AzureSubscription -SubscriptionId <sub-id>
Another workaround is still to leverage publish setting file. But private key needs to be imported by below code. $encodedCert is value of ManagementCertificate element in publish setting file.
$pfxPath = "c:\cer1.pfx"
$encodedCert = "......"
$certBytes = [System.Convert]::FromBase64String($encodedCert)
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList ($certBytes, [System.String]::Empty, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$pfx = $cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pfx)
[IO.File]::WriteAllBytes($pfxPath,$file)
Import-PfxCertificate -FilePath $pfxPath -CertStoreLocation Cert:\CurrentUser\My\
My team has been hitting this problem with our Azure classic cloud service pipelines in Azure DevOps. Agreed that it doesn't seem to be the cmdlets themselves because those obviously haven't changed in years now. Wondering if there is a bug with the Azure DevOps agents if they aren't correctly importing the service connection's client certificate then?
This issue does seem to be happening to a lot of customers right now. FYI here are 3 different threads for customers who are experiencing this issue starting this month:
https://developercommunity.visualstudio.com/content/problem/1179481/unable-to-create-ssl.html
Following as we have the same issue in our DevOps pipelines.
We're seeing this same behavior in a Server 2019 VM. Once KB4570720 is applied a previously working Get-AzureStorageAccount
begins throwing a Could not create SSL/TLS secure channel
error.
@dingmeng-xue The second workaround is, well, working for us at the moment so thanks for that. Obviously it will still be good to get to the bottom of the issue.
This issue is caused by a change of behavior introduced with the .NET September update. The following code will restore implicit storage of keys (the previous .Net 4.x behavior) through an environment variable:
Set-Item env:\COMPLUS_CngImplicitPersistKeySet 1
NOTE: You will then need to create a new publishsettings file, as the old certificate and keys will not be overwritten by a subsequent import.
Related issue with additional details about the behavioral change: https://github.com/Azure/azure-powershell/issues/13146
@dcaro We are experiencing this error when running Azure Powershell commands in a DevOps pipeline. Do we have to add the Set-Item
command in every PS script in our pipeline? Or just once at the beginning? Can you further explain "You will then need to create a new publishsettings file, as the old certificate and keys will not be overwritten by a subsequent import." - I dont know what that means unfortunately.
The Set-Item
command set the environment variable COMPLUS_CngImplicitPersistKeySet
to 1
and is read when importing the .publishsettings file.
In the context of ADO, I believe that it is better to set it at the task / pipeline configuration level. This article should help you with setting environment variables:
https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=classic%2Cbatch#set-variables-in-pipeline
@dcaro It's not working for me. I get the same error "The request was aborted: Could not create SSL/TLS secure channel." after following your advice. What I'm doing wrong? Here is my test script: Import-Module -Name "C:\Program Files\WindowsPowerShell\Modules\Azure\5.1.2\Azure.psd1" -Global cd C:\temp\azure
Set-Item -Path env:COMPLUS_CngImplicitPersistKeySet -Value 1 $myValue = Get-Item -Path env:COMPLUS_CngImplicitPersistKeySet $settings = Import-AzurePublishsettingsFile 'new.publishsettings' $thumb = $settings.ExtendedProperties["Account"] $cert = Get-Item cert:\CurrentUser\My\$thumb $subName = $settings.Name $subId = $settings.Id Set-AzureSubscription -SubscriptionName $subName -SubscriptionId $subId -Certificate $cert -Environment AzureCloud $subscription = Select-AzureSubscription -SubscriptionId $subId
$deployment = Get-AzureDeployment -ServiceName "x-zwo" -Slot "Staging" -debug -ErrorVariable a -ErrorAction SilentlyContinue if($a[0] -ne $null) { $a[0] |fl * -Force } else { $deployment }
The
Set-Item
command set the environment variableCOMPLUS_CngImplicitPersistKeySet
to1
and is read when importing the .publishsettings file. In the context of ADO, I believe that it is better to set it at the task / pipeline configuration level. This article should help you with setting environment variables: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=classic%2Cbatch#set-variables-in-pipeline
Set-Item can setup this variable but unfortunately doesn't honor this in the current PS session.
If your code is working in Azure DevOps, you can setup this environment variable in DevOps Pipeline level.
If you are using some Windows client, I recommend Adding this variable by using System Control Panel/System Properties - Environment Variables. You need to start a new PS session after that to run the script.
Or you can use powershell to add this environment variable:
if you want to set up it the machine level, you need the admin privilege for PS:
Again, this takes effective in the new PS session, not the current one.
We have fixed this issue from AzureDevOps Task side by setting PersistKeySet while importing certificate. closing this issue
https://www.powershellgallery.com/packages/Azure/5.3.1 is available now.
Description
Steps to reproduce
Get-AzureStorageAccount -Debug
Debug output
Error output
This used to work before week or something suddenly it started failing