S3 バケットに対するリクエストのうち HTTP リクエストについて調査する方法を教えてください(Amazon S3 API コール編)

2023.03.06

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

困っていること

以前、弊社ブログ で紹介したサーバーアクセスログでの調査方法と異なり、
AWS CloudTrail の Amazon S3 API コール を利用した下記通信経路においての S3 バケットに対するリクエストのうち HTTP リクエストについて調査する方法を教えてください。

  • 自前 PC から S3 へ通信
  • EC2 から S3 へ通信

どう対応すればいいの?

前提条件

CloudTrail でオブジェクトレベルのアクション (DeleteObject GetObject PostObject PutObject など) を記録するためには、データイベントを有効にする必要がある のでまずはご確認ください。

やってみた

以下コマンドより検証。

$ curl --version
curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3
Release-Date: 2020-01-08
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets

$ curl -v http://バケット名.s3.ap-northeast-1.amazonaws.com/オブジェクト名 
$ curl -v https://バケット名.s3.ap-northeast-1.amazonaws.com/オブジェクト名

CloudTrail に記録された当該リクエストについて調査したところ、HTTPS を使用した場合はログ内に"CipherSuite:ECDHE-RSA-AES128-GCM-SHA256"といった項目が含まれ、HTTP を使用した場合は"CipherSuite"といった項目が含まれないことを確認できました。

結果を一部抜粋(マスクしています)

{"Records":[{"eventVersion":"1.08","userIdentity":{"type":"AWSService","invokedBy":"cloudtrail.amazonaws.com"},
"eventTime":"2023-02-12T08:43:14Z","eventSource":"s3.amazonaws.com",
"eventName":"GetBucketAcl","awsRegion":"ap-northeast-1","sourceIPAddress":"cloudtrail.amazonaws.com","userAgent":"cloudtrail.amazonaws.com",
"requestParameters":{"bucketName":"classmethod-■■■■■■","Host":"classmethod-■■■■■■.s3.ap-northeast-1.amazonaws.com","acl":""},
"responseElements":null,"additionalEventData":{"SignatureVersion":"SigV4","CipherSuite":"ECDHE-RSA-AES128-GCM-SHA256",

以上より、CloudTrail のログを使用した場合について以前に弊社 ブログ で紹介したサーバーアクセスログと同様に"CipherSuite"の項目を調査することで HTTP を使用したかを確認できるかと思います。

なお、自前の PC 又は EC2 インスタンスからのアクセスであるかについては、CloudTrail のログ として"sourceIPAddress"といった項目があるので、こちらを確認することで判別は可能です。

cipherSuite - The cipher suite (combination of security algorithms used) of a request.

sourceIPAddress
The IP address that the request was made from. For actions that originate from the service console, the address reported is for the underlying customer resource, not the console web server. For services in AWS, only the DNS name is displayed. CloudTrail redacts the value of sourceIPAddress and replaces it with AWS Internal if the request was made with a proxy client (such as the AWS Management Console), and sessionCredentialFromConsole is present with a value of true.

前回のブログ同様 Amazon Athena により分析いただくことで該当内容の抽出は可能ですので、お試しください。

参考資料