OpenShift v3.11の認証(web / oc login
)に、GitLab CEを使うための認証プロバイダの設定。
環境は以下の内容で構築したOKD3.11で確認
v4はこちら
ドキュメントはこちら 第13章 認証およびユーザーエージェントの設定 OpenShift Container Platform 3.11 / 13.3.11. GitLab
前提
GitLab CEについては、OCP v4編と同じ。
構築については下記の記事を参照。
zaki-hmkc.hatenablog.com
決めごと
認証プロバイダのアイデンティティ名についても、OCP v4編と同じ
この記事でもgitlabauth
としている。
GitLab CEのアプリケーション設定
アプリケーションIDとシークレット作成のための画面は、OCP v4編と同じ(そもそもGitLab側の話だし)
ただし入力項目のRedirect URIはv3とv4で構成が異なるのでrouteのドメインではなくmasterのホスト名:8443となる。
項目 | 内容 |
---|---|
Name | OCP v4 auth (など、見てわかる文言で) |
Redirect URI | 下記参照 |
Scopes | openid にチェック(他は不要) |
Redirect URIは、oc project
などで得られるmasterのURLをベースに、以下を入力する。(v4と異なり認証用のURLが無いことに注意)
末尾のgitlabauth
が最初に決めた認証プロバイダのアイデンティティ名。
https://<master-fqdn>:8443/oauth2callback/gitlabauth
作成されたApplication ID
とSecret
をOpenShfit側で使用する。
OpenShiftの設定
認証局のcrtファイルをmasterノードに配置
全masterノード上で、masterノード設定ファイルと同じパスである/etc/origin/master
に配置する。
[root@okd-master master]# file /etc/origin/master/gitlab-ce.example.org.crt /etc/origin/master/gitlab-ce.example.org.crt: PEM certificate
※ 例えば/usr/local/etc/gitlab-cert/gitlab-ce.example.org.crt
に置いてフルパスで指定したり、symlinkにした場合は動かなかった。実ファイルが必要っぽい。
masterノードの設定変更
全masterノードの/etc/origin/master/master-config.yaml
に設定を追加する。
クラスタデプロイ時にHTPasswdを使うように設定していれば、初期状態は以下のような設定になっているはず。
oauthConfig: assetPublicURL: https://okd-master.esxi.jp-z.jp:8443/console/ grantConfig: method: auto identityProviders: - challenge: true login: true mappingMethod: claim name: htpasswd_auth provider: apiVersion: v1 file: /etc/origin/master/htpasswd kind: HTPasswdPasswordIdentityProvider
これにGitLabの設定を追加する。
- name: gitlabauth challenge: true login: true mappingMethod: claim provider: apiVersion: v1 kind: GitLabIdentityProvider legacy: false url: https://gitlab-ce.example.org:8443 # GitLab CEのURL clientID: ................................... # GitLab CEのApplication ID clientSecret: ................................... # GitLab CEのSecret ca: gitlab-ce.example.org.crt # 証明書ファイル名
全体(oauthConfig部分抜粋)でこんな感じ
oauthConfig: assetPublicURL: https://okd-master.esxi.jp-z.jp:8443/console/ grantConfig: method: auto identityProviders: - challenge: true login: true mappingMethod: claim name: htpasswd_auth provider: apiVersion: v1 file: /etc/origin/master/htpasswd kind: HTPasswdPasswordIdentityProvider - name: gitlabauth challenge: true login: true mappingMethod: claim provider: apiVersion: v1 kind: GitLabIdentityProvider legacy: false url: https://gitlab-ce.example.org:8443 # GitLab CEのURL clientID: ................................... # GitLab CEのApplication ID clientSecret: ................................... # GitLab CEのSecret ca: gitlab-ce.example.org.crt # 証明書ファイル名 masterCA: ca-bundle.crt masterPublicURL: https://okd-master.esxi.jp-z.jp:8443 masterURL: https://okd-master.esxi.jp-z.jp:8443 : :
編集が終わったら全masterノードでrestartする
[root@okd-master master]# master-restart api 2 [root@okd-master master]# master-restart controllers 2 [root@okd-master master]#
出力が2
で無い場合は失敗してるらしいので、設定を見直す。
それ以外にも設定に失敗するとAPIサーバが起動せずoc
コマンドが使えなくなるので、その場合は設定を見直してorigin-node(OKD)やatomic-openshift(OpenShift)サービスをrestartする(うまくいかなければOSをreboot)。
認証
これ以降はOCP v4と同じ
web認証
webコンソールにアクセスすると、GitLab CEの認証用のgitlabauth
というボタンが表示されているはず。
gitlabauth
押下すればGitLab CEの認証画面に遷移するので、ログインするとアプリケーション連携の確認画面になるのでAuthorizeする。
webコンソールにログイン
ログインするとこの通りuserとidentitiesが作成される。
[zaki@okd-master ~]$ oc get user NAME UID FULL NAME IDENTITIES zaki ********-5140-11ea-9f59-************ zaki gitlabauth:2 [zaki@okd-master ~]$ oc get identities NAME IDP NAME IDP USER NAME USER NAME USER UID gitlabauth:2 gitlabauth 2 zaki ********-5140-11ea-9f59-************
CLI
[zaki@okd-master ~]$ oc login -u zaki Authentication required for https://okd-master.esxi.jp-z.jp:8443 (openshift) Username: zaki Password: Login successful. You don't have any projects. You can try to create a new project, by running oc new-project <projectname> [zaki@okd-master ~]$
普通にログインすればOK
(OCP v4と違ってx509エラーにならなかった)
アプリケーションのソースコード等をパブリックなサービス(GitHubとか)でなく、ローカルのGitリポジトリで管理しててかつGitLab CEを使っていて、さらにデプロイ環境などにOpenShiftを使っていれば、組み合わせれば便利に使えるはず。