Jenkins OIDC、Gitea OIDC、Grafana SSO と Casdoor: セルフホスト型 DevOps スタックのためのワンログイン
一般的なセルフホスト型 DevOps スタックのすべてのツールは、OpenID Connect クライアントとして機能できます。Gitea と Argo CD は OIDC をネイティブにサポートし、Jenkins は oic-auth プラグインを介して、Grafana と Portainer は汎用 OAuth 2.0 を介して、MinIO、Harbor、GitLab はそれぞれの OIDC 設定を介して対応しています。これらすべてを 1 つの Casdoor インスタンスに向け、各ツールごとに個別の Casdoor アプリケーションを作成し、ユーザーを Casdoor グループに追加します。各ツールは groups クレームを読み取り、誰が管理者であるかを判断します。この記事では、各ツールのコールバック URL、設定キー、グループマッピングを一覧にし、その後、共通部分を解説します。
スタックの概要
以下のパスはすべて、ツール自身の公開 URL からの相対パスです。それらをそのツールの Casdoor アプリケーションの Redirect URLs に登録してください。
| App | Protocol | Callback URL | Group/role to admin mapping | Casdoor doc |
|---|---|---|---|---|
| Gitea | OIDC (OAuth2 auth source) | /user/oauth2/<source-name>/callback | Yes: admin group, restricted group, team map | Gitea |
| Jenkins | OIDC (oic-auth plugin) | /securityRealm/finishLogin, logout /OicLogout | Yes: groups claim plus Matrix-based security | Jenkins (OIDC) |
| Grafana | Generic OAuth 2.0 | /login/generic_oauth | Yes: role_attribute_path | Grafana |
| Argo CD | OIDC | /auth/callback, CLI http://localhost:8085/auth/callback | Yes: argocd-rbac-cm | Argo CD |
| MinIO | OIDC | Console /oauth_callback | Policies from one claim (claim_name) | MinIO |
| Portainer | OAuth 2.0 (Custom) | The Portainer base URL | Business Edition only | Portainer |
| Harbor | OIDC | /c/oidc/callback | Yes: OIDC Admin Group | none yet |
| GitLab | OIDC (OmniAuth) | /users/auth/openid_connect/callback | Premium and Ultimate: admin_groups | GitLab |
The discovery document every OIDC client needs is https://<casdoor-host>/.well-known/openid-configuration. If you have not connected an OIDC client to Casdoor before, Connect a standard OIDC client explains the endpoints.
Casdoor を一度だけ準備する
ツールに触れる前に、Casdoor で 3 つのことを設定します。
Groups. 組織ツリーに devops-admins や devops-users などのグループを作成し、ユーザーを追加します。Groups を参照してください。
Token group format. By default the groups claim names each group as <organization>/<group>. Most tools compare the claim with a plain string you type, so set Token group format on the OIDC/OAuth tab of each application to Name (group). The claim then carries devops-admins. The options are described under Group format.
Token format. Token format はデフォルトの JWT のままにしてください。この形式では、ID トークンに groups、roles、tag が含まれます。JWT-Empty と JWT-Standard ではこれら 3 つすべてがトークンから除外され、JWT-Custom は Token fields で選択した場合のみこれらを含みます。profile スコープが付与されている場合、/api/userinfo レスポンスは groups とロール名を返すため、userinfo を読み取るツールでも確認できます。
Roles も機能します。JWT 形式では roles クレームはロールオブジェクトの配列なので、roles[*].name で一致させます。/api/userinfo では単なる名前の配列です。User roles を参照してください。
Gitea
Site Administration で、プロバイダーを OpenID Connect としたタイプ OAuth2 の認証ソースを追加し、クライアント ID とシークレット、および Casdoor のディスカバリ URL を指定します。ソースに付けた名前はコールバック URL の一部になります。casdoor という名前のソースは https://gitea.example.com/user/oauth2/casdoor/callback を使用します。
グループマッピングの場合、Claim name providing group names に groups を入力し、Group Claim value for administrator users に devops-admins を入力します。Gitea にはさらに Group Claim value for restricted users と Map claimed groups to Organization teams もあります。CLI から同じソースを使用する場合:
gitea admin auth add-oauth \
--name casdoor \
--provider openidConnect \
--key <client-id> \
--secret <client-secret> \
--auto-discover-url https://door.example.com/.well-known/openid-configuration \
--group-claim-name groups \
--admin-group devops-admins
Jenkins
Jenkins 自体には OIDC サポートがありません。OpenId Connect Authentication プラグインをインストールし、セキュリティレルムとして選択し、well-known configuration を使用します。ログインコールバックは /securityRealm/finishLogin、ログアウトコールバックは /OicLogout なので、両方を Casdoor に追加します。JCasC では:
jenkins:
securityRealm:
oic:
serverConfiguration:
wellKnown:
wellKnownOpenIDConfigurationUrl: https://door.example.com/.well-known/openid-configuration
clientId: <client-id>
clientSecret: <client-secret>
userNameField: name
fullNameFieldName: displayName
emailFieldName: email
groupsFieldName: groups
logoutFromOpenidProvider: true
properties:
- "pkce"
プラグインはグループのみを Jenkins に渡します。権限は認可戦略によって決まります。Matrix ベースのセキュリティを使用する場合、テーブルの各行はユーザーまたはグループを表すため、devops-admins の行を追加し、Overall/Administer を付与します。プラグインをセキュリティレルムとして選択すると他のログイン方法が無効になるため、保存する前にプラグインの escapeHatch プロパティ(フォールバック用のユーザー名とシークレット)を設定してください。Casdoor には独自の Jenkins プラグインもあり、Jenkins plugin で説明されていますが、この記事では汎用 OIDC プラグインを使用している前提で進めます。
Grafana
Grafana は汎用 OAuth を使用します。コールバックは /login/generic_oauth です。Grafana のデフォルトの scopes は user:email なので、OIDC スコープを明示的に設定します:
[auth.generic_oauth]
enabled = true
name = Casdoor
client_id = <client-id>
client_secret = <client-secret>
scopes = openid profile email
auth_url = https://door.example.com/login/oauth/authorize
token_url = https://door.example.com/api/login/oauth/access_token
api_url = https://door.example.com/api/userinfo
use_pkce = true
groups_attribute_path = groups
role_attribute_path = contains(groups[*], 'devops-admins') && 'Admin' || contains(groups[*], 'devops-users') && 'Editor' || 'Viewer'
role_attribute_strict = true
Grafana evaluates role_attribute_path against the ID token first, then the userinfo response, then the access token. Valid results are None, Viewer, Editor, Admin and GrafanaAdmin; the last one needs allow_assign_grafana_admin = true. allowed_groups limits login to listed groups and requires groups_attribute_path. Team sync is a Grafana Enterprise and Grafana Cloud feature.
Argo CD
Argo CD は、同梱されている Dex を経由せず、Casdoor と直接通信します。ブラウザからのコールバック URL は /auth/callback です。argocd login --sso はデフォルトでポート 8085 にローカルサーバーを起動し、http://localhost:8085/auth/callback を使用するため、この URL も登録してください。
argocd-cm で url と oidc.config(name、issuer、clientID、clientSecret、requestedScopes を含む)を設定します。Argo CD のデフォルトの requestedScopes には groups スコープが含まれますが、Casdoor ではこれは不要です。なぜなら、JWT 形式の ID トークンは常に groups を含んでいるため、本ガイドでは ["openid", "profile", "email"] をリクエストしています。グループのマッピングは argocd-rbac-cm で行い、scopes のデフォルト値は [groups] です:
data:
policy.default: role:readonly
policy.csv: |
g, devops-admins, role:admin
argocd-secret にクライアントシークレットを設定するなど、完全な手順については Argo CD ガイドを参照してください。
MinIO
MinIO は単一のクレームからポリシーを読み取ります。これは claim_name(デフォルトは policy)で設定されます。MinIO はグループをマッピングしません。MinIO 公式の Casdoor クイックスタートと本ガイドでは、Casdoor の tag クレームを使用します。ユーザーの Tag に readwrite などの MinIO ポリシー名を入力し、以下のように設定します:
mc admin config set myminio identity_openid \
config_url="https://door.example.com/.well-known/openid-configuration" \
client_id=<client-id> client_secret=<client-secret> claim_name="tag"
role_policy は代替手段です。このプロバイダーを通じてサインインするすべてのユーザーに、リストされたポリシーが付与され、claim_name と併用することはできません。コンソールのコールバック URL は <console-url>/oauth_callback です。プロキシの使用時は MINIO_BROWSER_REDIRECT_URL を設定してください。古い redirect_uri キーは非推奨となりました。minio/minio GitHub リポジトリはアーカイブされており、README にはメンテナンスされていない旨が記載されているため、これらの設定に依存する前に、実行している MinIO のビルドを確認してください。
Portainer
Portainer はカスタム OAuth プロバイダーを使用します。Casdoor ホスト上の Authorization URL (/login/oauth/authorize)、Access token URL (/api/login/oauth/access_token)、および Resource URL (/api/userinfo) に入力し、Redirect URL には Portainer のベース URL を設定します。Logout URL フィールドもあります。Portainer CE では、Automatic team membership は Business Edition の機能としてマークされており、グループに管理者権限を割り当てる設定も Business Edition のみで利用可能です。CE では、自動プロビジョニングによって作成されたユーザーは標準ユーザーロールになり、管理者の手動昇格が必要になります。
Harbor と GitLab
Harbor の OIDC 設定ページの下部にリダイレクト URI が表示されます:<harbor-url>/c/oidc/callback。OIDC Provider Endpoint には Casdoor の URL、Group Claim Name には groups、OIDC Admin Group には devops-admins を設定します。Harbor は ID トークンからグループクレームを読み取るため、JWT 形式を提供する必要があります。データベース認証から OIDC 認証への切替は、ローカルユーザーが存在しない状態で行う必要があります。
GitLab の OIDC ドキュメントには Casdoor のセクションがあり、Casdoor は HTTPS で提供される必要があります。コールバック URL は /users/auth/openid_connect/callback です。グループベースのロール(groups_attribute、admin_groups、required_groups、external_groups)には GitLab Premium または Ultimate が必要です。
OIDC をサポートしていないツール
独自のログインを持たない内部ダッシュボードの場合は、APISIX ガイドにあるように Apache APISIX の openid-connect プラグイン(discovery、client_id、client_secret、redirect_uri、bearer_only)の背後に配置するか、Nginx SSO 認証に記載されているように nginx の背後に配置します。
ツールごとにアプリケーションを作成するか、共有するか
すべてのツールのコールバック URL をその Redirect URLs に含めた単一の Casdoor アプリケーションでも動作しますが、ツールごとに個別のアプリケーションを作成する方が運用しやすい場合があります:
- 各ツールが固有のクライアントシークレットを持つため、Jenkins のシークレットが漏洩しても Grafana は影響を受けません。
- Token group format、Token format、およびトークンの有効期限はアプリケーション単位で設定されるため、Argo CD 用に
Name (group)形式に変更しても、他のツールのクレームには影響しません。 - Casdoor は
post_logout_redirect_uriをそのアプリケーションの Redirect URLs に対して検証するため、各リストは短く具体的に保たれます。
ユーザーは一度だけサインインすれば済みます。初回ログイン後、Casdoor のセッションクッキーにより、次のツールへのリダイレクト時にパスワード入力を求められずに完了できます。
ログアウト
Casdoor のエンドセッションエンドポイントは /api/logout で、ディスカバリドキュメントでは end_session_endpoint としてリストされています。これは id_token_hint、post_logout_redirect_uri、client_id、state を受け入れ、アプリケーションの Redirect URLs にリストされた URL のみにリダイレクトします。Casdoor からサインアウトすると Casdoor のセッションとそのセッションのトークンは終了しますが、各ツールは独自のカスタマイズしたセッションクッキーを保持します。各ツールでログアウトを設定してください:
- Jenkins:
logoutFromOpenidProvider、/OicLogoutを登録済み。 - Grafana:
signout_redirect_url。 - Argo CD:
oidc.config内のlogoutURL、例:https://door.example.com/api/logout?id_token_hint={{token}}&post_logout_redirect_uri={{logoutRedirectURL}}。 - Harbor: OIDC Session Logout。
- Portainer: Logout URL。
エンドポイントの詳細については RP-initiated logout を参照してください。
参考資料
- Gitea: Authentication,
admin auth add-oauth - Jenkins: OpenId Connect Authentication plugin, configuration reference, Managing security
- Grafana: Configure generic OAuth2 authentication
- Argo CD: User management, RBAC,
argocd login - MinIO: Casdoor quickstart in the MinIO repository
- Portainer: OAuth authentication
- Harbor: Configure OIDC provider authentication
- GitLab: Use OpenID Connect as an authentication provider
- Apache APISIX: openid-connect plugin