使用Graylog的SSO插件和oauth2_proxy来进行Google OAuth2认证

使用Graylog的SSO插件和oauth2_proxy来进行Google OAuth2认证。

由于在Graylog中使用SSO插件和oauth2_proxy设置了Google OAuth2验证,下面是相关备忘录。

我想要实现的目标

我想要在Graylog中只使用Google OAuth2认证,而不需要每次都创建用户,仅允许浏览和搜索。

使用的物品

能够通过以下组合实现

    • GraylogのSSO plugin : https://github.com/Graylog2/graylog-plugin-auth-sso

oauth2_proxy : https://github.com/bitly/oauth2_proxy

要求以中文进行本地化,只需要提供一个选项:「积分」。

OAuth2代理

設置檔案

    • 【最重要】pass_basic_auth を false にしないと駄目

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

将以下内容以中文以本地方式改述,只提供一种选项:
为了跳过※进行健康检查并跳过Prometheus Exporter的Endpoint。

灰日志

单点登录插件

    • Automatically create users: ON

 

    • Username Header: X-Forwarded-User

Email Header: X-Forwarded-Email

Default User Role: 次項で作成したRole

角色

通过SSO插件,可以实现用户的自动创建,并且可以设置所创建用户的角色。不过,使用Graylog的角色机制,则需要……

    • Admin/Reader どちらかが必須

 

    • Adminは全権限。Readerはデータへのアクセス権一切ない(ログ一切みれない)

 

    • Readerと、自分で作ったRole(個別ストリーム/ダッシュボードへのアクセス権限を付ける)を組み合わせて使うことが必須

 

    だけどSSO pluginは自動作成時に1つしかRole選べない。自分で作ったRole選ぶとReaderがつかないのでまともに使えないUserができる(試したけどNotFoundでまくる)

有一个问题存在。

要解决这个问题,我们可以通过REST API创建一个具有阅读权限和所需访问权限的角色,然后在SSO插件中指定该角色即可。

为了创建可以读取所有流和仪表板的开发者角色。

-> % 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信号。

管理的访问途径 de

    • oauth2_proxyを通さないアクセス経路を用意しておくことで、adminログインの経路を確保しておくべし

 

    この経路では、SSO Pluginに設定している X-Forwarded-User Headerが絶対にGraylogに渡らないように、Proxyで潰すこと(でないとログインし放題になっちゃう)

如果选择Nginx的话

proxy_hide_header   X-Forwarded-User;
proxy_hide_header   X-Forwarded-Email;
bannerAds