Terminación de HTTPS en instancias de Amazon EC2 que ejecutan .NET - AWS Elastic Beanstalk

Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.

Terminación de HTTPS en instancias de Amazon EC2 que ejecutan .NET

El siguiente archivo de configuración crea y ejecuta un script de Windows PowerShell que realiza las siguientes tareas:

  • Comprueba si existe un certificado HTTPS vinculado con el puerto 443.

  • Obtiene el certificado PFX de un bucket de Amazon S3.

    nota

    Añade una política AmazonS3ReadOnlyAccess a aws-elasticbeanstalk-ec2-role para obtener acceso al certificado SSL del bucket de Amazon S3.

  • Obtiene la contraseña de AWS Secrets Manager.

    nota

    Agregue una declaración en aws-elasticbeanstalk-ec2-role que permita la acción de secretsmanager:GetSecretValue para el secreto que contiene la contraseña del certificado

  • Instala el certificado.

  • Enlaza el certificado al puerto 443.

    nota

    Para quitar el punto de enlace HTTP (puerto 80), incluya el comando Remove-WebBinding en la sección Remove the HTTP binding (Quitar la vinculación con HTTP) del ejemplo.

ejemplo .ebextensions/https-instance-dotnet.config
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

En un entorno de instancia única, también debe modificar el grupo de seguridad de la instancia para permitir el tráfico en el puerto 443. El siguiente archivo de configuración recupera el ID del grupo de seguridad con una función de AWS CloudFormation y le agrega una regla.

ejemplo .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

En un entorno de balanceador de carga, el balanceador de carga se configura para el paso a través del tráfico seguro o para descifrar y volver a cifrar en el cifrado integral.