Expressions
Traffic Policy module enables you to filter inbound and outbound traffic with Common Expression Language (CEL) expressions. Each policy rule expression must evaluate to true in order for the rule's actions to take effect against traffic. In addition to CEL's built-in functions and macros we provide additional variables for the connection.
Connection Variables
The following connection variables are available on the conn
struct:
Name | Type | Description |
---|---|---|
conn.ClientIP | string | The source IP of the TCP connection to the ngrok endpoint. |
conn.Geo.CountryCode | string | The two-letter ISO country code based on the client IP. |
conn.Geo.Latitude | string | The approximate latitude based on the client IP. |
conn.Geo.LatLongRadiusKm | string | The radius in kilometers around the latitude and longitude where the client IP is likely to originate. |
conn.Geo.Longitude | string | The approximate longitude based on the client IP. |
conn.ClientIP
The source IP of the TCP connection to the ngrok endpoint as a string.
- YAML
- JSON
expressions:
- conn.ClientIP in ['::1', '127.0.0.1']
{
"expressions": [
"conn.ClientIP in ['::1', '127.0.0.1']"
]
}
conn.Geo.CountryCode
The two-letter ISO country code based on the client IP.
- YAML
- JSON
expressions:
- conn.Geo.CountryCode != 'US'
{
"expressions": [
"conn.Geo.CountryCode != 'US'"
]
}
conn.Geo.Latitude
The approximate latitude based on the client IP.
- YAML
- JSON
expressions:
- double(conn.Geo.Latitude) >= 45.0
{
"expressions": [
"double(conn.Geo.Latitude) >= 45.0"
]
}
conn.Geo.LatLongRadiusKm
The radius in kilometers around the latitude and longitude where the client IP is likely to originate.
- YAML
- JSON
expressions:
- conn.Geo.LatLongRadiusKm <= '20'
{
"expressions": [
"conn.Geo.LatLongRadiusKm <= '20'"
]
}
conn.Geo.Longitude
The approximate longitude based on the client IP.
- YAML
- JSON
expressions:
- double(conn.Geo.Longitude) <= -93.0
{
"expressions": [
"double(conn.Geo.Longitude) <= -93.0"
]
}