.env
with your Tyk Dashboard license key
make
command:
http://localhost:3000
using the following Bootstrapped credentials:
.env.example
./tyk/scripts/bootstrap-oss.sh
script creates an API definition that includes the custom plugin.
STDOUT
Pump where the records will be printed to the Standard OUT (docker logs!)
Property | Description |
---|---|
Enabled | When true, the plugin is activated |
Name | A name used to identify the plugin |
Path | The path to the source code file on the Tyk Gateway file system |
Function name | The name of the function that implements the plugin. The function should exist within the source code file referenced in path |
Raw body only | When set to true, this flag indicates that only the raw request body should be processed |
Require session state | When set to true, Tyk Gateway will serialize the request session state and pass it as an argument to the function that implements the plugin in the target language. This is applicable to Post, Response, and Authentication hooks only |
grpc
plugin driver should be used to instruct Tyk to request execution of plugins from within a gRPC server that is external to the Tyk process. This offers additional language support since Tyk can integrate with a gRPC server that is implemented using any supported gRPC language.
For a given API it is not possible to mix the implementation language for the plugin types: Pre, Authentication, Post, Post Authentication and Response plugins. For example, it is not possible to implement a pre request plugin in Go and also implement a post request plugin in Python for the same API.
x-tyk-api-gateway.middleware.global
section is used to configure plugins in a Tyk OAS API. It contains a pluginConfig
section and a list of plugins for each phase of the API request / response lifecycle.
The pluginConfig
section contains the driver
parameter that is used to configure the plugin implementation language:
x-tyk-api-gateway.middleware.global
section, keyed lists of plugins can be configured for each phase of the API request / response lifecycle described in the table below:
Phase | Description | Config Key |
---|---|---|
Pre | Executed at the start of the request processing chain | prePlugins |
Post Auth | Executed after the requester has been authenticated | postAuthenticationPlugins |
Post | Executed at the end of the request processing chain | postPlugins |
Response | Occurs after the main request processing but before the response is sent. | responsePlugins |
enabled
: When true, enables the plugin.functionName
: The name of the function that implements the plugin within the source file.path
: The path to the plugin source file.rawBodyOnly
: When true, indicates that only the raw body should be processed.requireSession
: When true, indicates that session metadata will be available to the plugin. This is applicable only for post, post authentication and response plugins.postAuthenticationPlugins
list as shown below:
driver
field to goplugin
within the pluginConfig
object. This configuration instructs Tyk Gateway that our plugins are implemented using Golang.
We can also see that the following type of plugins are configured:
prePlugins
list. The plugin is enabled and implemented by function pre-plugin
within the source file located at path /path/to/plugin1.so
.postAuthenticationPlugins
list. The plugin is enabled and implemented by function post_authentication_func
within the source file located at path /path/to/plugin1.so
. The raw request body and session metadata is available to the plugin.responsePlugins
list. The plugin is enabled and implemented by function postplugin
within the source file located at path /path/to/plugin1.so
. The raw request body and session metadata is available to the plugin.postPlugins
list. The plugin is enabled and implemented by function Response
within the source file located at path /path/to/plugin1.so
. The raw request body and session metadata is available to the plugin.path
and functionName
parameters for each plugin to reflect the source code.
Function Name
: Enter the name of the function within your plugin code that Tyk should invoke.Path
: Enter the path to the source file that contains the function that implements your plugin.Raw Body Only
: Optionally, toggle the Raw Body Only switch to true when you do not wish to fill body in request or response object for your plugins.Phase | Description | Config |
---|---|---|
Pre | Executed at the start of the request processing chain | pre |
Auth | Executed during the authentication step | auth_check |
Post Auth | Executed after the requester has been authenticated | post_key_auth |
Post | Executed at the end of the request processing chain | post |
Response | Executed on the response received from the upstream | response |
auth_check
), post authentication (post_key_auth
), post, pre and response plugins configured.
It can be seen that each plugin is configured with the specific function name and associated source file path of the file that contains the function. Furthermore, each lifecycle phase (except auth
) can have a list of plugins configured, allowing for complex processing workflows. For example, you might develop one plugin for logging and another for modifying the request in the pre request phase. When multiple plugins are configured for a phase they will be executed in the order that they appear in the API definition.
The driver
configuration parameter describes the plugin implementation language. Please refer to the supported languages section for list of supported plugin driver names.
Each plugin can have additional settings, such as:
disabled
: When true, disables the plugin.raw_body_only
: When true, indicates that only the raw body should be processed.require_session
: When true, indicates that session metadata will be available to the plugin. This is applicable only for post, post authentication and response plugins.custom_middleware
section of the Tyk Classic API Definition.
http://my-bundle-server.com/bundles/bundle-latest.zip
. The bundle contents will be cached so that, when a Tyk reload event occurs, the Gateway does not have to retrieve the bundle from the server again each time. If you want to use a different bundle then you must update your API to retrieve a different bundle filename and then trigger a reload. It is not sufficient simply to replace the bundle file on your server with an updated version with the same name - the caching ensures this will not be retrieved during a reload event.
As a suggestion, you may organize your plugin bundle files using a Git commit reference or version number, e.g. bundle-e5e6044.zip
, bundle-48714c8.zip
, bundle-1.0.0.zip
, bundle-1.0.1.zip
, etc.
Alternatively, you may delete the cached bundle from Tyk manually and then trigger a hot reload to tell Tyk to fetch a new one. By default, Tyk will store downloaded bundles in this path:
{ TYK_ROOT } / { CONFIG_MIDDLEWARE_PATH } / bundles
tyk.conf
:
enable_bundle_downloader
: Enables the bundle downloader.
bundle_base_url
: A base URL that will be used to download the bundle. For example if we have bundle-latest.zip
specified in the API definition, Tyk will fetch the following file: http://my-bundle-server.com/bundles/bundle-latest.zip
(see the next section for details).
public_key_path
: Sets a public key, used for verifying signed bundles. If unsigned bundles are used you may omit this.
"enable_coprocess": true
in your tyk.conf
when using rich plugins!manifest.json
). The manifest file contains important information like the configuration block and the list of source code files that will be included as part of the bundle file. If a file isn’t specified in the list, it won’t be included in the resulting file, even if it’s present in the current directory.
A sample manifest file looks like this:
checksum
and signature
fields empty, the bundler tool will fill these during the build process.
The custom_middleware
block follows the standard syntax we use for Tyk plugins. In Tyk Community Edition, where file-based API configuration is used by default, a custom_middleware
block is located/added to the API configuration file.
tyk
binary. For further details please visit the Bundle CLI tool page.
pluginConfig
section within the middleware.global
section of the x-tyk-api-gateway
part of a Tyk OAS API Definition.
The pluginConfig
section is structured as follows:
bundle
: A JSON entity that contains the following configuration parameters:
enabled
: When true
, enables the plugin.path
: The relative path of the zip file in relation to the base URL configured on the remote webserver that hosts plugin bundles.driver
: Indicates the type of plugin, e.g. golang
, grpc
, lua
, otto
or python
.middleware.global.pluginConfig.bundle
object. The plugin is enabled and bundled within file plugin.zip
. The plugin bundle is a Go plugin, i.e. middleware.global.pluginConfig.driver
has been configured with value goplugin
.
The configuration above is a complete and valid Tyk OAS API Definition that you can import into Tyk to try out custom plugin bundles, assuming that you have provided a valid bundle file named plugin.zip
.
custom_middleware_bundle
field of the Tyk Classic API Definition. An illustrative example is listed below:
manifest.json
file contained within bundle-latest.zip
uploaded to your remote webserver, e.g. http://your-example-plugin-server.com/plugins
.
Tyk Gateway should be configured for downloading plugin bundles from a secured web server. Please consult the plugin bundles documentation for further details.
bundle
command:
--manifest
command option.
TYK_GW_PUBLICKEYPATH
or the public_key_path
parameter in tyk.conf
:bundle-directory
location.manifest.json
will reference the files located in the bundle-directory
, ensure plugin source files are organized relative to the manifest. The Tyk Gateway will load and execute these plugins based on the paths defined in the manifest.json
file.
Sample manifest.json
is shown below for Golang, Javascript and Python bundles in the tabs below.
manifest.json
with the checksum and signature
(if required) applied, in ZIP format.
By default, Tyk will attempt to sign plugin bundles for improved security. If no private key is specified, the program
will prompt for a confirmation. Use -y
to override this (see options below).
--manifest
: Specifies the path to the manifest file. This defaults to manifest.json
within the current working
directory.--output
: Specifies the name of the bundle file e.g. --output bundle-latest.zip
. If this flag is not specified,
bundle.zip
will be used.-y
: Force tool to create unsigned bundle without prompting e.g. $ tyk bundle build --output bundle-latest.zip -y
.--key
: Specifies the path to your private key which is used to generate signed bundle e.g.
$ tyk bundle build --output bundle-latest.zip --key=mykey.pem
.tykio/tyk-gateway:v5.4.0
image to build a Tyk plugin bundle. It mounts
the current directory from the host as /plugin-source
and a directory containing keys as /keys
inside the container.
The working directory within the container is set to /plugin-source
, and the default entrypoint is overridden to use
/bin/bash
. The command executed in the container exports a modified PATH
to include the Tyk Gateway binaries, then
runs tyk bundle build
to generate a plugin bundle named bundle.zip
, using the specified key for authentication. The
container is automatically removed after the command completes, and the operation is conducted interactively.
Auth | Pre | Post-Auth | Post | Response | |
---|---|---|---|---|---|
GoLang | ✅ | ✅ | ✅ | ✅ | ✅ |
JavaScript | ❌ | ✅ | ❌ | ✅ | ❌ |
gRPC | ✅ | ✅ | ✅ | ✅ | ✅ |
Python | ✅ | ✅ | ✅ | ✅ | ✅ |
Lua | ✅ | ✅ | ✅ | ✅ | ❌ |
Plugin | Name |
---|---|
GoLang | goplugin |
JavaScript | otto |
gRPC | grpc |
Python | python |
Lua | lua |
GoLang | JavaScript | gRPC | Python | Lua | |
---|---|---|---|---|---|
Runs in Gateway process | ✅ Runs natively | ✅ Built-In JSVM Interpreter | ❌ Standalone server | ✅ Tyk talks with Python interpreter | ✅ |
Built-in SDK | ✅ All Gateway Functionality | ✅ Yes | ❌ | ✅ Yes | ❌ |
TCP Connections (DBs, Redis, etc) | ✅ | ❌ Very Limited | ✅ | ✅ | ✅ |