ALBの接続ログ (Connection logs)を試してみた

ALBが新たにサポートした接続ログを設定、その動作を確認してみました。
2023.12.06

2023年11月 Application Load Balancer (ELB) が接続ログ(Connection Logs)をサポートするアップデートがありました。

接続ログ出力を有効化したALBを用意し、そのログ記録内容について確認する機会がありましたので、紹介させて頂きます。

設定

ALBの「属性」タブで、接続ログの設定が可能になりました。

ALB属性

ALB属性設定

接続ログの出力先のS3バケット、ELBからのログ書き込みを許可するバケットポリシーが必要です。

今回の動作確認は東京リージョンを利用。以下のバケットポリシーをS3バケットに設定し、ログ出力先としました。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::582318560864:root"
            },
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::<S3バケット名>/*"
        }
    ]
}

動作確認

CloudShellで利用可能な 「curl」コマンドを利用して、以下リスナー設定をしたELBへのアクセスを実施して、接続ログの出力内容を確認しました。

  • プロトコル: HTTPS:443
  • Security policy: ELBSecurityPolicy-TLS13-1-2-2021-06
$ curl --version
curl 8.3.0 (x86_64-amazon-linux-gnu) libcurl/8.3.0 OpenSSL/3.0.8 zlib/1.2.11 libidn2/2.3.2 nghttp2/1.57.0
Release-Date: 2023-09-13

TLSネゴシエーション失敗

サポート外のTLSv1を指定。意図的にTLS接続を失敗を再現しました。

Curl

$ curl  -v --tls-max 1.0 https://alb.example.com/
*   Trying 52.xxx.xxx.xxx:443...
* Connected to alb.example.com (52.xxx.xxx.xxx) port 443
* ALPN: curl offers h2,http/1.1
* TLSv1.3 (OUT), TLS alert, protocol version (582):
*  CAfile: /etc/pki/tls/certs/ca-bundle.crt
*  CApath: none
* OpenSSL/3.0.8: error:0A0000BF:SSL routines::no protocols available
* Closing connection
curl: (35) OpenSSL/3.0.8: error:0A0000BF:SSL routines::no protocols available

Connection Log

Unmapped runtime connection error のログ記録が確認できました。

2023-12-05T14:39:18.169062Z 54.92.36.xxx 49823 443 TLSv1.2 ECDHE-ECDSA-AES128-GCM-SHA256 - "-" - - Failed:UnmappedConnectionError
2023-12-05T14:39:19.173977Z 54.92.36.xxx 34719 443 TLSv1.2 ECDHE-ECDSA-AES128-GCM-SHA256 - "-" - - Failed:UnmappedConnectionError
2023-12-05T14:39:22.179932Z 54.92.36.xxx 52081 443 TLSv1.2 ECDHE-ECDSA-AES128-GCM-SHA256 - "-" - - Failed:UnmappedConnectionError
2023-12-05T14:39:31.186108Z 54.92.36.xxx 48725 443 TLSv1.2 ECDHE-ECDSA-AES128-GCM-SHA256 - "-" - - Failed:UnmappedConnectionError
2023-12-05T14:39:48.450383Z 54.92.36.xxx 57233 443 TLSv1.2 ECDHE-ECDSA-AES128-GCM-SHA256 - "-" - - Failed:UnmappedConnectionError
2023-12-05T14:39:49.455209Z 54.92.36.xxx 36119 443 TLSv1.2 ECDHE-ECDSA-AES128-GCM-SHA256 - "-" - - Failed:UnmappedConnectionError
2023-12-05T14:39:52.460734Z 54.92.36.xxx 56745 443 TLSv1.2 ECDHE-ECDSA-AES128-GCM-SHA256 - "-" - - Failed:UnmappedConnectionError

接続成功時

Curl

$ curl  -v --tls-max 1.3 https://alb.example.com/
*   Trying 52.xxx.xxx.xxx:443...
* Connected to alb.example.com (52.xxx.xxx.xxx) port 443
* ALPN: curl offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/pki/tls/certs/ca-bundle.crt
*  CApath: none
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN: server accepted h2
* Server certificate:
*  subject: CN=*.example.com
*  start date: Feb  3 00:00:00 2023 GMT
*  expire date: Mar  4 23:59:59 2024 GMT
*  subjectAltName: host "alb.example.com" matched cert's "*.example.com"
*  issuer: C=US; O=Amazon; CN=Amazon ECDSA 384 M02
*  SSL certificate verify ok.
* using HTTP/2
* [HTTP/2] [1] OPENED stream for https://alb.example.com/
* [HTTP/2] [1] [:method: GET]
* [HTTP/2] [1] [:scheme: https]
* [HTTP/2] [1] [:authority: alb.example.com]
* [HTTP/2] [1] [:path: /]
* [HTTP/2] [1] [user-agent: curl/8.3.0]
* [HTTP/2] [1] [accept: */*]
> GET / HTTP/2
> Host: alb.example.com
> User-Agent: curl/8.3.0
> Accept: */*
> 
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
< HTTP/2 200 
< server: awselb/2.0
< date: Tue, 05 Dec 2023 14:27:13 GMT
< content-type: text/plain; charset=utf-8
< content-length: 14
< 
* Connection #0 to host alb.example.com left intact

Connection Log

2023-12-05T14:27:13.699577Z 54.248.xx.xx 54414 443 TLSv1.3 TLS_AES_128_GCM_SHA256 0.057 "-" - - Success

まとめ

ALBの接続ログ、TLS認証失敗時のログ記録が可能になりました。

TLSクライアント認証(mTLS)をトラストストア検証で利用、接続失敗時の調査が必要な場合や、

mTLSを利用しない場合でも、

  • 古いTLSバージョンのサポートを打ち切るセキュリティポリシーを採用した。
  • CloudWatchのELBのメトリクスで 「Client TLS Negotiation Errors」の値が増加した。
  • TLSネゴシエーションに失敗している環境の調査が必要。

といった場合、ALBが新たにサポートした接続ログをご活用ください。

Client TLS Negotiation Errorsメトリクス例

Client TLS Negotiation Errors