The Close Connection Traffic Policy action lets you forcibly close connections to an endpoint when certain conditions are met, for example, when the number of requests exceeds a given limit (to mitigate DDoS attacks). This action can be used with other actions such as rate-limit and deny.

Configuration Reference

The Traffic Policy configuration reference for this action.

Supported Phases

on_http_request, on_tcp_connect

Type

close-connection

Configuration Fields

This action does not have any configuration fields.

Behavior

When this action is executed, connection to the endpoint is closed immediately. This can be useful for dealing with DDoS attacks.

Examples

Basic Example

This basic example configuration will guide you through setting up an endpoint on ngrok (hotdog.ngrok.app) and closing the connection to the endpoint.
1

Save the following traffic policy document to a file called policy.yml

policy.yml
on_http_request:
- name: "Immediately close connection"
  expressions:
    - req.url.path.startsWith("/dc")
  actions:
    - type: close-connection
2

Start the endpoint with the traffic policy

ngrok http 8080 --url hotdog.ngrok.app --traffic-policy-file ./policy.yml
3

Send a request to the endpoint

curl http://hotdog.ngrok.app/dc
You should see something similar to the following:
curl: (16) Error in the HTTP2 framing layer
This is expected as the connection is closed immediately.

Action Result Variables

The following variables are made available for use in subsequent expressions and CEL interpolations after the action has run. Variable values will only apply to the last action execution, results are not concatenated.
This action does not set any variables after it has been executed.