Security Hub の KMS.5 は Config がキーポリシーを参照できない場合にも失敗する話
Security Hub controls for AWS KMS - AWS Security Hub
This control also returns a FAILED finding for an AWS KMS key if your configurations prevent AWS Config from recording the key policy in the Configuration Item (CI) for the KMS key.
上記仕様を確認してみました。
KMS キーの作成
デフォルト設定で CMK を 作成しました。
現在のキーポリシーは以下の通りです。
{
"Id": "key-consolepolicy-3",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::012345678901:root"
},
"Action": "kms:*",
"Resource": "*"
}
]
}
デフォルトのキーポリシーのみの状態であるため、IAM 側でアクセス権があればキーへのアクセスが可能です。
Default key policy - AWS Key Management Service
It allows the account to use IAM policies to allow access to the KMS key, in addition to the key policy.
AWS Config ではサービスロールである AWSServiceRoleForConfig が使用されており、当該サービスロールには AWSConfigServiceRolePolicy がアタッチされています。
Using Service-Linked Roles for AWS Config - AWS Config
AWSConfigServiceRolePolicy - AWS Managed Policy
AWSConfigServiceRolePolicy には KMS に関する以下の権限も含まれています。
- "kms:DescribeKey"
- "kms:GetKeyPolicy"
- "kms:GetKeyRotationStatus"
- "kms:ListAliases"
- "kms:ListKeys"
- "kms:ListResourceTags"
IAM 側で GetKeyPolicy が許可されているため、KMS のキーポリシーを参照できる状態です。
この状態で Config ルールを再評価した場合、KMS キーは準拠と判定されるため、Security Hub 側でも PASSED と評価されます。
キーポリシーを変更してみる
デフォルトのキーポリシーを変更して GetKeyPolicy のみ拒否してみます。
なお、GetKeyPolicy を拒否するとキーポリシーの閲覧はできなくなりますが、キーポリシーの変更は可能なため後述の手順で元に戻します。
{
"Id": "key-consolepolicy-3",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::012345678901:root"
},
"Action": "kms:*",
"Resource": "*"
},
{
"Effect": "Deny",
"Principal": {
"AWS": "arn:aws:iam::012345678901:root"
},
"Action": "kms:GetKeyPolicy",
"Resource": "*"
}
]
}
この状態で Config ルールを再評価した場合、KMS キーは非準拠と判定されるため、Security Hub 側でも FAILED と評価されます。
Config の非準拠の理由には以下のメッセージが記録されていました。
The AWS::KMS::Key configuration item (CI) does not contain a KMS key policy.
Verify that read access to the KMS key policy is provided to the AWS Config role so that the KMS key policy can be populated in the CI.
AWS Config からキーポリシーを参照できるように修正する必要がある旨のメッセージです。
キーポリシーを元に戻してみる
KMS でキーポリシーの変更を誤り「キーにアクセスする権限がありません」になったときの対処方法 | DevelopersIO
上記ブログを参考にデフォルトのキーポリシーを記載した default.json を作成し、AWS CLI の put-key-policy
コマンドでキーポリシーを元に戻します。
{
"Id": "key-consolepolicy-3",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::012345678901:root"
},
"Action": "kms:*",
"Resource": "*"
}
]
}
$ aws kms put-key-policy \
--key-id your-key-id \
--policy file://default.json
この状態で Config ルールを再評価した場合、Config が KMS キーのキーポリシーを参照できるため準拠と判定され、Security Hub 側でも PASSED と評価されます。
まとめ
今回は Security Hub の KMS.5 は Config がキーポリシーを参照できない場合にも失敗する話を紹介しました。
どなたかの参考になれば幸いです。
Discussion