LoginSignup
1
0

More than 5 years have passed since last update.

Graylog で SSO Pluginと、oauth2_proxy を使ってGoogle OAuth2認証する

Posted at

Graylog で SSO Pluginと、oauth2_proxy を使ってGoogle OAuth2認証する

Graylog で SSO Pluginと、oauth2_proxy を使ってGoogle OAuth2認証を設定したのでそのメモ

実現したいこと

Graylogでいちいちユーザーを作らないでも、Google OAuth2認証だけで、閲覧・検索だけはできるようにしたい。

使ったもの

以下の組み合わせて実現できた

ポイント

oauth2_proxy

設定ファイル

  • 【最重要】pass_basic_authfalse にしないと駄目
    • Graylogの認証メカニズムでも authorization Headerを利用するので、falseにしないと、oauth2_proxyで上書きされてしまってちゃんと動かない
  • 死活/監視用のEndpointは、 skip_auth_regex にいれてやるべし
  • コマンドラインオプションと1:1対応していないので、 https://github.com/bitly/oauth2_proxy/blob/master/contrib/oauth2_proxy.cfg.example を見ながら試行錯誤する必要あり

設定ファイル例

client_id = "XXXXXXXXXXXXX"
client_secret = "YYYYYYYYYYYYYYYYYYY"
email_domains = ["test.com"]
provider = "google"
upstreams = ["http://localhost:9000"]
cookie_secret = "ZZZZZZZZZZ"
cookie_refresh = "1h"
skip_auth_regex = ["^/api/system/lbstatus", "^/api/plugins/org.graylog.plugins.metrics.prometheus/metrics"]
pass_basic_auth = false

※LB死活チェックと、Prometheus ExporterのEndpointはskipするようにしている

Graylog

SSO Plugin

  • Automatically create users: ON
  • Username Header: X-Forwarded-User
  • Email Header: X-Forwarded-Email
  • Default User Role: 次項で作成したRole

Role

SSO Pluginで、ユーザーの自動作成と、作成したユーザーのRoleが設定できるが、、、、
GraylogのRole機構だと、

  • Admin/Reader どちらかが必須
  • Adminは全権限。Readerはデータへのアクセス権一切ない(ログ一切みれない)
  • Readerと、自分で作ったRole(個別ストリーム/ダッシュボードへのアクセス権限を付ける)を組み合わせて使うことが必須
  • だけどSSO pluginは自動作成時に1つしかRole選べない。自分で作ったRole選ぶとReaderがつかないのでまともに使えないUserができる(試したけどNotFoundでまくる)

という問題がある。

これを解決するには、REST APIで、Reader権限と、必要なアクセス権限をあわせもつRoleを無理やり作って、それをSSO pluginで指定すればOK

例:全てのstreamsとdashboardがreadできる Developer Roleを作成する

-> % curl -v -XPOST -u user:pass  -H 'Content-Type: application/json'  'http://172.28.0.107/api/roles?pretty=true' -d '{     "name" : "Developer",     "description" : "Read all streams and dashboards",     "permissions" : [ "clusterconfigentry:read", "indexercluster:read", "messagecount:read", "journal:read", "messages:analyze", "inputs:read", "metrics:read", "savedsearches:edit", "fieldnames:read", "buffers:read", "system:read", "savedsearches:create", "jvmstats:read", "decorators:read", "throughput:read", "savedsearches:read", "messages:read" , "streams:read:*", "dashboards:read:*"],     "read_only" : false} '
  • streams, dashboardsは試したところ、 * を設定すれば、全てが対象になる :
    • 例 : "streams:read:*", "dashboards:read:*"

その他の設定など

oauth2_proxyのログ

アクセスログとかとっておきたいけど、、、、

  • アクセスログが標準出力
  • エラーログが標準エラー出力

に出力されるのでファイルに出力してやる

systemdなら、、、

[Unit]
Description=oauth2_proxy Service

[Service]
Type=simple
Restart=always
User=oa2proxy
ExecStart=/bin/bash -c 'exec /usr/local/oauth2_proxy/oauth2_proxy -config /etc/oauth2_proxy/oauth2_proxy.conf >> /var/log/oauth2_proxy/access.log 2>> /var/log/oauth2_proxy/error.log'
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
SendSIGKILL=no

[Install]
WantedBy=multi-user.target

※AmazonLinxu2だと、systemdが古すぎて StandardOutput/StandardError が使えないのでExecStartでリダイレクトしてやっている

ログのローテーションはlogrotateで

/var/log/oauth2_proxy/*log {
    create 0644 oa2proxy oa2proxy
    daily
    rotate 10
    missingok
    notifempty
    compress
    sharedscripts
    postrotate
        /usr/bin/systemctl reload oauth2_proxy.service 2> /dev/null || true
    endscript
}

※試したところUSR1だとログが切り替わらなかったので、HUPを送っている

管理用のアクセス経路

  • oauth2_proxyを通さないアクセス経路を用意しておくことで、adminログインの経路を確保しておくべし
  • この経路では、SSO Pluginに設定している X-Forwarded-User Headerが絶対にGraylogに渡らないように、Proxyで潰すこと(でないとログインし放題になっちゃう)

Nginxなら

proxy_hide_header   X-Forwarded-User;
proxy_hide_header   X-Forwarded-Email;
1
0
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
1
0