LoginSignup
7
8

More than 5 years have passed since last update.

ボット利用者の権限管理を行う hubot-acl の使い方

Last updated at Posted at 2015-03-21

hubot 経由で jenkins のジョブを実行したり、github の pull リクエストをマージしたりするの、便利でおもしろけど、ボットに話しかけられる人なら誰でも実行できてしまうのでちょっと怖い感じがした。

ボットに話しかけられる人の権限管理を行えるようになっていればいいなーと思い、tily/hubot-acl という Hubot スクリプトを作ってみた。

使い方

external-scripts で hubot-acl をロードすると robot が acl というイベントを発行するようになるので、自分のスクリプトの中でこれを捕捉して設定を行う。

module.exports = (robot)->
  robot.on 'acl', (order, allow, deny)->
    # ここに ACL 設定を記述する。

ACL 設定は apache の httpd.conf っぽいスタイル で記述できるようにしてみた。 (他に参考にできるようなインタフェースを思いつかなかったので…)

ホワイトリスト

robot.on 'acl', (order, allow, deny)->
  order deny, allow
  deny text: /.*/
  allow id: [1], text: /.*/
  allow id: [2], text: /^jenkins/
  allow id: [3], text: /^jenkins (list|last|describe)/
  • デフォルトでは全員がすべてのコマンドを禁止されている
  • id=1 のユーザーはすべてのコマンドを許可されている
  • id=2 のユーザーは jenkins プラグインのコマンドのみ許可されている
  • id=3 のユーザーは jenkins プラグインの閲覧系コマンドのみ許可されている

ブラックリスト

robot.on 'acl', (order, allow, deny)->
  order allow, deny
  allow text: /.*/
  deny name: ['bay4k', 'manny'], text: /^jenkins/
  deny name: ['sticky'], text: /^jenkins (b|build)/
  • デフォルトでは全員がすべてのコマンドを許可されている
  • bay4k, manny は jenkins プラグインのコマンドを禁止されている
  • sticky は jenkins プラグインのビルド系コマンドを禁止されている

hubot-auth との連携

hubot-auth (CoffeeScript - Hubot の標準的な権限管理 (hubot-auth) - Qiita) で指定された role での権限設定も可能 (v0.0.2 から)。

robot.on 'acl', (order, allow, deny)->
  order deny, allow
  deny text: /.*/
  allow role: ['admin'], text: /.*/
  allow role: ['jenkins'], text: /^jenkins/
  allow role: ['jenkins-readonly'], text: /^jenkins (list|last|describe)/

実行例

権限がないとこんな感じでリプライが返ります。

Hubot> Hubot jenkins build hoge
bes: Error: you are not allowed to execute that command

仕組みとか TODO とか

Robot#respond は内部的に Robot#listeners にコールバックを push するんだけど、ACL の判定はボットが reply に反応するときに一番最初に呼ばれるようにしたいので、Robot#listeners へ直接 unshift して必ず一番最初に呼ばれるようにしている。(JavaScript - Hubotの応答に権限追加 - Qiita のように #receive をオーバーライドしたほうが確実かな…。)

あと、それなりに重要な要件だから Hubot のテストの書き方をよく分かっていないんだけどテストを書きたい。

7
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
8