11.6. WasmPlugin カスタムリソースの作成
Service Mesh は、WasmPlugin
として知られる Proxy-WASM エクステンションを指定してサイドカープロキシーに適用するためのカスタムリソース定義 (CRD) を提供します。Service Mesh は、3scale による HTTP API 管理を必要とする一連のワークロードにカスタムリソース (CR) を適用します。
手順
- このモジュールを適用する Service Mesh デプロイメント上の OpenShift Container Platform (OCP) namespace (info プロジェクトなど) を特定します。
registry.redhat.io 認証情報を使用してプルシークレットを取得します。
-
WasmPlugin
と同じ namespace に新しいプルシークレットリソースを作成します。
-
モジュールが適用されるアプリケーションのセットを識別するセレクターとともに、
threescale-wasm-auth
モジュールがデプロイされる namespace を宣言する必要があります。次の例は、threescale-wasm-auth
モジュールの CR の YAML 形式です。apiVersion: extensions.istio.io/v1alpha1 kind: WasmPlugin metadata: name: <threescale_wasm_plugin_name> namespace: <namespace> spec: url: oci://registry.redhat.io/3scale-amp2/3scale-auth-wasm-rhel8:0.0.3 imagePullSecret: <pull_secret_resource> phase: AUTHZ priority: 100 match: - mode: CLIENT selector: matchLabels: app: <selector> pluginConfig: api: v1 system: name: system upstream: name: outbound|443||<system_host> url: <system_url> timeout: 5000 token: <access_token> backend: name: backend upstream: name: outbound|<backend_port>||<backend_host> url: <backend_url> timeout: 5000 extensions: - no_body services: - id: '<product_id>' authorities: - "*" credentials: user_key: - query_string: keys: - user_key - header: keys: - user_key
-
spec.pluginConfig
フィールドはアプリケーションによって異なります。その他のフィールドはすべて、このカスタムリソースの複数のインスタンス間で永続します。 -
この特定の
WasmPlugin
spec.pluginConfig
は、クエリー文字列で提供されるuser_key
認証を使用して設定されています。 説明:
-
name
: 3scale 内のWasmPlugin
の一意の名前または識別子を指定します。 -
namespace
: ワークロードの namespace。 -
imagePullSecret
: 手順 2 で作成したプルシークレットの名前。 -
selector
: ワークロードラベルセレクター。info プロジェクトの製品ページをご利用ください。 -
backend-port
: 使用している 3scale によって異なります。3scale URL を Service Mesh に追加する を参照してください。たとえば、内部 3scale はポート 80 を使用し、外部 3scale はポート 443 を使用します。 -
backend-host
、system-host
: 3scale URL を Service Mesh に追加する で使用したホストと同じホストを使用します。 -
system-url
、backend-url
: それぞれのホストを使用し、プロトコルを追加します。たとえば、https://<system-host>
などです。 -
access-token
: システムテナントへのアクセストークン。 -
product_id
: 使用する製品の ID。複数の製品が必要な場合は、サービスセクションで複数の製品を定義します。
-
spec.pluginConfig
および残りのカスタムリソースにモジュール設定を追加したら、oc apply
コマンドでこれを適用します。$ oc apply -f threescale-wasm-auth-info.yaml
-
11.6.1. 3scale WasmPlugin 認証オプション
これらは、3scale User key (App IDd/App key) 認証の設定例です。
ユーザーキー
apiVersion: extensions.istio.io/v1alpha1 kind: WasmPlugin metadata: name: <threescale_wasm_plugin_name> spec: ... pluginConfig: ... services: - id: '<service_id>' authorities: - "*" credentials: user_key: - query_string: keys: - user_key - header: keys: - user_key
App ID と App key
apiVersion: extensions.istio.io/v1alpha1 kind: WasmPlugin metadata: name: <threescale_wasm_plugin_name> spec: ... pluginConfig: ... services: - id: '<service_id>' authorities: - "*" credentials: app_id: - query_string: keys: - app_id - header: keys: - app_id app_key: - query_string: keys: - app_key - header: keys: - app_key
OIDC
WasmPlugin
自体とは別に、OpenID Connect (OIDC) が機能するには、RequestAuthentication
と呼ばれる追加のカスタムリソースも必要です。RequestAuthentication
を適用すると、JWT トークンを検証するネイティブプラグインを使用して Envoy
が設定されます。プロキシーは、モジュールを実行する前にすべてを検証します。したがって、失敗したリクエストが 3scale WebAssembly モジュールに実行されません。
apiVersion: security.istio.io/v1beta1 kind: RequestAuthentication metadata: name: jwt-example namespace: <info> spec: selector: matchLabels: app: <productpage> jwtRules: - issuer: >- "<url>/auth/realms/<realm_name>" jwksUri: >- "<url>/auth/realms/<realm_name>/protocol/openid-connect/certs"
説明
-
<url>
: OIDC インスタンスの URL は、keycloak で設定されている場合、認証設定用の keycloak OIDC プロバイダーのメタデータエンドポイントを指定するために使用されます。 -
<realm_name>
: OIDC で使用されるレルムの名前。
apiVersion: extensions.istio.io/v1alpha1 kind: WasmPlugin metadata: name: <threescale_wasm_plugin_name> spec: ... pluginConfig: ... services: - id: '<service_id>' authorities: - "*" credentials: app_id: - filter: path: - envoy.filters.http.jwt_authn - "0" keys: - azp - aud ops: - take: head: 1