Wird bei laufenden HTTPS EC2 Amazon-Instances beendet. NET - AWS Elastic Beanstalk

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Wird bei laufenden HTTPS EC2 Amazon-Instances beendet. NET

Die folgende Konfigurationsdatei erstellt und führt ein PowerShell Windows-Skript aus, das die folgenden Aufgaben ausführt:

  • Überprüft, ob ein vorhandenes HTTPS Zertifikat an Port 443 gebunden ist.

  • Ruft das PFXZertifikat aus einem Amazon S3 S3-Bucket ab.

    Anmerkung

    Fügen Sie eine AmazonS3ReadOnlyAccess Richtlinie für den aws-elasticbeanstalk-ec2-role Zugriff auf das SSL Zertifikat im Amazon S3 S3-Bucket hinzu.

  • Ruft das Passwort von ab AWS Secrets Manager.

    Anmerkung

    Fügen Sie eine Anweisung hinzuaws-elasticbeanstalk-ec2-role, die die secretsmanager:GetSecretValue Aktion für das Geheimnis ermöglicht, das das Zertifikatspasswort enthält

  • Installiert das Zertifikat.

  • Bindet das Zertifikat an Port 443.

    Anmerkung

    Um den HTTP Endpunkt (Port 80) zu entfernen, fügen Sie den Remove-WebBinding Befehl in den Abschnitt HTTPBindung entfernen des Beispiels ein.

Beispiel .ebextensions/ .config https-instance-dotnet
files: "C:\\certs\\install-cert.ps1": content: | import-module webadministration ## Settings - replace the following values with your own $bucket = "amzn-s3-demo-bucket" ## S3 bucket name $certkey = "example.com.pfx" ## S3 object key for your PFX certificate $secretname = "example_secret" ## AWS Secrets Manager name for a secret that contains the certificate's password ## # Set variables $certfile = "C:\cert.pfx" $pwd = Get-SECSecretValue -SecretId $secretname | select -expand SecretString # Clean up existing binding if ( Get-WebBinding "Default Web Site" -Port 443 ) { Echo "Removing WebBinding" Remove-WebBinding -Name "Default Web Site" -BindingInformation *:443: } if ( Get-Item -path IIS:\SslBindings\0.0.0.0!443 ) { Echo "Deregistering WebBinding from IIS" Remove-Item -path IIS:\SslBindings\0.0.0.0!443 } # Download certificate from S3 Read-S3Object -BucketName $bucket -Key $certkey -File $certfile # Install certificate Echo "Installing cert..." $securepwd = ConvertTo-SecureString -String $pwd -Force -AsPlainText $cert = Import-PfxCertificate -FilePath $certfile cert:\localMachine\my -Password $securepwd # Create site binding Echo "Creating and registering WebBinding" New-WebBinding -Name "Default Web Site" -IP "*" -Port 443 -Protocol https New-Item -path IIS:\SslBindings\0.0.0.0!443 -value $cert -Force ## Remove the HTTP binding ## (optional) Uncomment the following line to unbind port 80 # Remove-WebBinding -Name "Default Web Site" -BindingInformation *:80: ## # Update firewall netsh advfirewall firewall add rule name="Open port 443" protocol=TCP localport=443 action=allow dir=OUT commands: 00_install_ssl: command: powershell -NoProfile -ExecutionPolicy Bypass -file C:\\certs\\install-cert.ps1

In einer einzelnen Instance-Umgebung müssen Sie außerdem die Sicherheitsgruppe der Instance ändern, damit Datenverkehr über Port 443 zugelassen wird. Die folgende Konfigurationsdatei ruft mithilfe einer AWS CloudFormation Funktion die ID der Sicherheitsgruppe ab und fügt ihr eine Regel hinzu.

Beispiel .ebeextensions/ .config https-instance-single
Resources: sslSecurityGroupIngress: Type: AWS::EC2::SecurityGroupIngress Properties: GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]} IpProtocol: tcp ToPort: 443 FromPort: 443 CidrIp: 0.0.0.0/0

In einer Umgebung mit Lastenausgleich konfigurieren Sie den Load Balancer so, dass er entweder sicheren Datenverkehr unangetastet weiterleitet oder zur Verschlüsselung entschlüsselt und erneut verschlüsselt. end-to-end