The Forward Proxy plugin allows Kong to connect to intermediary transparent
HTTP proxies, instead of directly to the upstream_url, when forwarding requests
upstream. This is useful in environments where Kong sits in an organization’s
internal network, the upstream API is available via the public internet, and
the organization proxies all outbound traffic through a forward proxy server.
Configuration Reference
This plugin is compatible with DB-less mode.
In DB-less mode, you configure Kong Gateway
declaratively.
Therefore, the Admin API is mostly read-only. The only tasks it can perform are all
related to handling the declarative config, including:
- Setting a target's health status in the load balancer
- Validating configurations against schemas
- Uploading the declarative configuration using the
/config
endpoint
Enable the plugin on a service
Admin API
Kubernetes
Declarative (YAML)
Konnect Cloud
Kong Manager
For example, configure this plugin on a service by
making the following request:
curl -X POST http://{HOST}:8001/services/{SERVICE}/plugins \
--data "name=forward-proxy" \
--data "config.http_proxy_host=http://example.com" \
--data "config.http_proxy_port=80" \
--data "config.proxy_scheme=http" \
--data "config.auth_username=example_user" \
--data "config.auth_password=example_pass" \
--data "config.https_verify=false"
SERVICE
is the id
or name
of the service that this plugin
configuration will target.
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <forward-proxy-example>
config:
http_proxy_host: http://example.com
http_proxy_port: 80
proxy_scheme: http
auth_username: example_user
auth_password: example_pass
https_verify: false
plugin: forward-proxy
Next, apply the KongPlugin resource to a
Service by annotating the
Service as follows:
apiVersion: v1
kind: Service
metadata:
name: {SERVICE}
labels:
app: {SERVICE}
annotations:
konghq.com/plugins: <forward-proxy-example>
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
name: {SERVICE}
selector:
app: {SERVICE}
{SERVICE}
is the id
or name
of the service that this plugin
configuration will target.
Note: The KongPlugin resource only needs to be defined once
and can be applied to any service, consumer, or route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
For example, configure this plugin on a service by
adding this section to your declarative configuration file:
plugins:
- name: forward-proxy
service: {SERVICE}
config:
http_proxy_host: http://example.com
http_proxy_port: 80
proxy_scheme: http
auth_username: example_user
auth_password: example_pass
https_verify: false
SERVICE
is the id
or name
of the service that this plugin
configuration will target.
Configure this plugin on a service:
- In Konnect Cloud, select the service on the ServiceHub page.
- Scroll down to Versions and select the version.
- Scroll down to Plugins and click New Plugin.
- Find and select the Forward Proxy Advanced plugin.
-
Enter the following parameters, updating the default
or sample values as needed:
- Config.Proxy Scheme:
http
- Config.Https Verify: clear checkbox
- Click Create.
Configure this plugin on a service:
- In Kong Manager, select the workspace.
- From the Dashboard, scroll down to Services and click View for the
service row.
- Scroll down to plugins and click Add Plugin.
-
Find and select the Forward Proxy Advanced plugin.
Note: If the plugin is greyed out, then it is not available
for your product tier. See
Kong Gateway tiers.
- If the option is available, select Scoped.
- Add the service name and ID to the Service field if it
is not already prefilled.
-
Enter the following parameters, updating the default or sample values as needed:
- Config.Proxy Scheme:
http
- Config.Https Verify: clear checkbox
- Click Create.
Enable the plugin on a route
Admin API
Kubernetes
Declarative (YAML)
Konnect Cloud
Kong Manager
For example, configure this plugin on a route with:
$ curl -X POST http://{HOST}:8001/routes/{ROUTE}/plugins \
--data "name=forward-proxy" \
--data "config.http_proxy_host=http://example.com" \
--data "config.http_proxy_port=80" \
--data "config.proxy_scheme=http" \
--data "config.auth_username=example_user" \
--data "config.auth_password=example_pass" \
--data "config.https_verify=false"
ROUTE
is the id
or name
of the route that this plugin configuration
will target.
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <forward-proxy-example>
config:
http_proxy_host: http://example.com
http_proxy_port: 80
proxy_scheme: http
auth_username: example_user
auth_password: example_pass
https_verify: false
plugin: forward-proxy
Then, apply it to an ingress (Route or Routes)
by annotating the ingress as follows:
apiVersion: networking/v1beta1
kind: Ingress
metadata:
name: {ROUTE}
annotations:
kubernetes.io/ingress.class: kong
konghq.com/plugins: <forward-proxy-example>
spec:
rules:
- host: examplehostname.com
http:
paths:
- path: /bar
backend:
serviceName: echo
servicePort: 80
ROUTE
is the id
or name
of the route that this plugin configuration
will target.
Note: The KongPlugin resource only needs to be defined once
and can be applied to any service, consumer, or route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
For example, configure this plugin on a route by
adding this section to your declarative configuration file:
plugins:
- name: forward-proxy
route: <route>
config:
http_proxy_host: http://example.com
http_proxy_port: 80
proxy_scheme: http
auth_username: example_user
auth_password: example_pass
https_verify: false
ROUTE
is the id
or name
of the route that this plugin configuration
will target.
Configure this plugin on a route:
- In Konnect Cloud, select the service from the ServiceHub page.
- Scroll down to Versions and select the version.
- Select the route.
- Scroll down to Plugins and click Add Plugin.
- Find and select the Forward Proxy Advanced plugin.
-
Enter the following parameters, updating the default
or sample values as needed:
- Config.Proxy Scheme:
http
- Config.Https Verify: clear checkbox
- Click Create.
Configure this plugin on a route:
- In Kong Manager, select the workspace.
- From the Dashboard, select Routes in the left navigation.
- Click View for the route row.
- Scroll down to plugins and click Add Plugin.
-
Find and select the Forward Proxy Advanced plugin.
Note: If the plugin is greyed out, then it is not available
for your product tier. See
Kong Gateway tiers.
- If the option is available, select Scoped.
- Add the Route ID if it is not already prefilled.
-
Enter the following parameters, updating the default
or sample values as needed:
- Config.Proxy Scheme:
http
- Config.Https Verify: clear checkbox
- Click Create.
Enabling the plugin on a consumer
Admin API
Kubernetes
Declarative (YAML)
Kong Manager
For example, configure this plugin on a consumer with:
$ curl -X POST http://{HOST}:8001/consumers/{CONSUMER}/plugins \
--data "name=forward-proxy" \
--data "config.http_proxy_host=http://example.com" \
--data "config.http_proxy_port=80" \
--data "config.proxy_scheme=http" \
--data "config.auth_username=example_user" \
--data "config.auth_password=example_pass" \
--data "config.https_verify=false"
CONSUMER
is the id
or username
of the consumer that this plugin
configuration will target.
You can combine consumer.id
, service.id
, or route.id
in the same request, to further narrow the scope of the plugin.
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <forward-proxy-example>
config:
http_proxy_host: http://example.com
http_proxy_port: 80
proxy_scheme: http
auth_username: example_user
auth_password: example_pass
https_verify: false
plugin: forward-proxy
Then, apply it to a consumer by
annotating the KongConsumer resource as follows:
apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
name: {CONSUMER}
annotations:
konghq.com/plugins: <forward-proxy-example>
kubernetes.io/ingress.class: kong
CONSUMER
is the id
or username
of the consumer that this plugin
configuration will target.
Note: The KongPlugin resource only needs to be defined once
and can be applied to any Service, Consumer, or Route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
For example, configure this plugin on a consumer by
adding this section to your declarative configuration file:
plugins:
- name: forward-proxy
consumer: {CONSUMER}
config:
http_proxy_host: http://example.com
http_proxy_port: 80
proxy_scheme: http
auth_username: example_user
auth_password: example_pass
https_verify: false
CONSUMER
is the id
or username
of the consumer that this plugin
configuration will target.
Configure this plugin on a consumer:
- In Kong Manager, select the workspace.
- From the Dashboard, scroll down to Consumers and click View for the consumer row.
- Select the Plugins tab.
- Click Add Plugin.
-
Find and select the Forward Proxy Advanced plugin.
Note: If the plugin is greyed out, then it is not available
for your product tier. See
Kong Gateway tiers.
- If the option is available, select Global.
-
Enter the following parameters, updating the default or sample values as needed:
- Config.Proxy Scheme:
http
- Config.Https Verify: clear checkbox
- Click Create.
Enable the plugin globally
A plugin which is not associated to any service, route, or consumer is
considered global, and will be run on every request. Read the
Plugin Reference and the Plugin Precedence
sections for more information.
Admin API
Kubernetes
Declarative (YAML)
Kong Manager
For example, configure this plugin globally with:
$ curl -X POST http://{HOST}:8001/plugins/ \
--data "name=forward-proxy" \
--data "config.http_proxy_host=http://example.com" \
--data "config.http_proxy_port=80" \
--data "config.proxy_scheme=http" \
--data "config.auth_username=example_user" \
--data "config.auth_password=example_pass" \
--data "config.https_verify=false"
Create a KongClusterPlugin
resource and label it as global:
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: <global-forward-proxy>
annotations:
kubernetes.io/ingress.class: kong
labels:
global: \"true\"
config:
http_proxy_host: http://example.com
http_proxy_port: 80
proxy_scheme: http
auth_username: example_user
auth_password: example_pass
https_verify: false
plugin: forward-proxy
For example, configure this plugin using the plugins:
entry in the declarative
configuration file:
plugins:
- name: forward-proxy
config:
http_proxy_host: http://example.com
http_proxy_port: 80
proxy_scheme: http
auth_username: example_user
auth_password: example_pass
https_verify: false
Configure this plugin globally:
- In Kong Manager, select the workspace.
- From the Dashboard, select Plugins in the left navigation.
- Click New Plugin.
-
Find and select the Forward Proxy Advanced plugin.
Note: If the plugin is greyed out, then it is not available
for your product tier. See
Kong Gateway tiers.
- If the option is available, set the plugin scope to Global.
-
Enter the following parameters, updating the
default/sample values as needed:
- Config.Proxy Scheme:
http
- Config.Https Verify: clear checkbox
- Click Create.
Parameters
Here's a list of all the parameters which can be used in this plugin's configuration:
Form Parameter |
Description |
name
required
Type: string |
The name of the plugin, in this case forward-proxy . |
service.id
Type: string |
The ID of the Service the plugin targets. |
route.id
Type: string |
The ID of the Route the plugin targets. |
consumer.id
Type: string |
The ID of the Consumer the plugin targets. |
enabled
required
Type: boolean
Default value: true |
Whether this plugin will be applied. |
config.http_proxy_host
semi-optional
Type: string
|
The HTTP hostname or IP address of the forward proxy to which to connect.
Required if http_proxy_port is set.
At least one of http_proxy_host or https_proxy_host must be specified.
|
config.http_proxy_port
semi-optional
Type: string
|
The TCP port of the HTTP forward proxy to which to connect.
Required if http_proxy_host is set.
At least one of http_proxy_port or https_proxy_port must be specified.
|
config.https_proxy_host
semi-optional
Type: string
|
The HTTPS hostname or IP address of the forward proxy to which to connect.
Required if https_proxy_port is set.
At least one of http_proxy_host or https_proxy_host must be specified.
|
config.https_proxy_port
semi-optional
Type: string
|
The TCP port of the HTTPS forward proxy to which to connect.
Required if https_proxy_host is set.
At least one of http_proxy_port or https_proxy_port must be specified.
|
config.proxy_host
optional
Type: string
|
This parameter is deprecated as of Kong Gateway 2.8.0.0 and
is planned to be removed in 3.x.x.
Use http_proxy_host or https_proxy_host instead.
The hostname or IP address of the forward proxy to which to connect.
|
config.proxy_port
optional
Type: string
|
This parameter is deprecated as of Kong Gateway 2.8.0.0 and
is planned to be removed in 3.x.x.
Use http_proxy_host or https_proxy_host instead.
The TCP port of the forward proxy to which to connect.
|
config.proxy_scheme
required
Type: string
Default value: http
|
The proxy scheme to use when connecting. Only http is supported.
|
config.auth_username
optional
Type: string
|
The username to authenticate with, if the forward proxy is protected
by basic authentication.
This field is referenceable, which means it can be securely stored as a
secret
in a vault. References must follow a specific format.
|
config.auth_password
optional
Type: string
|
The password to authenticate with, if the forward proxy is protected
by basic authentication.
This field is referenceable, which means it can be securely stored as a
secret
in a vault. References must follow a specific format.
|
config.https_verify
required
Type: boolean
Default value: false
|
Whether the server certificate will be verified according to the CA certificates
specified in
lua_ssl_trusted_certificate.
|
The plugin attempts to transparently replace upstream connections made by Kong
core, sending the request instead to an intermediary forward proxy. Only
transparent HTTP proxies are supported; TLS connections (via CONNECT
)
are not supported.
Changelog
Kong Gateway 2.8.x (plugin version 1.2.0)
-
Added http_proxy_host
, http_proxy_port
, https_proxy_host
, and
https_proxy_port
configuration parameters for mTLS support.
These parameters replace the proxy_port
and proxy_host
fields, which
are now deprecated and planned to be removed in 3.x.x.
-
The auth_password
and auth_username
configuration fields are now marked as
referenceable, which means they can be securely stored as
secrets
in a vault. References must follow a specific format.
-
Fixed a plugin version in the documentation. Previously, there was a plugin
version labelled as 1.0.x
. It is now updated to align with the
plugin’s actual version, 1.1.x
.
Kong Gateway 2.7.x (plugin version 1.1.0)
- Added
auth_username
and auth_password
parameters for proxy authentication.