- 概要
- やりたいこと
- Error: An error occurred (NoSuchConfigRuleException) when calling the DescribeConfigRules operation: The ConfigRule ‘ec2-instance-detailed-monitoring-enabled’ provided in the request is invalid. Please check the configRule name.
- [ERROR] AccessDeniedException: An error occurred (AccessDeniedException) when calling the BatchImportFindings operation: User: arn:aws:sts::444455556666:assumed-role/config-sechub-lambda-role-ap-northeast-1/Config-SecHub-Lambda is not authorized to perform: securityhub:BatchImportFindings on resource: arn:aws:securityhub:ap-northeast-1:111122223333:product/111122223333/default
- アーキテクチャ
- AWS アカウント間のイベントの送受信
- CloudFormation
- エラー
- Error occurred while GetObject. S3 Error Code: NoSuchKey. S3 Error Message: The specified key does not exist
- An error occurred (ValidationError) when calling the CreateChangeSet operation: Template error: instance of Fn::GetAtt references undefined resource arn:aws:events:ap-northeast-1:111111111111:event-bus/default
- “Provided role ‘arn:aws:iam::111111111111:role/event-send-crossaccount-role’ cannot be assumed by principal ‘events.amazonaws.com’.
- イベントを送れているかわからない
- 参考
概要
やりたいこと
今回は、Config Rules の評価結果を、別アカウントの SecurityHub にインポートしたい。
同アカウント内で、 AWS Config Rules を SecurityHub にインポートするのは以前行った。
Error: An error occurred (NoSuchConfigRuleException) when calling the DescribeConfigRules operation: The ConfigRule ‘ec2-instance-detailed-monitoring-enabled’ provided in the request is invalid. Please check the configRule name.
送信先と送信元で同じ Config Rules を有効化しておかないとエラーが出る。。
CloudWatch Logs に出力されていた。
[ERROR] AccessDeniedException: An error occurred (AccessDeniedException) when calling the BatchImportFindings operation: User: arn:aws:sts::444455556666:assumed-role/config-sechub-lambda-role-ap-northeast-1/Config-SecHub-Lambda is not authorized to perform: securityhub:BatchImportFindings on resource: arn:aws:securityhub:ap-northeast-1:111122223333:product/111122223333/default
Security Hub に Findings をインポートする際のエラーが出てしまい進まない。。
以下としている。
- アカウントA 送信側 : 111122223333
- アカウントB 受信側 : 444455556666
「Security Hub でアクションの実行を承認されていない」が該当しそう。
Lambda は BatchImportFindings を許可されていない。
arn:aws:securityhub:ap-northeast-1:111122223333:product/111122223333/default に対して。
リソースレベルでのアクセス許可ができていない可能性。
アーキテクチャ
同アカウント内で、Config Rules を Security Hub へインポートする場合の流れは以下。
- ConfigRules -> Amazon EventBridge -> Lambda -> SecurtiyHub
今回は、Config Rules が発生するアカウントと、取り込む Security Hub が以下の通り別となる。
- アカウントA : Config Rules
- アカウントB : SecurityHub
この場合、 Amazon EventBridge 間でイベントの送受信を行う。
- アカウントA の ConfigRules
- アカウントA の Amazon EventBridge
- アカウントB の Amazon EventBridge
- アカウントB の Lambda
- アカウントB の SecurityHub
AWS アカウント間のイベントの送受信
Amazon EventBridge を利用すれば、AWSアカウント間のイベントの送受信ができる。
手順は以下。
- 受信側 : 他の AWS アカウントからイベントを受信できるようにアクセス許可
- 受信側 : 別の AWS アカウントのイベントに一致するルール
- 送信側 : 受信アカウントにイベントを送信するためのアクセス許可
- 送信側 : 受信アカウントのイベントバスをターゲットとするルール
CloudFormation
- アカウントA 送信側 : 111122223333
- アカウントB 受信側 : 444455556666
アカウントB : 受信側
別の AWS アカウントからイベントを受信できるようアクセス許可
イベントバスポリシーを設定し、別の AWS アカウントのイベントの受信を許可する。
ReceiveEventBusPolicy: Type: AWS : : Events : : EventBusPolicy Properties: Action: "events:PutEvents" Principal: "111122223333" StatementId: "MyStatement" |
別の AWS アカウントのイベントの受信
別アカウントからのデータを受け取り、Target のアクションを行うルール。
※Lambda の CloudFormation 部分は前回のブログ参照。
ConfigSecHubCWRule: Type: AWS : : Events : : Rule Properties: Description: This CW rule integrates AWS Config Compliance events with AWS Lambda as a target Name: 'Config-Sechub-CW-Rule' EventPattern: source: - aws.config detail-type: - Config Rules Compliance Change detail: messageType: - ComplianceChangeNotification State: 'ENABLED' Targets: - Arn: Fn: : GetAtt : - 'ConfigSecHubFunction' - 'Arn' Id: 'TargetFunctionV1' |
デプロイすると default のイベントバスにルールが設定される。
aws cloudformation deploy \ --profile AccountB\ --stack-name send-configrules \ --template-file sendConfigRules.yaml \ --capabilities CAPABILITY_NAMED_IAM
アカウント A : 送信側
受信アカウントにイベントを送信するためのアクセス許可
クロスアカウントの場合送信・受信側両方にアクセス許可が必要となるため、送信側でも受信アカウントへ許可を出しておく。
Resources: EventSendRole: Type: 'AWS::IAM::Role' Properties: RoleName: 'event-send-crossaccount-role' AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Effect : Allow Principal: Service: - events.amazonaws.com Action: - 'sts:AssumeRole' Policies: - PolicyName : crossaccount-eventbridge-access-policy-policy PolicyDocument: Statement: - Effect : Allow Action: - 'events:PutEvents' Resource: - 'arn:aws:events:ap-northeast-1:444455556666:event-bus/default' |
受信アカウントのイベントバスをターゲットとするルール
上記で作った IAM Role をアタッチし、送信先の event-bus を Targets に指定する。
EventSendCrossAccount: Type: AWS : : Events : : Rule Properties: Description: This CW rule integrates AWS Config Compliance events with AWS Lambda as a target Name: 'Event-Send-Cross-Account' RoleArn: !GetAtt EventSendRole.Arn EventPattern: source: - aws.config detail-type: - Config Rules Compliance Change detail: messageType: - ComplianceChangeNotification State: 'ENABLED' Targets: - Arn: Fn: : GetAtt : - 'arn:aws:events:ap-northeast-1:444455556666:event-bus/default' - Arn Id: 'CrossAccountTargetId' |
デプロイ。
aws --profile AccountA cloudformation deploy \ --stack-name send-configrules \ --template-file sendConfigRules.yaml \ --capabilities CAPABILITY_NAMED_IAM
確認
送信元・受信先で同じ Config Rules を設定しておく必要がある。
送信元の Config Rules でコンプライアンスチェックを失敗させたあと、送信先の Security Hub で「Default」ログを確認できれば OK。

エラー
Error occurred while GetObject. S3 Error Code: NoSuchKey. S3 Error Message: The specified key does not exist
zip ファイルを S3 にアップロードしていない状態で Lambda を作成する CloudFormation を実行した際に出力。
An error occurred (ValidationError) when calling the CreateChangeSet operation: Template error: instance of Fn::GetAtt references undefined resource arn:aws:events:ap-northeast-1:111111111111:event-bus/default
EventBridge ルールの Targets をこう書いていた。リソースには別アカウントIDを指定。
Targets: - Arn: Fn: : GetAtt : - 'arn:aws:events:ap-northeast-1:111111111111:event-bus/default' - Arn |
正解はこう。
Targets: - Arn: "arn:aws:events:ap-northeast-1:111111111111:event-bus/default" Id: 'TargetAccount' |
“Provided role ‘arn:aws:iam::111111111111:role/event-send-crossaccount-role’ cannot be assumed by principal ‘events.amazonaws.com’.
Principal の Service に lambda.amazonaws.com を指定していた。
EventSendRole: Type: 'AWS::IAM::Role' Properties: RoleName: 'event-send-crossaccount-role' AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Effect : Allow Principal: Service: - lambda.amazonaws.com Action: - 'sts:AssumeRole' |
events.amazonaws.com を指定しなければならない。
EventSendRole: Type: 'AWS::IAM::Role' Properties: RoleName: 'event-send-crossaccount-role' AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Effect : Allow Principal: Service: - events.amazonaws.com Action: - 'sts:AssumeRole' |
イベントを送れているかわからない
送信元 EventBridge ルールのコンソールから「ルールのメトリクス」をクリック。

CloudWatch メトリクスのコンソールに飛び、そこで該当ルールのメトリクスが存在していれば、イベントは送っている。

送信先の EventBridge のメトリクスでも同様に値が存在していれば、受け取れてはいる。
コメント