Lorsqu'un fichier est téléchargé depuis un proxy cloud vers un point de terminaison Windows, le téléchargement peut échouer en raison de protocoles de sécurité.

Problème

Le téléchargement du script échoue sur une plate-forme Windows avec le message suivant :
La demande a été abandonnée : impossible de créer un canal sécurisé SSL/TLS.
Il existe trois types de scripts PowerShell hébergés dans un proxy cloud qui peuvent être téléchargés et exécutés sur les machines virtuelles de point de terminaison Windows à différentes fins :
  • Pour installer telegraf personnalisé à l’aide d’un script (download.ps1).
  • Pour installer Telegraf personnalisé sur un serveur physique (unmanagedagent_setup_sample.ps1).
  • Pour configurer Telegraf Open Source sur des machines virtuelles gérées ou non gérées (open_source_telegraf_monitor.ps1).

Solution

Ignorez ServerCertificateValidationCallback à l'aide de la commande suivante.
if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
{
$certCallback = @"
    using System;
    using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    public class ServerCertificateValidationCallback
    {
        public static void Ignore()
        {
            if(ServicePointManager.ServerCertificateValidationCallback ==null)
            {
                ServicePointManager.ServerCertificateValidationCallback +=
                    delegate
                    (
                        Object obj,
                        X509Certificate certificate,
                        X509Chain chain,
                        SslPolicyErrors errors
                    )
                    {
                        return true;
                    };
            }
        }
    }
"@
    Add-Type $certCallback
 }
[ServerCertificateValidationCallback]::Ignore()
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Après le téléchargement et l'exécution du script requis, ServerCertificateValidationCallback peut être activé.