OCI_マネコンにログインした時にメール通知するようにしてみる
Categories:
OCIコンソールにログインした時にメール通知するようにしてみる
勉強
- 監査ログはデフォルトで作成される下記のロググループに吐かれている
Observability & Management > Log Groups > _Audit - 監査ログはRegion毎に吐かれる(イベントが起きたRegionでloggingされるらしい) ただし、OCIコンソール上では一元管理できるようになっている。検索リージョンをallにする。
- Compartmentはrootに配置され全Compartのログが含まれる単一のLog Groupになる。
- 左のCompartment指定は特に影響ない気がする。select regions to searchで指定するCompartmentはフィルターとして機能。
- 権限のあるcompartmentのログは見えるっていう形だと思う。
ログインイベントはdata.eventName='InteractiveLogin’
っぽい
ログイン監査がAuditログに載るようになったのは最近らしい。やったね。
https://docs.oracle.com/en-us/iaas/Content/Identity/api-getstarted/usingauditeventapis.htm
[!note]
Identity domains AuditEvents and certain reports templates in the Reports APIs will stop returning new data after December 15, 2024. Instead, you can use the OCI Audit service to get this data. To view service change announcements for IAM, see Service Change Announcements for IAM.
Notifications作成
※OCI コンソールは全リージョン検索に対応しているがコネクターは対応してないらしくログが出たRegionでConnectors Hub及び連携先のNotificationsを作らなきゃいけないっぽい(2025/06/01時点)
https://docs.oracle.com/en-us/iaas/Content/Logging/Concepts/multiregion_search.htm
→とりあえずHome RegionのAshburn、OracleIdentityCloudServiceのリージョンのPhoenix、よく使うTokyoの3つを作る
→試したところDefault ドメイン指定でログインすると Ashburn、OracleIdentityCloudService指定だとPhoenixに飛ぶっポイ。だからこの2つだけ作ればいいぽかった。
というかDefaultドメインはログインできないので不要なのかと思いきや、なんかログインを試みている怪しい形跡があることがメール飛ばすことによって分かったので残しておく。
以下リージョン毎に作ってく
Topic作成(Topic:Notificationsサービスの窓口的存在、Connectors HubのTargetに指定する)
Developer Services > Notifications{Application Integrationカテゴリ} > Topics > Create Topic- Region: Ashburn
- Name: Topic_audit_logging_Ashburn
- Compartmment: root
- Region: Phoenix
- Name: Topic_audit_logging_Phoenix
- Compartmment: root
- Region: Tokyo
- Name: Topic_audit_logging_Tokyo
- Compartmment: root
- Region: Ashburn
Subscirption作成(これが通知メソッド、今回はEmail。Topicに紐づけて作成する)
※作成すると設定したメールアドレスに確認メールが飛ぶのでメール記載のリンクをクリックして確定させる
Developer Services > Notifications{Application Integrationカテゴリ} > Subscriptions > Create Subscription- Region: Ashburn
- Topic: Topic_audit_logging_Ashburn
- Protocol: Email
- Email: xxxxxxxxxxxxxxxxxxxxxxxxxxx
- Compartmment: root
- Region: Phoenix
- Topic: Topic_audit_logging_Phoenix
- Protocol: Email
- Email: xxxxxxxxxxxxxxxxxxxxxxxxxxx
- Compartmment: root
- Region: Tokyo
- Topic: Topic_audit_logging_Tokyo
- Protocol: Email
- Email: xxxxxxxxxxxxxxxxxxxxxxxxxxx
- Compartmment: root
- Region: Ashburn
Connectors Hub作成
logging servicesから別サービス(今回はNotifications)にログを送る設定
Observability & Management > Logging > Connectors > Create Connector
- Region: Ashburn
- Connector name: Connector_audit_Logging_Ashburn
- Compartmment: root
- Source
- Logging
- Compartment: root
- Loggroup: _Audit
- include _Audit in subcompartmentsにチェック
- Log filter task
- Filter type: Event type
- Service name: Identity SignOn
- Event type: interactive Login
- Target
- Notifications
- Topic: Topic_audit_logging_Ashburn
Send raw messages→Send formatted messages ※そのままメールに出すならformatted、functionとかに食わせるならrawって感じ。
- Enable logs(Connectors Hubのログ出力をlogging Servicesに出す)
- Compartment: root
- Loggroup: Connector_loggroup_Ashburn
- Log name: Connector_log_Ashburn
- Region: Phoenix
- Connector name: Connector_audit_Logging_Phoenix
- Compartmment: root
- Source
- Logging
- Compartment: root
- Loggroup: _Audit
- include _Audit in subcompartmentsにチェック
- Log filter task
- Filter type: Event type
- Service name: Identity SignOn
- Event type: interactive Login
- Target
- Notifications
- Topic: Topic_audit_logging_Phoenix
Send raw messages→Send formatted messages
- Enable logs(Connectors Hubのログ出力をlogging Servicesに出す)
- Compartment: root
- Loggroup: Connector_loggroup_Phoenix
- Log name: Connector_log_Phoenix
- Region: Tokyo
- Connector name: Connector_audit_Logging_Tokyo
- Compartmment: root
- Source
- Logging
- Compartment: root
- Loggroup: _Audit
- include _Audit in subcompartmentsにチェック
- Log filter task
- Filter type: Event type
- Service name: Identity SignOn
- Event type: interactive Login
- Target
- Notifications
- Topic: Topic_audit_loggings_Tokyo
Send raw messages→Send formatted messages
- Enable logs(Connectors Hubのログ出力をlogging Servicesに出す)
- Compartment: root
- Loggroup: Connector_loggroup_Tokyo
- Log name: Connector_log_Tokyo
Policy created: ConnectorPolicy_notifications_2025-06-01T08.40.24.688Z ※Createボタン押すと名前デフォルトで作成される
メール飛ぶようになったけど、JSONフォーマットそのまま飛ぶのでFunctionかませて整形したいな
→最初rawで出してたがSend formatted messagesにしたら多少マシになった。