higress-group/higress

Implement api-spec plugin and support api level wasm configuration for all plugins

Ouverte

#601 ouverte le 24 oct. 2023

 (0 commentaire) (1 réaction) (0 personne assignée)Go (1 219 forks)github user discovery
area/apimarea/pluginhelp wantedlevel/challengesig/apim

Métriques du dépôt

Stars
 (9 036 étoiles)
Métriques de merge PR
 (Merge moyen 7j 9h) (18 PRs mergées en 30 j)

Description

Why do you need it?

The api we are talking about here is "business api".

There are several differences between business api and route api:

  1. Intent
  • business api: Use to specific business functions such as trading, pricing, etc.
  • route api: Used to determine which service to proxy the request to if it meets certain conditions.
  1. Config model standards
  • business api: Swagger, OAS3, gRPC/Dubbo IDL etc.
  • route api: Ingress API, Gateway API, etc.
  1. Granularity
  • business api: One business function is mapped to one api.
  • route api: One service backend is mapped to some apis.

We want to implement business api level strategy, for example:

  1. Apply transform plugin to the pricing api to implement mapping of price fields.
  2. Apply key-rate-limit plugin to the trading api to limit transactions per second per user.

How could it be?

  • Implement a plugin which can binding business apis to a route (or service in the feature), plugin's configuration maybe like:
apiVersion: extensions.higress.io/v1alpha1
kind: WasmPlugin
metadata:
  name: api-spec
  namespace: higress-system
spec:
  url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/api-spec:1.0.0
  matchRules:
  - ingress:
    - default/foo
    config:
      name: petStore
      basePath: /v1
      spec:
        '/pet/{petId}':
            get:
              tags:
                - pet
              operationId: getPetById
            post:
              tags:
                - pet
              operationId: updatePetWithForm
  • We can control the acl of operationId of router
apiVersion: extensions.higress.io/v1alpha1
kind: WasmPlugin
metadata:
  name: api-acl
  namespace: higress-system
spec:
  url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/api-acl:1.0.0
  matchRules:
  - ingress:
    - default/foo
    config:
      allow:
      - getPetById
#     deny:
#     - updatePetWithForm
  • We can enable additional plugins when matching API's tag and operationId of specific routes:
apiVersion: extensions.higress.io/v1alpha1
kind: WasmPlugin
metadata:
  name: request-transform
  namespace: higress-system
spec:
  url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/transformer:1.0.0
  matchRules:
  - api:
    - updatePetWithForm
    ingress:
    - default/foo
    config:
      type: request
      rules:
      - operate: map
        querys:
        - key: petId
           value: petid
  - apiTag:
    - pet
    ingress:
    - default/foo    
    config:
      type: request
      rules:
      - operate: remove
        headers:
        - key: x-test-id

Other related information

part of https://github.com/alibaba/higress/issues/535

Guide contributeur