はじめに
IBM Security Verifyで管理者がユーザーの作成・変更・削除・パスワードリセットを行った際に、Slackに通知するという設定を行ってみました。
少し前にリリースされた通知Webhook機能を利用して設定を行っています。
機能のマニュアルについては下部の参考情報を参照ください。
1.通知Webhook設定概要
マニュアルだけだと理解が難しかったため、設定内容を整理してみました。
IBM Security Verifyの通知Webhook設定には、大きく3つの設定があります。
それぞれの設定について簡単に紹介します。
項目 | 管理画面のGUI上の表記 | 説明 | 設定方法 | 対応するAPIのBodyパラメータ |
---|---|---|---|---|
通知先の設定 | 接続の詳細 | 呼び出し先URL(SlackのIncomming WebhookのURL)を設定する。 通知先によっては認証方法や認証ヘッダーの情報も設することができる。 |
GUI/APIいずれでも設定可能 | urls/name/type/purposeなど |
通知イベントの設定 | イベント・サブスクリプション | IBM Security Verifyのどのイベントを通知するか設定できる。 事前定義のイベントや、カスタムで設定できる。 今回は、管理イベントを対象として設定する。 |
GUI/APIいずれでも設定可能 | notification-interests |
イベントデータ変換設定 | (GUI上は表記無し) | IBM Security Verifyのイベントペイロードを、Slackのmessage payloadのフォーマットに変換する。 | GUIでは設定できない。 APIで設定が必要 |
transform-outgoing |
2.SlackのIncomming Webhook設定について
①Slackにログインします。
https://slack.com/intl/ja-jp/
②Security Verifyというワークスペースと、webhookというchannelを用意します。
③Incomming webhookの設定を行います。下記URLにアクセスします。
https://api.slack.com/
⑥AppNameとワークスペース名を設定して、「Create App」をクリックします。
⑨表示されたWebhookのURLをコピーします。
https://hooks.slack.com/services/xxxx/xxxx/xxxx
⑩Slackに通知できるかテストします。
curl -X POST -H "Content-type: application/json" --data "{\"text\":\"Hello, World!\"}" https://hooks.slack.com/services/xxxx/xxxx/xxxx
3.IBM Security Verifyの通知Webhook設定について
Slack側の準備ができたので、IBM Security Verify側の設定を行います。
POST /config/v1.0/webhooks/で、通知Webhookの設定を登録します。
JSONのdataは以下の通りです。
{
"name": "user_management_webhook",
"type": "notification",
"transform": {
"outgoing": "statements:\r\n- context: \"isEventType1 := (body.data.resource == 'user')&&(body.data.action == 'created')\"\r\n- context: \"isEventType2 := (body.data.resource == 'user')&&(body.data.action == 'modified')\"\r\n- context: \"isEventType3 := (body.data.resource == 'user')&&(body.data.action == 'deleted')\"\r\n- context: \"isEventType4 := (body.data.resource == 'user')&&(body.data.action == 'reset password')\"\r\n- if:\r\n match: context.isEventType1 \r\n block:\r\n - context: \"d := body['data']\"\r\n - return: \"{'body': {'text': '<!channel> :new: ユーザーが作成されました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }\"\r\n- if:\r\n match: context.isEventType2 \r\n block:\r\n - context: \"d := body['data']\"\r\n - return: \"{'body': {'text': '<!channel> :sound: ユーザーが変更されました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }\"\r\n- if:\r\n match: context.isEventType3 \r\n block:\r\n - context: \"d := body['data']\"\r\n - return: \"{'body': {'text': '<!channel> :warning: ユーザーが削除されました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }\"\r\n- if:\r\n match: context.isEventType4 \r\n block:\r\n - context: \"d := body['data']\"\r\n - return: \"{'body': {'text': '<!channel> :unlock: ユーザーのパスワードがリセットされました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }\"\r\n- return: \"{'body': {'text':'other'}}\""
},
"urls": [
"https://hooks.slack.com/services/xxxx/xxxx/xxxx"
],
"purpose": [
"notifications"
],
"notification": {
"interests": [
{
"name": "management events",
"description": "",
"clauses": [
{
"operation": "include",
"key": "data.resource",
"value": "user"
}
]
}
],
"enabled": true
}
}
データ変換にあたる、"transform"-"outgoing"は、Common Expression Language (CEL) 形式で記載します。記載方法については、API を使用した Webhook の管理 - 変換や、複数行ルール実行プログラムを参照ください。
以下は改行など省いて見やすくしたデータ変換ルールになります。
statements:
- context: "isEventType1 := (body.data.resource == 'user')&&(body.data.action == 'created')"
- context: "isEventType2 := (body.data.resource == 'user')&&(body.data.action == 'modified')"
- context: "isEventType3 := (body.data.resource == 'user')&&(body.data.action == 'deleted')"
- context: "isEventType4 := (body.data.resource == 'user')&&(body.data.action == 'reset password')"
- if:
match: context.isEventType1
block:
- context: "d := body['data']"
- return: "{'body': {'text': '<!channel> :new: ユーザーが作成されました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }"
- if:
match: context.isEventType2
block:
- context: "d := body['data']"
- return: "{'body': {'text': '<!channel> :sound: ユーザーが変更されました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }"
- if:
match: context.isEventType3
block:
- context: "d := body['data']"
- return: "{'body': {'text': '<!channel> :warning: ユーザーが削除されました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }"
- if:
match: context.isEventType4
block:
- context: "d := body['data']"
- return: "{'body': {'text': '<!channel> :unlock: ユーザーのパスワードがリセットされました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }"
- return: "{'body': {'text':'other'}}"h
絵文字については、Emoji Cheat Sheetを参考にしました。
4.通知Webhookの動作確認
IBM Security Verifyの管理画面で、ユーザーの作成・変更・削除、パスワードリセット操作を行い、Slackに通知されることを確認します。
5.Webhook機能の制約事項について
マニュアルには、Webhook の制限が記載されています。
すべてのイベントを取得するような使い方の場合は、イベントAPI( Get all events for a tenant. )のほうが適して言います。
参考情報
IBM Security Verifyの通知Webhook機能
- ユーザー・インターフェースを使用した Webhook の管理 - 通知 Webhook の作成
- API を使用した Webhook の管理 - 通知 Webhook
- Create a Webhook (API)
- Security Learning Academy:Webhooks in Verify SaaS and the new use cases they support
- Webhook の制限
Slackのincomming Webhook機能