Flex Gateway新着情報
Governance新着情報
Monitoring API ManagerWebAssembly (WASM) 拡張機能を使用して、Envoy 上でカスタム検索条件として機能するカスタムポリシーを実装できます。次の手順は、ローカルモードで実行されている API にカスタム検索条件 (ポリシー) をデプロイおよび適用する方法を示しています。
設定 YAML ファイルを作成します。
ファイルを Flex Gateway 設定ディレクトリに保存します。
拡張機能定義を作成します。
base64 を使用して、カスタムポリシー WASM 実装をエンコードします。
拡張機能定義をカスタムポリシー WASM バイナリ実装にリンクします。
カスタムポリシーを API インスタンスにリンクします。
リソースを Flex Gateway インスタンスに適用します。
始める前に、次の準備が整っていることを確認します。
Flex Gateway がインストールされていてローカルモードで実行されている。ゲートウェイのインストールと実行についての詳細は、Flex Gateway のダウンロードを参照してください。
アップストリームサービスの URL が用意されている。例については、ローカルモードでのシンプルな API のパブリッシュを参照してください。
カスタムポリシーが実装およびコンパイルされている。Rust での Flex Gateway カスタムポリシーの実装を参照してください。
custom-policy-example.yaml という設定ファイルを作成します。
ファイルを Flex Gateway 設定ディレクトリに保存します。次に例を示します。
/etc/mulesoft/flex-gateway/conf.d/policies
拡張機能定義を作成します。
次の YAML スニペットをコピーして、新しい設定ファイルに貼り付けます。YAML は、カスタムポリシーの設定とメタデータプロパティを定義します。
apiVersion: gateway.mulesoft.com/v1alpha1
kind: Extension
metadata:
  name: custom-local-example-definition
spec:
  extends:
  - name: extension-authentication
  - name: extension-definition
  properties:
    secret-value:
      type: string
  required:
    - secret-value
metadata.name 値には、拡張機能名が含まれます。
Extension は、他の定義済み拡張機能からプロパティを継承します。たとえば、spec.extends は、拡張機能が extension-definition であり、authentication カテゴリ (extension-authentication) に属していることを指定します。
spec.properties 値は、カスタムポリシーインスタンスを設定するプロパティを定義します。
spec.required 値は、必要なプロパティを指定します。
base64 を使用して、カスタムポリシー WASM バイナリ実装をエンコードします。
次のコマンドを実行して、カスタムポリシー WASM バイナリ実装をエンコードします。
base64 <your-custom-policy-name>.wasm | tr -d '\n\r' > policy
このコマンドは、エンコードデータを policy というファイルに送信します。次のステップで、<WASM_BINARY_IN_BASE64> をこのエンコードデータに置き換えます。
| 
 
 
  | 
拡張機能定義をカスタムポリシー WASM バイナリ実装にリンクします。
custom-policy-example.yaml で、ポリシー実装を含む別のリソースを定義します。
apiVersion: gateway.mulesoft.com/v1alpha1
kind: Extension
metadata:
  name: custom-local-example-flex
spec:
  extends:
    - name: custom-local-example-definition
    - name: envoy-filter
    - name: proxy-wasm-filter
  properties:
    rootId:
      type: string
      default: main
    implementation:
      type: string
      default: base64://<WASM_BINARY_IN_BASE64>
metadata.name 値にはポリシー名が含まれます。これは、定義で指定された名前とは異なる必要があります。
spec.extends 値は、継承元のリソース定義を指定します。たとえば、custom-local-example-definition は以前に定義されたリソースです。
spec.properties.implementation.default の <WASM_BINARY_IN_BASE64> 値を、以前に生成した base64 エンコード WASM バイナリデータに置き換えます。
| 
 ポリシー定義と実装を同じ   | 
カスタムポリシーを API インスタンスにリンクします。
custom-policy-example.yaml で、ポリシーを API インスタンスにリンクする別のリソースを定義します。
apiVersion: gateway.mulesoft.com/v1alpha1
kind: PolicyBinding
metadata:
  name: custom-local-example
spec:
  targetRef:
    kind: ApiInstance
    name: ingress-http
  policyRef:
    kind: Extension
    name: custom-local-example-flex
  config:
    secret-value: "an-example-value"
metadata.name 値には、カスタムポリシーインスタンス名が含まれます。
spec.targetRef.name 値には、カスタムポリシーを適用する API インスタンスの名前が含まれます。API インスタンスはすでに定義済みで、適用されている必要があります。
spec.policyRef.name 値には、適用するカスタムポリシー実装が含まれます。
spec.config 値には、ポリシー設定データが含まれます。
リソースを Flex Gateway インスタンスに適用します。
完全な custom-policy-example.yaml ファイルに次の内容が含まれるようになります。
---
apiVersion: gateway.mulesoft.com/v1alpha1
kind: Extension
metadata:
  name: custom-local-example-definition
spec:
  extends:
  - name: extension-authentication
  - name: extension-definition
  properties:
    secret-value:
      type: string
  required:
    - secret-value
---
apiVersion: gateway.mulesoft.com/v1alpha1
kind: Extension
metadata:
  name: custom-local-example-flex
spec:
  extends:
    - name: custom-local-example-definition
    - name: envoy-filter
    - name: proxy-wasm-filter
  properties:
    rootId:
      type: string
      default: main
    implementation:
      type: string
      default: base64://<WASM_BINARY_IN_BASE64>
---
apiVersion: gateway.mulesoft.com/v1alpha1
kind: PolicyBinding
metadata:
  name: custom-local-example
spec:
  targetRef:
    kind: ApiInstance
    name: ingress-http
  policyRef:
    kind: Extension
    name: custom-local-example-flex
  config:
    secret-value: "an-example-value"
ファイルを Flex Gateway 設定ディレクトリに保存します。次に例を示します。
/etc/mulesoft/flex-gateway/conf.d/policies
これで、カスタムポリシーが ingress-http という API インスタンスに適用されます。