api7 / envoy-apisix

Apache License 2.0
34 stars 6 forks source link

About

A Lua framework that support Apache APISIX plugins run directly in Envoy Lua filter without modify Envoy.

Example

  1. clone the code

    git clone https://github.com/api7/envoy-apisix.git
  2. build and run the example

    $ cd envoy-apisix/example
    $ docker-compose pull
    $ docker-compose up --build -d
  3. test the example

$ curl 127.0.0.1:8000/foo/root.exe -i

HTTP/1.1 403 Forbidden
server: envoy
content-length: 0
date: Wed, 18 Nov 2020 00:08:54 GMT

Plugins

How does it work

We shield platform differences for the plugin layer. All interfaces that need to be used are abstracted in the underlying framework, which we call apisix.core, so that all plugins can run on Envoy and Apache APISIX at the same time.

Architecture

Plugin workflow

Architecture

We use the example to show how the plugin runs:

First step, read configuration

We configure through metadata to determine what plugins need to run on each route and what configuration is for each plugin. In the example, we configured plugin uri-blocker for the route whose prefix is ​​/foo, as well as the block rule of the plugin and the response status when a block is required.

Second step, parse request

We encapsulated the client request data into ctx so that it can be used directly in the entire process.

Third step, run the plugin

We determine whether we need to block this request by matching the configured rules and the obtained uri. If a block is needed, we call respond to directly respond, otherwise we let it go.