Beenden von HTTPS auf Amazon EC2-Instances, auf denen .NET ausgeführt wird
Die folgende Konfigurationsdatei erstellt ein Windows PowerShell-Skript und führt es aus. Dieses übernimmt die folgenden Aufgaben:
-
Prüft auf ein vorhandenes HTTPS-Zertifikat für eine Bindung mit Port 443
-
Ruft das PFX-Zertifikat und Passwort aus einem Amazon S3-Bucket ab
Anmerkung
Fügen Sie eine
AmazonS3ReadOnlyAccess
-Richtlinie zuaws-elasticbeanstalk-ec2-role
hinzu, um auf das SSL-Zertifikat und Passwortdateien im Amazon S3-Bucket zugreifen zu können. -
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 unter dem Abschnitt Remove the HTTP binding des Beispiels hinzu.
Beispiel .ebextensions/https-instance-dotnet.config
files:
"C:\\certs\\install-cert.ps1":
content: |
import-module webadministration
## Settings - replace the following values with your own
$bucket = "DOC-EXAMPLE-BUCKET
" ## S3 bucket name
$certkey = "example.com.pfx
" ## S3 object key for your PFX certificate
$pwdkey = "password.txt
" ## S3 object key for a text file containing the certificate's password
##
# Set variables
$certfile = "C:\cert.pfx"
$pwdfile = "C:\certs\pwdcontent"
Read-S3Object -BucketName $bucket -Key $pwdkey -File $pwdfile
$pwd = Get-Content $pwdfile -Raw
# 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. Mit der folgenden Konfigurationsdatei wird die ID der Sicherheitsgruppe mit einer AWS CloudFormation-Funktion abgerufen und eine Regel hinzugefügt.
Beispiel .ebextensions/https-instance-single.config
Resources:
sslSecurityGroupIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]}
IpProtocol: tcp
ToPort: 443
FromPort: 443
CidrIp: 0.0.0.0/0
Bei einer Umgebung mit Load Balancer konfigurieren Sie den Load Balancer entweder so, dass sicherer Datenverkehr unangetastet durchgelassen wird, oder für Verschlüsseln und erneutes Entschlüsseln mit End-to-End-Verschlüsselung.