Skip to content

AssemblyScript implementation of a prototype rate-limiting filter using proxy-wasm

Notifications You must be signed in to change notification settings

Kong/proxy-wasm-assemblyscript-rate-limiting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

proxy-wasm-as-rate-limiting

A prototype implementation of a rate-limiting filter written in AssemblyScript, using the proxy-wasm API for running on WebAssembly-enabled gateways.

What's implemented

  • "local" policy only, using the SHM-based key-value store

What's missing

  • Other policies, which would require additional features from the underlying system, such as calling out to a Redis instance.

Build requirements

Building

Once the environment is set up with npm in your PATH, you can build it with:

npm install && make

This will produce as_rate_limiting_debug.wasm and as_rate_limiting.wasm files in build/.

Running

Make sure Kong configuration has the parameter wasm set to on and the injected nginx directive nginx_wasm_shm_kong_wasm_rate_limiting_counters set to some reasonable value, e.g. 12m. This directive defines a shared key/value memory zone named kong_wasm_rate_limiting_counters that's used by the filter to share request counters between workers.

The above configuration can be achieved using the environment variables:

  • KONG_WASM=on
  • KONG_NGINX_WASM_SHM_KONG_WASM_RATE_LIMITING_COUNTERS=12m

The script demo.sh uses docker to start an upstream service and a Kong instance configured to receive requests at http://localhost:8000/rated and to allow only 3 requests per minute through the upstream service.

The docker resources created and initialized by the script can be destroyed by invoking ./demo.sh stop.

About

AssemblyScript implementation of a prototype rate-limiting filter using proxy-wasm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published