Gate: Plugin - Request validator
In some cases, you may want to perform custom validation of your requests.
It's possible to do that with the request-validator plugin.
request-validator makes decision if the request is valid based on the response of your validation endpoint.
Example usage
Please see API authentication at the edge.
Configuring Gate
- Environment variables
- HCL
- JSON
- TOML
- YAML
GATE_PLUGINS_<PLUGIN NUMBER>_TYPE=request-validator
GATE_PLUGINS_<PLUGIN NUMBER>_PARAMETERS_VALIDATE_URL=<URL of validation endpoint>
In the Environment variables configuration, <PLUGIN NUMBER> defined plugin execution order.
gate = {
plugins = [
// ...
{
type = "request-validator"
parameters = {
validate_url = "<URL of validation endpoint>"
}
}
// ...
]
}
{
"gate": {
"plugins": [
// ...
{
"type": "request-validator",
"parameters": {
"validate_url": "<URL of validation endpoint>"
}
}
// ...
]
}
}
[[gate.plugins]]
type = "request-validator"
parameters.validate_url = "<URL of validation endpoint>"
gate:
plugins:
// ...
- type: request-validator
parameters:
validate_url: <URL of validation endpoint>
// ...
where:
<URL of validation endpoint>URL to be called by the plugin.
To learn more about configuring Gate, please visit the configuration page and plugins section.
The order of plugins in configuration determines their execution order.
Validation endpoint
The configured endpoint is called on every request with the GET method.
All headers of the original request are forwarded to the validation endpoint.
Two additional headers are included in the request:
SlashID-Target-MethodSlashID-Target-Location
These carry the method and location of the original request, respectively.
If the endpoint returns 2XX status code, the request is considered as valid.
If 5XX HTTP status is returned, Gate will respond with 502 Bad Gateway HTTP status.
In all other cases, Gate will return 401 Unauthorized.
Requests with the OPTIONS method are not validated and are always valid.
Disabling plugin for specific URLs
You can enable or disable this plugin for specific URLs by using the enabled option in the URLs configuration.
- Environment variables
- HCL
- JSON
- TOML
- YAML
GATE_PLUGINS_<plugin number>_TYPE=<plugin type>
GATE_PLUGINS_<plugin number>_ID=<plugin ID>
GATE_PLUGINS_<plugin number>_ENABLED=false
GATE_PLUGINS_<plugin number>_PARAMETERS_<plugin_parameter>=<plugin parameter value>
GATE_URLS_0_PATTERN=svc-another-example.com/
GATE_URLS_0_TARGET=https://another-example:8080
GATE_URLS_0_PLUGINS__<PLUGIN ID>__ENABLED=true
GATE_URLS_0_PLUGINS__<PLUGIN ID>__PARAMETERS_<plugin_parameter>=<plugin parameter value>
Plugin ID is case-insensitive. Because of that, <PLUGIN ID> can be the uppercase version of the plugin ID.
Please note that in URL configuration, the plugin ID is separated by two underscores (__).
gate = {
plugins = [
{
type = "<plugin type>"
id = "<plugin ID>"
enabled = false
parameters = {
<plugin parameter> = <plugin parameter value>
}
}
]
urls = [
{
pattern = "svc-another-example.com/"
target = "https://another-example:8080"
plugins = {
"<plugin ID>" = {
enabled = true
parameters = {
<plugin parameter> = "<plugin parameter value>"
}
}
}
}
]
// ...
}
{
"gate": {
"plugins": [
{
"type": "<plugin type>",
"id": "<plugin ID>",
"enabled": false,
"parameters": {
"<plugin parameter>": "<plugin parameter value>"
}
},
"urls": [
{
"pattern": "svc-another-example.com/",
"target": "https://another-example:8080",
"plugins": {
"<plugin ID>": {
"enabled": true,
"parameters": {
"<plugin parameter>": "<plugin parameter value>"
}
}
}
}
],
// ...
[[gate.plugins]]
type = "<plugin type>"
id = "<plugin ID>"
enabled = false
parameters.<plugin parameter> = <plugin parameter value>
[[gate.urls]]
pattern = "svc-another-example.com/"
target = "https://another-example:8080"
plugins.<plugin ID>.enabled = true
plugins.<plugin ID>.parameters.<plugin parameter> = "<plugin parameter value>"
gate:
plugins:
- type: <plugin type>
id: <plugin ID>
enabled: false
parameters:
<plugin parameter>: <plugin parameter value>
urls:
- pattern: svc-another-example.com/
target: https://another-example:8080
plugins:
<plugin ID>:
enabled: true
parameters:
<plugin parameter>: <plugin parameter value>