7
3

More than 1 year has passed since last update.

【CloudTrail解説編】AWSマネージメントコンソールのログイン監視

Last updated at Posted at 2021-02-02

はじめに

AWS Security HubでサポートされているCIS AWS Foundations Benchmarkのコントロールのうち
マネージメントコンソールへのログインに関する内容について
CloudTrailの証跡ログをどのように見ていくのが良いかをまとめてみました。

これから「AWSのセキュリティ監視や監査を検討する方々」の一助になれば幸いです^^
※「素敵!」と思われた方、ぜひ照れずにLGTMを!

【主なポイント】
・ Rootでのマネージメントコンソールのログインをしていないか
・ ログインにはMFA (Multi-Factor Authentication) を利用しているか
・ マネージメントコンソールのログイン認証の失敗が多量発生していないか
・ 利用しているMFAの種類 (U2F、ハードウェア、仮想) は把握しているか

【参考】
CIS AWS Foundations Benchmarkのコントロール
AWSアカウントの証跡の作成

CIS AWS Foundations Benchmarkとは

インターネットセキュリティ標準化に取り組む米国の非営利団体である
CIS (Center for Internet Security) が公開しているAWSアカウントを利用する上で
必要となるセキュリティ設定のための技術的なベストプラクティスです。

image.png

2020年8月にバージョン1.3.0に更新されましたが
2021年2月時点ではバージョン1.2.0をベースにAWSのSecurity Hubでサポートされています。

【参考】
CIS AWS Foundations Benchmark

俯瞰図

  • マネージメントコンソールのログインに関するCloudTrail証跡ログを俯瞰したイメージ図を書いてみました。

image.png

【補足】
additionalEventData.MFAUsedがYesの場合、CheckMfaに関するログが登場する。
userIdentity.typeがAssumeRoleの場合、SwitchRoleに関するログが登場する。

フィールド定義

  • 以下、マネージメントコンソールのログインに関するCloudTrail証跡ログのフィールドになります。
フィールド名 説明
eventVersion ログイベント形式のバージョン
userIdentity.type ユーザIDの種類
userIdentity.principalId 呼び出しを行ったエンティティの一意の識別子
userIdentity.accountId AWSアカウント (12桁)
userIdentity.accessKeyId AWSアクセスキー
userIdentity.userName IAMユーザ名
eventTime イベントの発生日時
eventSource リクエストが行われたAWSサービス (signin.amazonaws.comになる)
eventName イベント名 (Console Login、CheckMfa、SwitchRoleのいずれか)
awsRegion ログインしたAWSリージョン
sourceIPAddress 送信元IPアドレス
userAgent 接続元のユーザーエージェント
errorMessage エラーのメッセージ
requestParameters リクエストとともに送信されたパラメータ (nullになる)
responseElements.CheckMfa MFAチェックの成否 (Success/Failure)
responseElements.ConsoleLogin コンソールログインの成否 (Success/Failure)
responseElements.SwitchRole スイッチロールの成否 (Success/Failure)
additionalEventData.MfaType MFAの種類 (U2F、Hardware、Virtual)
additionalEventData.LoginTo ログイン先URL
additionalEventData.MobileVersion モバイルバージョン (Noになる)
additionalEventData.MFAUsed MFAの利用有無 (Yes/No)
additionalEventData.SwitchFrom スイッチロールの接続元ARN
additionalEventData.RedirectTo スイッチロールのリダイレクト先URL
eventID CloudTrail証跡ログの中で一意となるイベントID
readOnly 読み取り専用の操作であるかどうか (falseになる)
eventType イベントレコードを生成したイベントのタイプ (AwsConsoleSignInになる)
managementEvent 管理用イベントかどうか (trueになる)
eventCategory イベントのカテゴリ (Managementになる)
recipientAccountId イベントを受信したAWSアカウント (12桁)

【参考】
CloudTrail レコードの内容
CloudTrail userIdentity要素

テストシナリオ

  • 下記シナリオでAWSマネージメントコンソールのログインテストを実施しました。
  1. RootによるMFAでのログイン成功
  2. RootによるMFAでのログイン失敗
  3. IAMユーザによるMFAでのログイン成功
  4. IAMユーザによるMFAでのログイン失敗
  5. 存在しないIAMユーザでのログイン失敗
  6. IAMユーザによるパスワードのみでのログイン成功
  7. IAMユーザによるパスワードのみでのログイン失敗
  8. 別アカウントからスイッチユーザによるログイン成功

【補足】
・ RootとIAMユーザでログ出力のされ方の違いを確認しました。
・ MFAを利用した場合と利用していない場合のログ出力のされ方の違いを確認しました。
・ ログインの成功と失敗でのログ出力のされ方の違いを確認しました。
・ パスワードリスト攻撃を想定し、存在しないIAMユーザでのログイン失敗時のログを確認しました。
・ マルチアカウント運用を想定し、スイッチロールによるログイン時のログを確認しました。

【参考】
AWSコンソールのサインインイベント

1. RootによるMFAでのログイン成功

  • userIdentity.typeRootとなり、userIdentity.userNameはありません。
  • ログイン成功の場合、responseElements.ConsoleLoginSuccessになります。
  • MFAを有効化している場合、additionalEventData.MFAUsedYesになります。
ConsoleLogin
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "Root",
        "principalId": "<AWSアカウント>",
        "arn": "arn:aws:iam::<AWSアカウント>:root",
        "accountId": "<AWSアカウント>",
        "accessKeyId": ""
    },
    "eventTime": "2021-01-31T08:33:01Z",
    "eventSource": "signin.amazonaws.com",
    "eventName": "ConsoleLogin",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "xx.77.xx.22",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
    "requestParameters": null,
    "responseElements": {
        "ConsoleLogin": "Success"
    },
    "additionalEventData": {
        "LoginTo": "https://console.aws.amazon.com/console/home?state=hashArgs%23&isauthcode=true",
        "MobileVersion": "No",
        "MFAUsed": "Yes"
    },
    "eventID": "0f6a04f5-812a-44ed-bb2c-c7c013299db8",
    "readOnly": false,
    "eventType": "AwsConsoleSignIn",
    "managementEvent": true,
    "eventCategory": "Management",
    "recipientAccountId": "<AWSアカウント>"
}

2. RootによるMFAでのログイン失敗

  • errorMessageFailed authenticationとなります。
  • responseElements.ConsoleLoginFailureになります。
ConsoleLogin
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "Root",
        "principalId": "<AWSアカウント>",
        "arn": "arn:aws:iam::<AWSアカウント>:root",
        "accountId": "<AWSアカウント>",
        "accessKeyId": ""
    },
    "eventTime": "2021-01-31T08:50:23Z",
    "eventSource": "signin.amazonaws.com",
    "eventName": "ConsoleLogin",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "xx.77.xx.22",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
    "errorMessage": "Failed authentication",
    "requestParameters": null,
    "responseElements": {
        "ConsoleLogin": "Failure"
    },
    "additionalEventData": {
        "LoginTo": "https://console.aws.amazon.com/console/home?region=us-east-1&state=hashArgs%23&isauthcode=true",
        "MobileVersion": "No",
        "MFAUsed": "Yes"
    },
    "eventID": "5075af8e-68bf-48c8-a370-387465236c6f",
    "readOnly": false,
    "eventType": "AwsConsoleSignIn",
    "managementEvent": true,
    "eventCategory": "Management",
    "recipientAccountId": "<AWSアカウント>"
}

3. IAMユーザによるMFAでのログイン成功

  • IAMユーザによるログインの場合、userIdentity.typeIAMUserとなります。
  • userIdentity.userNameにIAMユーザ名が記載されます。
  • Rootの場合は出なかったeventNameCheckMfaがConsoleLoginの直前に出ます。
  • additionalEventData.MfaTypeに利用しているMFAの種類が記載されます。
CheckMfa
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "IAMUser",
        "principalId": "AIDAILMY2GLOUWEUNCVCC",
        "accountId": "<AWSアカウント>",
        "accessKeyId": "",
        "userName": "hibino"
    },
    "eventTime": "2021-02-01T00:47:39Z",
    "eventSource": "signin.amazonaws.com",
    "eventName": "CheckMfa",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "xx.77.xx.22",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
    "requestParameters": null,
    "responseElements": {
        "CheckMfa": "Success"
    },
    "additionalEventData": {
        "MfaType": "Virtual MFA"
    },
    "eventID": "35bb6d1e-2250-420a-9f26-97cb5b3d19cf",
    "readOnly": true,
    "eventType": "AwsConsoleSignIn",
    "managementEvent": true,
    "eventCategory": "Management",
    "recipientAccountId": "<AWSアカウント>"
}
ConsoleLogin
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "IAMUser",
        "principalId": "AIDAILMY2GLOUWEUNCVCC",
        "arn": "arn:aws:iam::<AWSアカウント>:user/hibino",
        "accountId": "<AWSアカウント>",
        "userName": "hibino"
    },
    "eventTime": "2021-01-31T08:44:20Z",
    "eventSource": "signin.amazonaws.com",
    "eventName": "ConsoleLogin",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "xx.77.xx.22",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
    "requestParameters": null,
    "responseElements": {
        "ConsoleLogin": "Success"
    },
    "additionalEventData": {
        "LoginTo": "https://console.aws.amazon.com/console/home?state=hashArgs%23&isauthcode=true",
        "MobileVersion": "No",
        "MFAUsed": "Yes"
    },
    "eventID": "09c1e27b-b1c0-4828-a3bc-898f8fe75542",
    "readOnly": false,
    "eventType": "AwsConsoleSignIn",
    "managementEvent": true,
    "eventCategory": "Management",
    "recipientAccountId": "<AWSアカウント>"
}

4. IAMユーザによるMFAでのログイン失敗

  • Rootの場合と同様にerrorMessageresponseElements.ConsoleLoginに失敗が記録されます。
  • パスワードでミスしても、MFA認証コードでミスしてもログイン失敗のログの出方は同じでした。
ConsoleLogin
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "IAMUser",
        "principalId": "AIDAILMY2GLOUWEUNCVCC",
        "accountId": "<AWSアカウント>",
        "accessKeyId": "",
        "userName": "hibino"
    },
    "eventTime": "2021-02-01T00:47:46Z",
    "eventSource": "signin.amazonaws.com",
    "eventName": "ConsoleLogin",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "xx.77.xx.22",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
    "errorMessage": "Failed authentication",
    "requestParameters": null,
    "responseElements": {
        "ConsoleLogin": "Failure"
    },
    "additionalEventData": {
        "LoginTo": "https://console.aws.amazon.com/console/home?state=hashArgs%23&isauthcode=true",
        "MobileVersion": "No",
        "MFAUsed": "Yes"
    },
    "eventID": "01bc313d-36e3-49c0-9aea-59fadf5b85e2",
    "readOnly": false,
    "eventType": "AwsConsoleSignIn",
    "managementEvent": true,
    "eventCategory": "Management",
    "recipientAccountId": "<AWSアカウント>"
}

5. 存在しないIAMユーザでのログイン失敗

  • userIdentity.userNameHIDDEN_DUE_TO_SECURITY_REASONSと記録されます。
  • errorMessageNo username found in supplied accountと記録されます。
  • responseElements.ConsoleLoginは他の失敗ケースと同じくFailureになります。
ConsoleLogin
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "IAMUser",
        "accountId": "<AWSアカウント>",
        "accessKeyId": "",
        "userName": "HIDDEN_DUE_TO_SECURITY_REASONS"
    },
    "eventTime": "2020-12-04T14:16:21Z",
    "eventSource": "signin.amazonaws.com",
    "eventName": "ConsoleLogin",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "xx.77.xx.22",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36",
    "errorMessage": "No username found in supplied account",
    "requestParameters": null,
    "responseElements": {
        "ConsoleLogin": "Failure"
    },
    "additionalEventData": {
        "LoginTo": "https://console.aws.amazon.com/console/home?state=hashArgs%23&isauthcode=true",
        "MobileVersion": "No",
        "MFAUsed": "No"
    },
    "eventID": "4da3f90f-7106-40e0-9d11-a7c5df239087",
    "readOnly": false,
    "eventType": "AwsConsoleSignIn",
    "managementEvent": true,
    "eventCategory": "Management",
    "recipientAccountId": "<AWSアカウント>"
}

6. IAMユーザによるパスワードのみでのログイン成功

  • MFA利用時との違いは、additionalEventData.MFAUsedNoになります。
ConsoleLogin
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "IAMUser",
        "principalId": "AIDA6BYSTFHILFUDTGXUM",
        "arn": "arn:aws:iam::<AWSアカウント>:user/hibino-dev",
        "accountId": "<AWSアカウント>",
        "userName": "hibino-dev"
    },
    "eventTime": "2021-01-31T09:20:03Z",
    "eventSource": "signin.amazonaws.com",
    "eventName": "ConsoleLogin",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "xx.77.xx.22",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
    "requestParameters": null,
    "responseElements": {
        "ConsoleLogin": "Success"
    },
    "additionalEventData": {
        "LoginTo": "https://console.aws.amazon.com/console/home?state=hashArgs%23&isauthcode=true",
        "MobileVersion": "No",
        "MFAUsed": "No"
    },
    "eventID": "2745884d-f2ec-4840-8f85-59d333f8c12c",
    "readOnly": false,
    "eventType": "AwsConsoleSignIn",
    "managementEvent": true,
    "eventCategory": "Management",
    "recipientAccountId": "<AWSアカウント>"
}

7. IAMユーザによるパスワードのみでのログイン失敗

  • あまり特筆すべきポイントはありません。MFAなしのログイン失敗の組み合わせです。
ConsoleLogin
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "IAMUser",
        "principalId": "AIDA6BYSTFHILFUDTGXUM",
        "accountId": "<AWSアカウント>",
        "accessKeyId": "",
        "userName": "hibino-dev"
    },
    "eventTime": "2021-01-31T09:20:43Z",
    "eventSource": "signin.amazonaws.com",
    "eventName": "ConsoleLogin",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "xx.77.xx.22",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
    "errorMessage": "Failed authentication",
    "requestParameters": null,
    "responseElements": {
        "ConsoleLogin": "Failure"
    },
    "additionalEventData": {
        "LoginTo": "https://console.aws.amazon.com/console/home?state=hashArgs%23&isauthcode=true",
        "MobileVersion": "No",
        "MFAUsed": "No"
    },
    "eventID": "6d583a92-5743-4d93-bc2b-3efa0f3d30aa",
    "readOnly": false,
    "eventType": "AwsConsoleSignIn",
    "managementEvent": true,
    "eventCategory": "Management",
    "recipientAccountId": "<AWSアカウント>"
}

8. 別アカウントからスイッチユーザによるログイン成功

  • eventNameがConsoleLoginではなく、SwitchRoleになります。
  • additionalEventData.SwitchFrom接続元のARNが記録されます。
  • userIdentity.arnスイッチ後のARNが記録されます。
SwitchRole
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "AROAINH3FNBVMXGP7YQ2E:h_hibino",
        "arn": "arn:aws:sts::<AWSアカウント1>:assumed-role/dev/h_hibino",
        "accountId": "<AWSアカウント1>"
    },
    "eventTime": "2021-01-31T11:14:42Z",
    "eventSource": "signin.amazonaws.com",
    "eventName": "SwitchRole",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "xx.77.xx.22",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Safari/605.1.15",
    "requestParameters": null,
    "responseElements": {
        "SwitchRole": "Success"
    },
    "additionalEventData": {
        "SwitchFrom": "arn:aws:iam::<AWSアカウント2>:user/h_hibino",
        "RedirectTo": "https://us-east-2.console.aws.amazon.com/console/home?region=us-east-2#"
    },
    "eventID": "3a1f47b5-c5c5-44be-836f-f489956d194a",
    "readOnly": false,
    "eventType": "AwsConsoleSignIn",
    "managementEvent": true,
    "eventCategory": "Management",
    "recipientAccountId": "<AWSアカウント1>"
}

まとめ

以上ですが、いかがでしたでしょうか?

見張る上で必要なポイントは概ねCloudTrailの証跡ログで追うことができることがわかりました。

唯一、把握出来なかったのが、Rootで利用しているMFAのタイプでした。
Rootの場合はなぜかCheckMfaのイベントが出力されないため
additionalEventData.MfaTypeを確認することが出来ませんでした。

ログの内容を理解できれば、次はどのようにこのログを使って監視をすれば良いか見えてきますね^^

【参考】
【CloudTrail解説編】VPC操作ってどんなログ出るの?
【CloudTrail解説編】IAM操作ってどんなログ出るの?

7
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3