はじめに
今回はイベントバスのアクセス許可周りを見てみます。
イベント送信できるのは同一アカウントのみ。
初期状態では、イベント送信できるのは同一アカウントのみとのことなので、動作確認してみます。
適当なカスタムイベントバスCross-Account-Bus
をアカウントAに作ってみます。
アカウントBでCLIを利用し、アカウントAのカスタムイベントバスにイベント送信(put-events)してみます!
aws events put-events \
--entries '[{
"Source": "custom.application",
"DetailType": "paid",
"Detail": "{\"payment_number\": \"00001\"}",
"EventBusName": "arn:aws:events:ap-northeast-1:AAAAAAAAAAAA:event-bus/Cross-Account-Bus"
}]' \
--region ap-northeast-1
確かに以下のようなエラーが出ました。
An error occurred (AccessDeniedException) when calling the PutEvents operation: User: arn:aws:sts::BBBBBBBBBBBB:assumed-role/AWSReservedSSO_AdministratorAccess_27a704c6bb0e0488/chelky is not authorized to perform: events:PutEvents on resource: arn:aws:events:ap-northeast-1:AAAAAAAAAAAA:event-bus/Cross-Account-Bus because no resource-based policy allows the events:PutEvents action
no resource-based policy allows the events:PutEvents action
とあり、リソースベースのポリシーで許可されていないよ。って感じです。
リソースベースのポリシーを設定してみる。
エラーの通り、リソースベースのポリシーを設定してみます。
テンプレートをロード
機能があるので、作成は簡単です。
こんな感じで設定してみました。
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "AllowAccountToPutEvents",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::BBBBBBBBBBBB:root"
},
"Action": "events:PutEvents",
"Resource": "arn:aws:events:ap-northeast-1:853835738220:event-bus/Cross-Account-Bus"
}]
}
動作確認
リソースベースのポリシーを設定後、再度アカウントBからイベントを送信すると、無事イベント送信できました!
最後に
簡単な記事でしたが、カスタムイベントバスとリソースベースのポリシーを触ることができました!