

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Transfer Family Web 應用程式的 CloudTrail 記錄
<a name="webapp-cloudtrail"></a>

CloudTrail 是在 中 AWS 服務 建立所採取動作記錄的 AWS 帳戶。它會持續監控並記錄 API 操作，以進行主控台登入、 AWS Command Line Interface 命令和 SDK/API 操作等活動。這可讓您保留由誰採取動作的日誌，以及從何處採取的動作。CloudTrail 透過提供 AWS 環境中所有活動的歷史記錄，協助稽核、存取管理和法規遵循。

對於 Transfer Family Web 應用程式，您可以追蹤身分驗證事件和使用者執行的資料存取操作。若要啟用完整記錄，您需要：

1. 設定 CloudTrail 記錄用於追蹤身分驗證活動的管理事件。

1. 啟用 Amazon S3 資料事件，以追蹤透過 Web 應用程式執行的檔案操作。

**另請參閱**
+ [IAM Identity Center 的 CloudTrail 使用案例](https://docs.aws.amazon.com/singlesignon/latest/userguide/sso-cloudtrail-use-cases.html)
+ [了解 IAM Identity Center 登入事件](https://docs.aws.amazon.com/singlesignon/latest/userguide/understanding-sign-in-events.html)
+ [CloudTrail userIdentity 元素](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-user-identity.html)
+ [啟用 S3 儲存貯體和物件的 CloudTrail 事件記錄](https://docs.aws.amazon.com/AmazonS3/latest/userguide/enable-cloudtrail-logging-for-s3.html)
+ [Amazon S3 CloudTrail 事件](https://docs.aws.amazon.com/AmazonS3/latest/userguide/cloudtrail-logging-s3-info.html)

## 啟用 Amazon S3 資料事件
<a name="webapp-enable-s3-data-events"></a>

若要追蹤透過 Transfer Family Web 應用程式在 Amazon S3 儲存貯體上執行的檔案操作，您需要啟用這些儲存貯體的資料事件。資料事件提供物件層級 API 活動，對於追蹤 Web 應用程式使用者執行的檔案上傳、下載和其他操作特別有用。

若要為 Transfer Family Web 應用程式啟用 Amazon S3 資料事件：

1. 前往 [https://console.aws.amazon.com/cloudtrail/](https://console.aws.amazon.com/cloudtrail/) 開啟 CloudTrail 主控台。

1. 在導覽窗格中，選擇**線索**，然後選取現有的線索或建立新的線索。

1. 在**進階事件選取器**下，選擇**編輯**。

1. 選擇**新增進階事件選取器**。

1. 對於第一個欄位選擇器：
   + 將**欄位**設定為 `eventCategory`
   + 將**運算子**設定為**等於**
   + 將**值**設定為 `Data`

1. 針對第二個**欄位選擇器選擇新增**欄位和 ：
   + 將**欄位**設定為 `resources.type`
   + 將**運算子**設定為**等於**
   + 將**值**設定為 `AWS::S3::Object`

1. （選用） 若要僅記錄特定儲存貯體的事件，請選擇**新增欄位**並新增：
   + 將**欄位**設定為 `resources.ARN`
   + 將**運算子**設定為從 **開始**
   + 將**值**設定為 `arn:aws:s3:::your-bucket-name/`

1. 選擇**儲存變更**。

或者，您可以使用舊版資料事件組態：

1. 在**資料事件**下，選擇**編輯**。

1. 針對**資料事件類型**，選取 **S3 儲存貯體和物件事件**。

1. 選擇要記錄資料事件的 Amazon S3 儲存貯體。您可以選取**所有目前和未來的 S3 儲存貯**體，或指定個別儲存貯體。

1. 選擇記錄**讀取**事件、**寫入**事件或兩者。

1. 選擇**儲存變更**。

啟用資料事件後，您可以在為 CloudTrail 設定的 Amazon S3 儲存貯體中存取這些日誌。日誌包含詳細資訊，例如執行動作的使用者、動作時間戳記、受影響的特定物件，以及協助追蹤透過 Transfer Family Web 應用程式執行之動作`userId`的 `onBehalfOf` 欄位。

### 尋找和檢視您的日誌
<a name="webapp-find-view-logs"></a>

有幾種方式可以尋找和檢視 Transfer Family Web 應用程式的 CloudTrail 日誌：

#### 使用 CloudTrail 主控台
<a name="webapp-find-logs-console"></a>

檢視最近事件的最快方式：

1. 前往 [https://console.aws.amazon.com/cloudtrail/](https://console.aws.amazon.com/cloudtrail/) 開啟 CloudTrail 主控台。

1. 選擇**事件歷史記錄**。

1. 依下列條件篩選事件：
   + **事件來源**：`signin.amazonaws.com`適用於 Web 應用程式事件
   + **事件來源**：`s3.amazonaws.com`用於檔案操作

1. 按一下任何事件以檢視詳細資訊。

#### 在 Amazon S3 中存取日誌
<a name="webapp-find-logs-s3"></a>

若要存取存放在 Amazon S3 中的完整日誌檔案：

1. 識別 CloudTrail 追蹤的 Amazon S3 儲存貯體：

   ```
   aws cloudtrail describe-trails --query 'trailList[*].[Name,S3BucketName]' --output table
   ```

1. 導覽至 Amazon S3 中的日誌檔案：

   ```
   aws s3 ls s3://your-cloudtrail-bucket/AWSLogs/account-id/CloudTrail/region/YYYY/MM/DD/
   ```

1. 下載並搜尋 Web 應用程式 ID 的日誌檔案：

   ```
   aws s3 cp s3://your-cloudtrail-bucket/AWSLogs/account-id/CloudTrail/region/YYYY/MM/DD/ . --recursive
   gunzip *.json.gz
   grep -l "webapp-1a2b3c4d5e6f7g8h9" *.json
   ```

#### 使用 AWS CLI 搜尋事件
<a name="webapp-find-logs-cli"></a>

使用 搜尋特定的 Web 應用程式事件 AWS CLI：

```
aws logs filter-log-events \
  --log-group-name /aws/cloudtrail/your-trail-name \
  --filter-pattern "webapp-1a2b3c4d5e6f7g8h9" \
  --start-time $(date -d "1 day ago" +%s)000
```

或搜尋身分驗證事件：

```
aws logs filter-log-events \
  --log-group-name /aws/cloudtrail/your-trail-name \
  --filter-pattern "UserAuthentication" \
  --start-time $(date -d "1 day ago" +%s)000
```

## 身分驗證日誌範例
<a name="webapp-authentication-log-examples"></a>

CloudTrail 會記錄 Transfer Family Web 應用程式的身分驗證事件，這可協助您追蹤成功和失敗的登入嘗試。這些日誌對於安全監控和合規用途特別有用。

**Topics**
+ [登入資料驗證的範例日誌項目](#webapp-credential-verification-example)
+ [登入身分驗證的範例日誌項目](#webapp-signin-authentication-example)
+ [ListCallerAccessGrants 的範例日誌項目](#webapp-list-caller-access-grants-example)
+ [GetDataAccess 事件的範例日誌項目](#webapp-get-data-access-example)

### 登入資料驗證的範例日誌項目
<a name="webapp-credential-verification-example"></a>

下列範例顯示憑證驗證事件在身分驗證程序期間發生的 CloudTrail 日誌項目。

```
{
    "eventVersion": "1.09",
    "userIdentity": {
        "type": "Unknown",
        "principalId": "123456789012",
        "arn": "",
        "accountId": "123456789012",
        "accessKeyId": "",
        "userName": "demo-user-2",
        "onBehalfOf": {
            "userId": "f12bb510-a011-702f-10dd-5607e2776dbc",
            "identityStoreArn": "arn:aws:identitystore::123456789012:identitystore/d-9a670c546e"
        },
        "credentialId": "58138a11-87e5-401d-8f0b-7161c9389112"
    },
    "eventTime": "2025-08-08T15:29:30Z",
    "eventSource": "signin.amazonaws.com",
    "eventName": "CredentialVerification",
    "awsRegion": "us-east-2",
    "sourceIPAddress": "192.0.2.224",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
    "requestParameters": null,
    "responseElements": null,
    "additionalEventData": {
        "AuthWorkflowID": "f304a48b-7b6d-41c8-b136-4f49c91c1f31",
        "CredentialType": "PASSWORD"
    },
    "requestID": "ff936828-4a81-453c-802d-81368b6bca1a",
    "eventID": "70cb7008-493d-42c2-a9eb-38bf168af6a8",
    "readOnly": false,
    "eventType": "AWS ServiceEvent",
    "managementEvent": true,
    "recipientAccountId": "123456789012",
    "serviceEventDetails": {
        "CredentialVerification": "Success"
    },
    "eventCategory": "Management"
}
```

此事件提供身分驗證程序中登入資料驗證步驟的其他詳細資訊，顯示使用的特定登入資料 ID 和身分驗證工作流程 ID。

### 登入身分驗證的範例日誌項目
<a name="webapp-signin-authentication-example"></a>

下列範例顯示使用 IAM Identity Center 登入 Web 應用程式期間成功使用者身分驗證事件的 CloudTrail 日誌項目。

```
{
    "eventVersion": "1.09",
    "userIdentity": {
        "type": "Unknown",
        "principalId": "123456789012",
        "arn": "",
        "accountId": "123456789012",
        "accessKeyId": "",
        "userName": "demo-user-2",
        "onBehalfOf": {
            "userId": "f12bb510-a011-702f-10dd-5607e2776dbc",
            "identityStoreArn": "arn:aws:identitystore::123456789012:identitystore/d-9a670c546e"
        },
        "credentialId": "b41f0a02-1635-4d07-a414-aecf9e14b906"
    },
    "eventTime": "2025-08-07T14:09:07Z",
    "eventSource": "signin.amazonaws.com",
    "eventName": "UserAuthentication",
    "awsRegion": "us-east-2",
    "sourceIPAddress": "192.0.2.14",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
    "requestParameters": null,
    "responseElements": null,
    "additionalEventData": {
        "AuthWorkflowID": "7a4ef12c-7c4b-4bc3-b5bd-c2469afcc795",
        "LoginTo": "https://example.awsapps.com/start/",
        "CredentialType": "PASSWORD"
    },
    "requestID": "fc91bcf0-ac53-4454-a1a0-fb911eacc095",
    "eventID": "18522007-1e60-4a71-b2b5-150baf504ab3",
    "readOnly": false,
    "eventType": "AWS ServiceEvent",
    "managementEvent": true,
    "recipientAccountId": "123456789012",
    "serviceEventDetails": {
        "UserAuthentication": "Success"
    },
    "eventCategory": "Management"
}
```

在此範例中，請注意下列重要欄位：
+ `eventSource`：顯示 "signin.amazonaws.com"，表示這是 IAM Identity Center 身分驗證事件。
+ `userIdentity.onBehalfOf`：包含 Web 應用程式使用者的使用者 ID 和身分存放區 ARN。
+ `additionalEventData.LoginTo`：顯示正在存取的 IAM Identity Center 應用程式 URL。
+ `additionalEventData.CredentialType`：指出使用的身分驗證方法 (PASSWORD)。
+ `serviceEventDetails`：顯示身分驗證結果 （成功）。

### ListCallerAccessGrants 的範例日誌項目
<a name="webapp-list-caller-access-grants-example"></a>

下列範例顯示 ListCallerAccessGrants 事件的 CloudTrail 日誌項目，當 Transfer Family Web 應用程式查詢使用者的可用存取授權時發生。

```
{
    "eventVersion": "1.11",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "AROAEXAMPLEID:aws-transfer",
        "arn": "arn:aws:sts::123456789012:assumed-role/AWS TransferWebAppIdentityBearer-us-east-2/aws-transfer",
        "accountId": "123456789012",
        "accessKeyId": "ASIAEXAMPLEKEY",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "AROAEXAMPLEID",
                "arn": "arn:aws:iam::123456789012:role/service-role/AWS TransferWebAppIdentityBearer-us-east-2",
                "accountId": "123456789012",
                "userName": "AWS TransferWebAppIdentityBearer-us-east-2"
            },
            "attributes": {
                "creationDate": "2025-08-08T15:29:34Z",
                "mfaAuthenticated": "false"
            }
        },
        "invokedBy": "transfer.amazonaws.com",
        "onBehalfOf": {
            "userId": "f12bb510-a011-702f-10dd-5607e2776dbc",
            "identityStoreArn": "arn:aws:identitystore::123456789012:identitystore/d-9a670c546e"
        }
    },
    "eventTime": "2025-08-08T15:29:35Z",
    "eventSource": "s3.amazonaws.com",
    "eventName": "ListCallerAccessGrants",
    "awsRegion": "us-east-2",
    "sourceIPAddress": "transfer.amazonaws.com",
    "userAgent": "transfer.amazonaws.com",
    "requestParameters": {
        "Host": "123456789012.s3-control.dualstack.us-east-2.amazonaws.com",
        "allowedByApplication": "true",
        "maxResults": "100"
    },
    "responseElements": null,
    "additionalEventData": {
        "SignatureVersion": "SigV4",
        "CipherSuite": "TLS_AES_128_GCM_SHA256",
        "bytesTransferredIn": 0,
        "AuthenticationMethod": "AuthHeader",
        "x-amz-id-2": "1g34AaAELn/fntxwrifVsr41VDl8dp5ygWFasHJFNVq5FDCWYfX0ye7s4tWHEJC8ppI5lLePYLIcw3iTXAgn5Q==",
        "bytesTransferredOut": 462
    },
    "requestID": "48485MTZEDWT0ANT",
    "eventID": "3de5dd60-b7cf-474c-a1ab-631467c1a5c3",
    "readOnly": true,
    "resources": [
        {
            "accountId": "123456789012",
            "type": "AWS:S3::AccessGrantsInstance",
            "ARN": "arn:aws:s3:us-east-2:123456789012:access-grants/default"
        }
    ],
    "eventType": "AWS ApiCall",
    "managementEvent": true,
    "recipientAccountId": "123456789012",
    "eventCategory": "Management"
}
```

在此範例中，請注意下列重要欄位：
+ `eventName`：顯示這是 ListCallerAccessGrants 事件，可查詢可用的 S3 存取授權。
+ `requestParameters.allowedByApplication`：表示查詢會篩選為應用程式允許的授予。
+ `requestParameters.maxResults`：顯示回應中傳回的授予數量上限。
+ `userIdentity.onBehalfOf`：將請求連結至特定 Web 應用程式使用者。

此事件有助於追蹤 Transfer Family Web 應用程式何時查詢使用者可存取的 S3 資源，提供存取授權探索操作的可見性。

### GetDataAccess 事件的範例日誌項目
<a name="webapp-get-data-access-example"></a>

下列範例顯示 GetDataAccess 事件的 CloudTrail 日誌項目，會在 Transfer Family Web 應用程式代表使用者請求 S3 資源的存取許可時發生。

```
{
    "eventVersion": "1.11",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "AROASEQRAEABP7ADWEZA5:aws-transfer",
        "arn": "arn:aws:sts::123456789012:assumed-role/AWSTransferWebAppIdentityBearer-ap-southeast-1/aws-transfer",
        "accountId": "123456789012",
        "accessKeyId": "ASIAEXAMPLEKEY",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "AROASEQRAEABP7ADWEZA5",
                "arn": "arn:aws:iam::123456789012:role/service-role/AWSTransferWebAppIdentityBearer-ap-southeast-1",
                "accountId": "123456789012",
                "userName": "AWSTransferWebAppIdentityBearer-ap-southeast-1"
            },
            "attributes": {
                "creationDate": "2025-05-08T16:09:05Z",
                "mfaAuthenticated": "false"
            }
        },
        "invokedBy": "transfer.amazonaws.com",
        "onBehalfOf": {
            "identityStoreArn": "arn:aws:identitystore::123456789012:identitystore/d-9667b0da7a",
            "userId": "191a35ec-10a1-70c1-e4ab-e2802411e13e"
        }
    },
    "eventTime": "2025-05-08T16:10:25Z",
    "eventSource": "s3.amazonaws.com",
    "eventName": "GetDataAccess",
    "awsRegion": "ap-southeast-1",
    "sourceIPAddress": "transfer.amazonaws.com",
    "userAgent": "transfer.amazonaws.com",
    "requestParameters": {
        "Host": "123456789012.s3-control.dualstack.ap-southeast-1.amazonaws.com",
        "durationSeconds": 900,
        "permission": "READWRITE",
        "target": "s3://amzn-s3-demo-bucket/users/john.doe/documents/*"
    },
    "responseElements": null,
    "additionalEventData": {
        "AuthenticationMethod": "AuthHeader",
        "CipherSuite": "TLS_AES_128_GCM_SHA256",
        "SignatureVersion": "SigV4",
        "bytesTransferredIn": 0,
        "bytesTransferredOut": 2244,
        "x-amz-id-2": "8ce8sZOgNwsaj9w1mzagyA+csONjYl8FgEw4FGpE8DARi90aNC0RFWlTYNEn7ChqE9RCJrTzMvS+ru7Vz2xXHrkQt/1uQ9exZTZdlhX+/fM="
    },
    "requestID": "BXGSKKQXCWS5RAHB",
    "eventID": "c11db1d1-dfb8-431e-8625-48eba2ebadfe",
    "readOnly": true,
    "resources": [
        {
            "type": "AWS:S3::AccessGrantsInstance",
            "ARN": "arn:aws:s3:ap-southeast-1:123456789012:access-grants/default",
            "accountId": "123456789012"
        }
    ],
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "recipientAccountId": "123456789012",
    "eventCategory": "Management"
}
```

在此範例中，請注意下列重要欄位：
+ `eventName`：顯示這是一個 GetDataAccess 事件，會在 Transfer Family 請求 S3 資源的存取許可時發生。
+ `userIdentity.onBehalfOf`：包含身分存放區 ARN 和使用者 ID，將存取請求連結至特定的 Web 應用程式使用者。
+ `requestParameters.target`：顯示請求存取的 S3 路徑模式。
+ `requestParameters.permission`：指出請求的存取類型 (READWRITE、READWRITE 或 WRITE)。
+ `requestParameters.durationSeconds`：顯示存取授權的有效時間長度 （通常為 900 秒/15 分鐘）。
+ `sourceIPAddress` 和 `userAgent`：兩者都顯示 "transfer.amazonaws.com"，表示這是內部服務請求。

GetDataAccess 事件特別適用於追蹤 Transfer Family Web 應用程式使用者何時獲得特定 S3 資源的存取權，協助您監控存取模式並確保適當的授權。

## 檢視 CloudTrail 日誌項目
<a name="webapp-view-log-entries"></a>

有幾種方式可以檢視和分析 Transfer Family Web 應用程式的 CloudTrail 日誌項目：

### 使用 CloudTrail 主控台
<a name="webapp-view-logs-console"></a>

CloudTrail 主控台提供易於使用的界面，用於檢視和篩選日誌項目：

1. 透過 [https://console.aws.amazon.com/cloudtrail/](https://console.aws.amazon.com/cloudtrail/) 開啟 CloudTrail 主控台。

1. 在導覽窗格中，選擇 **Event history** (事件歷史記錄)。

1. 使用篩選條件選項縮小事件範圍：
   + 將**事件來源**設定為 `transfer.amazonaws.com`，以僅檢視 Transfer Family 事件。
   + 依**事件名稱**篩選，以查看特定操作，例如 `UserAuthentication`。
   + 使用**時間範圍**來專注於特定期間內的事件。

1. 按一下任何事件以檢視其詳細資訊。

### 在 Amazon S3 中存取日誌
<a name="webapp-view-logs-s3"></a>

如果您已設定 CloudTrail 追蹤將日誌交付到 Amazon S3 儲存貯體，您可以直接存取原始日誌檔案：

1. 開啟位於 [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/) 的 Amazon S3 主控台。

1. 導覽至存放 CloudTrail 日誌的儲存貯體和字首。

1. 日誌會依年、月、日和區域進行組織。導覽至適當的目錄。

1. 下載並開啟 JSON 格式的日誌檔案。