ELK
概要
Kibana 独自の SSO オプション(OAuth、OIDC、SAML、LDAP)は Elastic Stack の有料サブスクリプションに含まれます。無料で Kibana を Casdoor により保護するには、以下のいずれかをその前に配置します:
| elk-auth-casdoor | casdoor-forward-auth | |
|---|---|---|
| What it is | A reverse proxy: browsers talk to it and it forwards to Kibana | A forward auth service that your existing reverse proxy (Nginx, Traefik, Caddy) asks about every request |
| You need | Nothing else | Nginx, Traefik or Caddy |
| Hosts | Kibana's host only | A host for the auth service (e.g. auth.example.com) next to Kibana's, sharing a cookie domain |
| Good for | Protecting a single Kibana with the fewest moving parts | Setups that already have a reverse proxy, or several services behind one sign-in |
両方ともセッションのないユーザーを Casdoor のログインページへリダイレクトし、アクセストークンを検証した後、サインインしたユーザーを X-Forwarded-User ヘッダーで Kibana に渡します。
ステップ 1: Casdoor アプリケーションの設定
- Casdoor でアプリケーションを作成または編集します。
- Redirect URLs にコールバックを追加します:
- elk-auth-casdoor:
https://kibana.example.com/casdoor-auth/callback - casdoor-forward-auth:
https://auth.example.com/callback
- elk-auth-casdoor:
- Client ID と Client secret を控えてください。
以下の例では、Kibana は https://kibana.example.com で提供され、127.0.0.1:5601 で待ち受けています。
オプション A: elk-auth-casdoor
ステップ 2: elk-auth-casdoor の設定
アプリケーションの証明書(Casdoor の Certs ページ)の公開鍵証明書を conf/token_jwt_key.pem として保存し、conf/config.json を作成します:
{
"listenAddr": ":8080",
"pluginEndpoint": "https://kibana.example.com",
"targetEndpoint": "http://127.0.0.1:5601",
"casdoorEndpoint": "https://door.casdoor.com",
"clientId": "<client ID>",
"clientSecret": "<client secret>",
"certificateFile": "conf/token_jwt_key.pem",
"organization": "<organization of the application>",
"application": "<application name>"
}
pluginEndpointはユーザーがブラウザに入力する公開 URL です。targetEndpointは elk-auth-casdoor が Kibana に到達する場所です。organizationのユーザーのみがサインインできます。- Elasticsearch セキュリティが有効になっており、Kibana が独自ログインを求める場合は、
upstreamUsernameとupstreamPasswordに Kibana ユーザーを設定します。elk-auth-casdoor は Casdoor 経由でサインインした全員に対して基本認証でこれを Kibana に送信します。
すべての設定については elk-auth-casdoor README を参照してください。
ステップ 3: elk-auth-casdoor の実行
docker run -d --name elk-auth-casdoor --network host \
-v "$PWD/conf:/app/conf" \
-e SESSION_SECRET=<random string of at least 32 characters> \
ghcr.io/casdoor/elk-auth-casdoor:latest
SESSION_SECRET はセッションクッキーに署名するために使用されます。再起動後も同じ値を保持してください。そうしないと全員がサインアウトされます。ポート 8080 の前で TLS を終端するか、elk-auth-casdoor をロードバランサーの後ろで実行して、ユーザーが pluginEndpoint に到達できるようにしてください。
https://kibana.example.com を開きます。Casdoor へリダイレクトされ、サインイン後に Kibana が表示されます。/casdoor-auth/logout で elk-auth-casdoor からサインアウトします。
オプション B: Nginx と casdoor-forward-auth
ステップ 2: casdoor-forward-auth の実行
docker run -d --name casdoor-forward-auth -p 9999:9999 \
-e CASDOOR_ENDPOINT=https://door.casdoor.com \
-e CLIENT_ID=<client ID> \
-e CLIENT_SECRET=<client secret> \
-e EXTERNAL_URL=https://auth.example.com \
-e COOKIE_DOMAIN=example.com \
-e COOKIE_SECRET=<random string of at least 32 characters> \
ghcr.io/casdoor/casdoor-forward-auth:latest
COOKIE_DOMAIN は auth.example.com と kibana.example.com の両方をカバーする必要があります。これにより、ログイン後に設定されたセッションクッキーが Kibana のホストに送信されます。すべての設定については Configuration を参照してください。
ステップ 3: Nginx の設定
Nginx の auth_request モジュールはすべてのリクエストで casdoor-forward-auth の /verify を呼び出し、401 でログインへリダイレクトします:
server {
listen 443 ssl;
server_name auth.example.com;
# ssl_certificate ...
location / {
proxy_pass http://127.0.0.1:9999;
proxy_set_header Host $host;
}
}
server {
listen 443 ssl;
server_name kibana.example.com;
# ssl_certificate ...
location = /_casdoor_verify {
internal;
proxy_pass http://127.0.0.1:9999/verify;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
}
location @casdoor_login {
return 302 https://auth.example.com/login?rd=$scheme://$http_host$request_uri;
}
location / {
auth_request /_casdoor_verify;
error_page 401 = @casdoor_login;
auth_request_set $casdoor_user $upstream_http_x_forwarded_user;
proxy_set_header X-Forwarded-User $casdoor_user;
proxy_pass http://127.0.0.1:5601;
proxy_set_header Host $host;
}
}
Nginx をリロードし、https://kibana.example.com を開きます。Casdoor へリダイレクトされ、サインイン後に Kibana が表示されます。
Traefik を使用する場合は、Traefik ガイドに従い、Kibana を保護対象サービスとして使用してください。Caddy を使用する場合は、casdoor-forward-auth README を参照してください。
Kibana への直接アクセスをブロック
どちらのオプションでも、Kibana はプロキシ経由でのみ到達可能にする必要があります。ローカルホストにバインドするか(kibana.yml で server.host: "127.0.0.1")、ファイアウォールでポート 5601 をブロックしてください。そうしないと、誰でも Kibana に直接接続することでログインを回避できます。