ポータルアプリにリダイレクトポリシーを追加する
このトピックでは、リクエストをバックエンドの保護されたWebリソースにリダイレクトするアクセスポリシーの作成方法について説明します。
作成が必要な第2、第3、その他のバックエンドリダイレクトごとに1つのポリシーを作成します。
ポリシーを作成するには、Access Gateway管理者UIコンソールのテキストフィールドに設定を入力します。
ポリシーは、次のコンポーネントから構成されます。
-
ポリシーコンテナ。
/2ndのようなURIを割り当てます。 - カスタム構成コード。以下のセクションが含まれます。
policy_typeなど、ポリシーのオーバーライド設定- セッション変数
- ポリシーの属性を表すSAMLアサーションからのキー
- 必須のボイラープレートコード
- 書き換えられたインバウンドリクエスト
- 書き換えられたアウトバウンドリクエスト
- 書き換えられた302リダイレクト
- ヘッダーフィールド
リダイレクトポリシーを追加する
- ポリシー(policies)(Policies)タブを選択します。
- ポリシーリストのヘッダーにある追加(Add)(「+」アイコン)をクリックして、保護対象(Protected)を選択します。
- ポリシータイプをカスタム(Custom)に変更します。
- 詳細設定(Advanced)を展開します。
- セクション内のコードをカスタム構成(Custom Configuration)テキストフィールドに入力します。この手順の説明どおりにセクションを順序付けします。ポリシー構成全体の例については、コードブロックの完成例を参照してください。
- ポリシータイプを構成します。ポリシータイプのリストについては、「ポリシータイプ」を参照してください。
set $policy_type "PROTECTED" set $policy_*ステートメントの後にセッション変数を追加します。#Session variables set $UserName ''; set $oag_username ''; set $RemoteIP ''; set $RelayDomain ''; set $SESSIONID '';- 対応するインデックス付き変数のセットを属性ごとに指定します。これは、SAMLアサーションからのキーです。アプリの属性とインデックス付き変数には、1対1の対応が必要です。次の例には3つの属性があります。したがって、3つのsetステートメントと、追加のカウントsetステートメントを作成します。フィールド名は、名前(Name)列に指定された名前と一致する必要があります。また、$_argc変数は、ステートメント内の属性の総数(この例では3)と一致する必要があります。
# Keys from the SAML Assertion # authSession looks in the session for these keys # and populate the indexed variables set $_1 'oagusername'; set $_2 'firstname'; set $_3 'lastname'; set $_argc 3;次の図は、ポリシー構成内のステートメントとAccess Gateway管理者UIコンソールに表示される列名の関係を示しています。
- 例に示されるようなボイラープレートステートメントを入力します。変数とURLは独自の値に置き換えてください。
# process request policies access_by_lua_file conf/authSession.lua; # resolver -required if using domain and not IP resolver 127.0.0.1 valid=30s ; set $backend2 https://2ndbackend.myportal.com/ ; proxy_pass $backend2 ; - インバウンドの相対および絶対リクエストを書き換えます。アプリのパスをAccess GatewayアプリのURIに置き換えます。このURIが追加のバックエンドプロキシサーバーに渡されることになります。この例では
/2ndをURIとして使用します。# rewrite incoming requests to remove the /2nd # for relative links: subs_filter href="/ href="/2nd/ gir; # for absolute links: subs_filter 'https://2ndbackend.myportal.com/' 'https://$http_host/2nd/' ; - アウトバウンドの相対および絶対リクエストを書き換えます。
# Rewrite outbound requests to add back in /2nd # for absolute links subs_filter https://2ndbackend.myportal.com/ https://$http_host/2nd/ gir; # for relative links subs_filter href="/ href="/2nd/ gi; - 管理されているディレクティブ、アプリ用のヘッダー、ホスト名を構成します。元の属性値のサブセットである可能性があるすべての必須ヘッダーをリクエストに追加します。
# common managed directives include /etc/nginx/conf/icsgw_location_common.conf; # Include headers for application proxy_set_header oag_username $_1; proxy_set_header firstname $_2; proxy_set_header lastname $_3; # set to hostname that the protected upstream app needs proxy_set_header host $host; - 未検証(Not validated)をクリックしてコードブロックを検証します。コードが有効であれば、未検証(Not validated)は有効(Valid)に変わります。
- エラーがあれば訂正してからOkay(OK)をクリックします。
- 完了(Done)をクリックします。
コードブロックの完成例
次の例は、リクエストをすべてwww.myportal.com/2ndから2ndbackend.myportal.comにリダイレクトするための完成したコードブロックを示しています。
set $policy_type "PROTECTED";
# The values from auth Session
set $UserName '';
set $oag_username '';
set $RemoteIP '';
set $RelayDomain '';
set $SESSIONID '';
# Keys from the SAML Assertion
# authSession looks in the session for these keys
# and populate the indexed variables
set $_1 'oagusername';
set $_2 'firstname';
set $_3 'lastname';
set $_argc 3;
# process request policies
access_by_lua_file conf/authSession.lua;
# resolver -required if using a domain and not an IP address
resolver 127.0.0.1 valid=30s ;
set $<set_variable_name> https://2ndbackend.myportal.com/ ;
proxy_pass $<set_variable_name> ;
# rewrite incoming requests to remove the /2nd
# for relative links:
subs_filter href="/ href="/2nd/ gir;
# for absolute links:
subs_filter 'https://2ndbackend.myportal.com/' 'https://$http_host/2nd/' ;
# Rewrite outbound requests to add back in /2nd
# for absolute links
subs_filter https://2ndbackend.myportal.com/ https://$http_host/2nd/ gir;
# for relative links
subs_filter href="/ href="/2nd/ gi;
# common managed directives
include /etc/nginx/conf/icsgw_location_common.conf;
# Include headers for application
proxy_set_header oagusername $_1;
proxy_set_header firstname $_2;
proxy_set_header lastnamename $_3;
# set to the hostname that the protected upstream app needs
proxy_set_header host $host;
次の手順
この手順を必要なリダイレクトごとに繰り返します。第3のポリシーを追加するのであれば、https://3rdbackend.myportal.com/にリダイレクトする/3rdのような名前を使用します。
関連項目