UI ダッシュボードの認証と権限
これは何か?
どうやってUI認証を有効にするか?
-
設定ファイル gear.confを変更し、
gearpump-ui.gearpump.ui-security.authentication-enabled
のエントリを見つけ、値をtrueに変更します。gearpump-ui.gearpump.ui-security.authentication-enabled = true
UIダッシュボードを再起動し、UI認証を有効にします。ユーザ名とパスワードを入力するように促すでしょう。
Gearpump UIサーバはどれだけの数の認証メソッドをサポートするか?
現在のところ、以下をサポートします:
- ユーザ名-パスワードに基づいた認証と
- OAuth2に基づいた認証。
ユーザ-パスワードに基づいた認証は、gearpump-ui.gearpump.ui-security.authentication-enabled
の場合に有効になり、無効にすることはできません。
UI サーバ管理はauxiliary OAuth2 認証チャンネルを有効にするようにも選択できます。
ユーザ-パスワードに基づいた認証
ユーザ-パスワードに基づいた認証は、ユーザが明示的にユーザ名とパスワードを入力を要求するすべての認証のシナリオをカバーします。
Gearpumpは、設定ファイル内に格納されたユーザ名とパスワードのハッシュコードに対して検証を行う組み込みの ConfigFileBasedAuthenticatorを提供します。
しかし、開発者は独自のユーザ-パスワードに基づいた認証、LDAPのサポート、およびデータベースに基づいた認証...を提供するためにio.gearpump.security.Authenticator
を継承するために選択することができます。
ConfigFileBasedAuthenticator: 組み込みのユーザ-パスワード認証
ConfigFileBasedAuthenticatorは設定ファイル gear.confに全てのユーザ名とパスワードのハッシュコードを格納します。以下は ConfigFileBasedAuthenticatorを設定するステップです。
ユーザをどうやって追加または削除しますか?
デフォルトの認証プラグインのために、3つのカテゴリを持ちます: admins, users と guests。
- admins: クラスタのシャットダウン、マシーンの追加/削除 のような制限のないパーミッションを持ちます。
- users: アプリケーションなどをサブミットする制限ありのパーミッションを持ちます。
- guests: アプリケーションをサブミット/kill することはできませんが、アプリケーションの状態を見ることができます。
System administrator は設定ファイル conf/gear.conf
を更新することでユーザを追加または削除することができます。
administratorとしてユーザ jerry を追加したいとします。以下はそのステップです:
-
パスワードを取り上げ、このパスワードのダイジェストを生成します。パスワード
ilovegearpump
を使うといます。ダイジェストを生成するには:bin/gear io.gearpump.security.PasswordUtil -password ilovegearpump
このようなダイジェスト値を生成するでしょう:
CgGxGOxlU8ggNdOXejCeLxy+isrCv0TrS37HwA==
-
パス
gearpump-ui.gearpump.ui-security.config-file-based-authenticator.admins
にある設定ファイル conf/gear.conf を変更し、このリスト内にユーザjerry
を追加します:admins = { ## Default Admin. Username: admin, password: admin ## !!!セキュリティ上の理由でプロダクションクラスタについてはこの組み込みのアカウントを置き換えてください。!!! "admin" = "AeGxGOxlU8QENdOXejCeLxy+isrCv0TrS37HwA==" "jerry" = "CgGxGOxlU8ggNdOXejCeLxy+isrCv0TrS37HwA==" }
-
変更を有効にするために、
bin/services
を使ってUIダッシュボードを再起動します。 -
グループ "admins" はとても制限無しのパーミッションを持ち、そのパーミッションを制限したいかも知れません。この場合、
gearpump-ui.gearpump.ui-security.config-file-based-authenticator.users
あるいはgearpump-ui.gearpump.ui-security.config-file-based-authenticator.guests
を修正することができます。 -
さらに詳しい情報を見つけるには
conf/gear.conf
にある説明を見てください。
デフォルトのユーザとパスワードは何か?
ConfigFileBasedAuthenticator に関して、Gearpump配布物は二つのデフォルトのユーザと一緒に出荷されます:
- ユーザ名: admin, パスワード: admin
- ユーザ名: guest, パスワード: guest
ユーザadmin
は無制限のパーミッションを持ち、一方でguest
はアプリケーションのステータスのみを見ることができます。
セキュリティ上の理由で、プロダクションでのクラスタについてはデフォルトのユーザadmin
およびguest
は削除する必要があります。
これはsecureですか?
まず、自身がパスワードを知るユーザのみで、どのような方法でもいかなるパスワードも格納しないでしょう。ユーザ入力パスワードを検証するために一方向性ハッシュダイジェストを使用するでしょう。
LDAP, Database などのための独自のユーザ-パスワード認証の開発の仕方
開発者が彼/彼女の独自のユーザ-パスワードに基づいた認証を定義することを選択した場合、ユーザが設定オプションを修正する必要があります:
## "io.gearpump.security.CustomAuthenticator" と実際の認証クラスを置きかえます。
gearpump.ui-security.authenticator = "io.gearpump.security.CustomAuthenticator"
CustomAuthenticator が interface を継承するようにします : ```scala trait Authenticator {
def authenticate(user: String, password: String, ec: ExecutionContext): Future[AuthenticationResult] } ```
OAuth2に基づいた認証
OAuth2に基づいた認証は一般的にソーシャルネットワークアカウントと愛想が良いソーシャルログインを達成するために使われます。
Gearpump はユーザが新しい認証ソースをサポートするように拡張することができる一般的なOAuth2認証サポートを提供します。
基本的に、OAuth2に基づいた認証は以下のステップを含みます: 1. ユーザはGearpump UI webサイトへアクセスし、OAuth2サーバにログインするように選択します。 2. Gearpump UI webサイトはユーザをOAuth2 サーバドメイン認証のエンドポイントにリダイレクトします。3. エンドユーザはOAuth2サーバのドメインの中での認証を完了します。4. OAuth2 サーバはユーザをGearpump UI サーバにリダイレクトします。5. Gearpump UI サーバはトークンを検証し、クエリパラメータとフォームフィールドから証明書を抽出します。
専門用語
client Id および client secret のような単語については、ガイドRFC 6749を参照してください
UIサーバのためのwebプロキシを有効化
OAuth2 認証を有効にするには、幾つかのリクエストは直接Gearpump UIサーバの中で継承されるため、Gearpump UIサーバはOAuth2サーバへのネットワークアクセスを持つようにしなければなりません。つまり、ファイヤウォールの後ろにいろ場合は、UIサーバのためのプロキシプロパティを設定しなければなりません。
Windows上の場合
> set JAVA_OPTS=-Dhttp.proxyHost=xx.com -Dhttp.proxyPort=8088 -Dhttps.proxyHost=xx.com -Dhttps.proxyPort=8088
> bin\services
Linux上の場合
$ export JAVA_OPTS="-Dhttp.proxyHost=xx.com -Dhttp.proxyPort=8088 -Dhttps.proxyHost=xx.com -Dhttps.proxyPort=8088"
$ bin/services
Google Plus OAuth2 認証
Google Plus OAuth2 Authenticator は Google OAuth2 サービスとの認証を行います。証明書としてGoogleユーザプロフィールからメールアドレスを抽出します。
Google OAuth2 Authenticator を使うためには、いくつかのステップがあります:
- アプリケーション(ここではGearpump UI サーバ)をアプリケーションとしてGoogle 開発コンソールに登録します。
- gear.confに Google OAuth2 情報を設定します
- 当てはまる場合は、Gearpump UI サーバのためにネットワークプロキシを設定します。
ステップ1 : webサイトをGoogle上の OAuth2 アプリケーションとして登録する
- webサイトを表すアプリケーションをhttps://console.developers.google.comで生成する
- 生成したアプリケーションの "API Manager"の中で、API "Google+ API" を有効にする
- このアプリケーションのための OAuth client ID を生成する。"API Manager"の"Credential"タブの中で、"Create credentials"を選択し、OAuth client IDを選択します。callback URLを設定するためにウィザードに従い、client IDとclient Secretを生成します。
注意: Callback URL は任意ではありません。
ステップ2: gear.conf内の OAuth2 情報を設定
gearpump.ui-security.oauth2-authenticator-enabled
をtrueに設定することで、OAuth2認証を有効にする。- gear.confの
gearpump.ui-security.oauth2-authenticators.google
セクションを設定する。クラス名、client ID、client Secret および callback URLが適切に設定されるように注意してください。
注意: ここでCallback URL に設定されたものはステップ1のGoogleで設定したものと一致しなければなりません。
ステップ3: 当てはまる場合はネットワークプロキシを設定する。
OAuth2 認証を有効にするには、幾つかのリクエストは直接Gearpump UIサーバの中で継承されるため、Gearpump UIサーバはGoogleサービスへのネットワークアクセスを持つようにしなければなりません。つまり、ファイヤウォールの後ろにいろ場合は、UIサーバのためのプロキシプロパティを設定しなければなりません。
UIサーバのためのwebプロキシの設定方法のガイドについては、上の"UIサーバのためのwebプロキシを有効にする"セクションを参照してください。
ステップ4: UIサーバを再起動し、UIサーバ上のGoogleログインアイコンをクリックしてみてください。
CloudFoundry UAA server OAuth2 Authenticator
CloudFoundryUaaAuthenticatorは CloudFoundry UAA OAuth2 サービスを使って認証を行います。証明書としてGoogleユーザプロフィールからメールアドレスを抽出します。
UAA(ユーザアカウントおよび認証サービス)が何であるかについては、ガイドを見てください: UAA
Google OAuth2 Authenticator を使うためには、いくつかのステップがあります:
- ヘルパーツール
uaac
を使ってアプリケーション (ここでは Gearpump UI サーバ)をアプリケーションとしてUAAに登録する。 - gear.confに Google OAuth2 情報を設定します
- 当てはまる場合は、Gearpump UI サーバのためにネットワークプロキシを設定します。
ステップ1: uaac
を使ってアプリケーションをUAAに登録する
- uaacについてhttps://docs.cloudfoundry.org/adminguide/uaa-user-management.htmlでチュートリアルをチェックしてください
- bashシェルを開き、コマンド
uaac target
uaac target [your uaa server url]
によってUAAサーバを設定します -
以下の方法でユーザadminとしてログインする
uaac token client get admin -s MyAdminPassword
- UAA内で新しいアプリケーション(Client)を生成する
uaac client add [your_client_id] --scope "openid cloud_controller.read" --authorized_grant_types "authorization_code client_credentials refresh_token" --authorities "openid cloud_controller.read" --redirect_uri [your_redirect_url] --autoapprove true --secret [your_client_secret]
ステップ2: gear.conf内の OAuth2 情報を設定
gearpump.ui-security.oauth2-authenticator-enabled
をtrueに設定することで、OAuth2認証を有効にする。gearpump.ui-security.oauth2-authenticators.cloudfoundryuaa
の章に遷移する- gear.confの
gearpump.ui-security.oauth2-authenticators.cloudfoundryuaa
セクションを設定する。クラス名、client ID、client Secret および callback URLが適切に設定されるように注意してください。
注意: ここでの callback URLはステップ1での CloudFoundry UAAで設定したものと一致しなければなりません。
ステップ3: 当てはまる場合は、Gearpump UI サーバのためにネットワークプロキシを設定します
OAuth2 認証を有効にするには、幾つかのリクエストは直接Gearpump UIサーバの中で継承されるため、Gearpump UIサーバはGoogleサービスへのネットワークアクセスを持つようにしなければなりません。つまり、ファイヤウォールの後ろにいろ場合は、UIサーバのためのプロキシプロパティを設定しなければなりません。
UIサーバのためのwebプロキシの設定方法のガイドについては、上の"UIサーバのためのwebプロキシを有効にする"セクションを参照してください。
ステップ4: UIサーバを再起動し、UIサーバ上のCloudFoundryログインアイコンをクリックしてみてください。
ステップ5: 以下の設定をすることで、CloudFoundry UAAのための追加の認証を有効にすることもできます:
additional-authenticator-enabled = true
更なる情報については、gear.confの説明を見てください。
Facebook あるいは Twitterのような新しい認証サービスのサポートをするために OAuth2Authenticator を拡張する。
独自のOAuth2Authenticatorを定義するために Google OAuth2のコード例に従うことができます。 基本的に、ステップは以下のものを含みます:
-
OAuth2Authenticator 実装を定義する。
/** * * Uses OAuth2 social-login as the mechanism for authentication. * @see [[https://tools.ietf.org/html/rfc6749]] to find what is OAuth2, and how it works. * * Basically flow for OAuth2 Authentication: * 1. ユーザはGearpump UI webサイトにアクセスし、OAuth2サーバを使ってログインすることを選択します。 * 2. Gearpump UI webサイトはユーザをOAuth2 サーバドメイン認証のエンドポイントにリダイレクトします。 * 3. ユーザはOAuth2サーバのドメイン内での認証を完了します。 * 4. OAuth2 サーバはユーザを Gearpump UI sa-ba にリダイレクトします。 * 5. Gearpump UI サーバはトークンを検証し、クエリから証明書を抽出します * parameters and form fields. * * @note '''Thread-safety''' is a MUST requirement. 開発者はサブクラスがスレッドセーフであることを確実にする必要があります。 * Sub-class should have a parameterless constructor. * * @note OAuth2 Authenticator requires access of Internet. Please make sure HTTP proxy are * set properly if applied. * * @example Config proxy when UI server is started on Windows: * } * * @example Config proxy when UI server is started on Linux: * } * */ trait OAuth2Authenticator { /** * Inits authenticator with config which contains client ID, client secret, and etc.. * * Typically, the client key and client secret is provided by OAuth2 Authorization server when user * register an application there. * @see [[https://tools.ietf.org/html/rfc6749]] for definition of client, client Id, * and client secret. * * See [[https://developer.github.com/v3/oauth/]] for an actual example of how Github * use client key, and client secret. * * @note '''Thread-Safety''': Framework ensures this call is synchronized. * * @param config Client Id, client secret, callback URL and etc.. */ def init(config: Config): Unit /** * Returns the OAuth Authorization URL so for redirection to that address to do OAuth2 * authorization. * * @note '''Thread-Safety''': This can be called in a multi-thread environment. Developer * need to ensure thread safety. */ def getAuthorizationUrl: String /** * After authorization, OAuth2 server redirects user back with tokens. This verify the * tokens, retrieve the profiles, and return [[UserSession]] information. * * @note This is an Async call. * @note This call requires external internet access. * @note '''Thread-Safety''': This can be called in a multi-thread environment. Developer * need to ensure thread safety. * * @param parameters HTTP Query and Post parameters, which typically contains Authorization code. * @return UserSession if pass authentication. */ def authenticate(parameters: Map[String, String]): Future[UserSession] /** * Clean resource */ def close(): Unit }
-
gearpump.ui-security.oauth2-authenticators
の下の設定エントリを追加します。例えば:## name of this authenticator "socialnetworkx" { "class" = "io.gearpump.services.security.oauth2.impl.SocialNetworkXAuthenticator" ## Please make sure this URL matches the name "callback" = "http://127.0.0.1:8090/login/oauth2/socialnetworkx/callback" "clientId" = "gearpump_test2" "clientSecret" = "gearpump_test2" "defaultUserRole" = "guest" ## Make sure socialnetworkx.png exists under dashboard/icons icon = "/icons/socialnetworkx.png" }
設定のエントリはクラス
SocialNetworkXAuthenticator
によって使われるとみなすことができます。