我想要在 Amazon OpenSearch Service 中啟用稽核日誌。
簡短說明
若要啟用稽核日誌,請先將您的網域設定為將稽核日誌發佈至 Amazon CloudWatch Logs。接著,在 OpenSearch Dashboards 中啟用並設定稽核日誌。
如需更多資訊,請參閱在 Amazon OpenSearch Service 中監控稽核日誌。
解決方法
**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,請參閱對 AWS CLI 錯誤進行疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本。
在啟用稽核日誌之前,您必須先在叢集上啟用精細存取控制。
在 OpenSearch Service 中啟用稽核日誌
若要在 OpenSearch Service 中啟用稽核日誌並建立存取政策,請完成以下步驟:
-
開啟 OpenSearch Service console (OpenSearch Service 主控台)。
-
在導覽窗格中,選擇 Domains (網域),然後選擇您的網域。
-
選擇 Logs (日誌) 索引標籤,然後選擇 Audit logs (稽核日誌),接著選擇 Enable (啟用)。
-
選擇 Setup error logs (設定錯誤日誌),然後選取 Create new policy (建立新政策) 或 Select existing policy (選取現有政策)。
若要建立新政策,請於 New policy name (新政策名稱) 輸入政策名稱,然後使用以下範例的存取政策更新政策:
{ "Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "es.amazonaws.com"
},
"Action": [
"logs:PutLogEvents",
"logs:CreateLogStream"
],
"Resource": "cw_log_group_arn"
}
]
}
-
選擇 Enable (啟用)。
在 OpenSearch Dashboards 中啟用稽核日誌
請完成下列步驟:
- 開啟 OpenSearch Dashboards。
- 選擇 Security (安全性)。
**注意:**若要啟用稽核日誌,您的使用者角色必須對應到 security_manager (安全管理員) 角色。否則,您無法在 OpenSearch Dashboards 中看到 Security (安全性) 索引標籤。
- 選擇 Audit logs (稽核日誌)。
- 選擇 Enable audit logging (啟用稽核日誌)。
組態範例,請參閱 Audit log example (稽核日誌範例)。
稽核日誌錯誤疑難排解
您未設定進階安全選項
當您啟用稽核日誌而網域未啟用精細存取控制時,您會收到下列錯誤:
「UpdateDomainConfig: {"message":"audit log publishing cannot be enabled as you do not have advanced security options configured."}」
若要解決此錯誤,請啟用精細存取控制。
超過資源限制
當您在每個 AWS 區域中達到 CloudWatch Logs 資源政策的最大數量時,您會收到以下錯誤:
「PutResourcePolicy: {"__type":"LimitExceededException","message":"Resource limit exceeded."}」
每個帳戶在每個區域最多可擁有 10 個 CloudWatch Logs 資源政策。您無法更改此配額。如需更多資訊,請參閱 CloudWatch 日誌配額。
若要為多個網域啟用日誌,您可以重複使用包含多個日誌群組的政策。
若要檢查帳戶中每個區域的資源政策,請執行 describe-resource-policies AWS CLI 命令:
aws logs describe-resource-policies --region region-name
**注意:**將 region-name 替換為您的區域。
若要更新資源政策以涵蓋多個日誌群組,請加入萬用字元 *。您也可以針對所有日誌群組設定來自不同資源政策的多個陳述式,並刪除舊的政策。
例如,如果您的日誌群組名稱以 /aws/OpenSearchService/domains/ 開頭,那麼您可以建立一個適用於 /aws/OpenSearchService/domains/* 的資源政策。
下列範例資源政策會為所有名稱以 /aws/OpenSearchService/domains/* 開頭的日誌群組建立單一資源政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "es.amazonaws.com"
},
"Action": [
"logs:PutLogEvents",
"logs:CreateLogStream"
],
"Resource": "arn:aws:logs:REGION:AccountID:log-group:/aws/OpenSearchService/domains/*:*"
}
]
}
**注意:**將 Region 替換為您的區域。**將 **AccountID 替換為您的帳戶 ID。
若要套用合併後的政策,請在 CloudShell 上執行以下命令:
aws logs put-resource-policy \
--policy-name yourPolicyName \
--policy-document file://policy.json
**注意:**將 yourPolicyName 替換為您自己的政策名稱。
啟用稽核日誌時,您現在可以選取此更新後的政策。
若要移除不必要或重複的政策,請執行 delete-resource-policy 命令:
aws logs delete-resource-policy --policy-name PolicyName
**注意:**將 PolicyName 替換為您想要刪除的政策名稱。
CloudWatch Logs 中日誌群組的存取政策未授予足夠權限
當您嘗試啟用稽核日誌發佈時,您可能會收到以下錯誤:
「The Resource Access Policy specified for the CloudWatch Logs log group does not grant sufficient permissions for Amazon OpenSearch Service to create a log stream.Please check the Resource Access Policy.」
若要解決此錯誤,請確認您的政策資源元素包含正確的日誌群組 ARN。
相關資訊
如何對 OpenSearch Service 叢集的精細存取控制問題進行疑難排解?
對 Amazon OpenSearch Service 進行疑難排解