验证 Amazon ECS Service Connect 是否已启用 TLS - Amazon Elastic Container Service

验证 Amazon ECS Service Connect 是否已启用 TLS

Service Connect 在 Service Connect 代理处启动 TLS,并在目标代理处将其终止。因此,应用程序代码永远看不到 TLS 交互。使用以下步骤验证 TLS 是否已启用。

  1. 在您的应用程序映像中包含 openssl CLI。

  2. 在您的服务上启用 ECS Exec 以通过 SSM 连接到您的任务。或者,您可以在与服务相同的 Amazon VPC 中启动 Amazon EC2 实例。

  3. 从要验证的服务中检索任务的 IP 和端口。您可以从 AWS Cloud Map 控制台检索 IP 地址。该信息位于命名空间的服务详细信息页面上。

  4. 使用如下例所示的 execute-command 登录您的任何任务。或者,登录到步骤 2 中创建的 Amazon EC2 实例。

    $ aws ecs execute-command --cluster cluster-name \ --task < TASK_ID> \ --container app \ --interactive \ --command "/bin/sh"
    注意

    直接调用 DNS 名称不会显示证书。

  5. 在连接的 shell 中,使用 openssl CLI 验证和查看附加到任务的证书。

    例如:

    openssl s_client -connect 10.0.147.43:6379 < /dev/null 2> /dev/null \ | openssl x509 -noout -text

    响应示例:

    Certificate: Data: Version: 3 (0x2) Serial Number: <serial-number> Signature Algorithm: ecdsa-with-SHA256 Issuer: <issuer> Validity Not Before: Jan 23 21:38:12 2024 GMT Not After : Jan 30 22:38:12 2024 GMT Subject: <subject> Subject Public Key Info: Public Key Algorithm: id-ecPublicKey Public-Key: (256 bit) pub: <pub> ASN1 OID: prime256v1 NIST CURVE: P-256 X509v3 extensions: X509v3 Subject Alternative Name: DNS:redis.yelb-cftc X509v3 Basic Constraints: CA:FALSE X509v3 Authority Key Identifier: keyid:<key-id> X509v3 Subject Key Identifier: 1D:<id> X509v3 Key Usage: critical Digital Signature, Key Encipherment X509v3 Extended Key Usage: TLS Web Server Authentication, TLS Web Client Authentication Signature Algorithm: ecdsa-with-SHA256 <hash>