kong.service

    Sets the desired Upstream entity to handle the load-balancing step for this request. Using this method is equivalent to creating a Service with a property equal to that of an Upstream entity (in which case, the request would be proxied to one of the Targets associated with that Upstream).

    The host argument should receive a string equal to the name of one of the Upstream entities currently configured.

    Phases

    • access

    Parameters

    • host (string):

    Returns

    1. boolean|nil: true on success, or nil if no upstream entities where found

    2. string|nil: An error message describing the error if there was one.

    Usage

    kong.service.set_target(host, port)

    Sets the host and port on which to connect to for proxying the request. Using this method is equivalent to ask Kong to not run the load-balancing phase for this request, and consider it manually overridden. Load-balancing components such as retries and health-checks will also be ignored for this request.

    The host argument expects a string containing the IP address of the upstream server (IPv4/IPv6), and the port argument must contain a number representing the port on which to connect to.

    Phases

    • access

    Parameters

    • host (string):
    • port (number):

    Usage

    1. kong.service.set_target("service.local", 443)

    Sets the client certificate used while handshaking with the Service.

    The chain argument is the client certificate and intermediate chain (if any) returned by functions such as .

    Phases

    • rewrite, access, balancer

    Parameters

    • chain (cdata): The client certificate chain
    • key (cdata): The client certificate private key

    Returns

    1. boolean|nil: if the operation succeeded, nil if an error occurred

    2. string|nil: An error message describing the error if there was one

    Usage

    kong.service.set_tls_verify(on)

    Sets whether TLS verification is enabled while handshaking with the Service.

    The on argument is a boolean flag, where true means upstream verification is enabled and false disables it.

    This call affects only the current request. If the trusted certificate store is not set already (via or kong.service.set_upstream_ssl_trusted_store), then TLS verification will always fail with “unable to get local issuer certificate” error.

    Phases

    • rewrite, access, balancer

    Parameters

    • on (boolean): Whether to enable TLS certificate verification for the current request

    Returns

    1. boolean|nil: true if the operation succeeded, nil if an error occurred

    2. string|nil: An error message describing the error if there was one

    Usage

    1. local ok, err = kong.service.set_tls_verify(true)
    2. if not ok then
    3. -- do something with error
    4. end

    This call affects only the current request. For the depth to be actually used the verification has to be enabled with either the proxy_ssl_verify directive or using the function.

    Phases

    • rewrite, access, balancer

    Parameters

    Returns

    1. boolean|nil: true if the operation succeeded, nil if an error occurred

    2. string|nil: An error message describing the error if there was one

    Usage

    kong.service.set_tls_verify_store(store)

    Sets the CA trust store to use when validating upstream server’s TLS certificate.

    This call affects only the current request. For the store to be actually used the verification has to be enabled with either the directive or using the kong.service.set_tls_verify function.

    The resty.openssl.x509.store object can be created by following from the Kong/lua-kong-nginx-module repo.

    Phases

    • rewrite, access, balancer

    Parameters

    • store (table): resty.openssl.x509.store object to use

    Returns

    1. boolean|nil: true if the operation succeeded, nil if an error occurred

    2. string|nil: An error message describing the error if there was one

    1. local store = require("resty.openssl.x509.store")
    2. local st = assert(store.new())
    3. -- st:add(...certificate)
    4. local ok, err = kong.service.set_tls_verify_store(st)
    5. if not ok then
    6. -- do something with error
    7. end