Teral

Gateway

Read and change an environment's gateway policies.

Policies run in order, and the first one that blocks a request ends evaluation. Deployments take a copy of the policies when they're created, so changes reach traffic with the next deployment. See Gateway.

List policies

POST /v1/gateway.listPolicies

Returns an environment's policies in the order they run.

Permissions: the key needs one of environment.*.read_policies, environment.<environment_id>.read_policies.

Request

FieldTypeDescription
projectstring, requiredThe project, by ID or slug. 3 to 255 characters.
appstring, requiredThe app, by ID or slug. 3 to 255 characters.
environmentstring, requiredThe environment: production, preview, or its ID. 3 to 255 characters.
curl -X POST https://api.teral.dev/v1/gateway.listPolicies \
  -H "Authorization: Bearer $TERAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "project": "shop",
    "app": "web",
    "environment": "production"
  }'

Response

On success the status is 200 OK. The fields in data:

FieldTypeDescription
idstringThe policy's ID. It changes whenever gateway.setPolicies replaces the list.
namestringThe policy's name. 1 to 256 characters.
enabledbooleanWhether it runs. Disabled policies are kept but skipped.
matchobject[]The conditions. All of them must match for the policy to apply. Missing or empty means every request. At most 10 items.
match[].pathobjectMatches the request path, without the query string.
match[].path.pathobjectHow to compare. Set exactly one of exact, prefix or regex.
match[].path.path.exactstringMatches the exact value. 1 to 1024 characters.
match[].path.path.prefixstringMatches values that start with this. 1 to 1024 characters.
match[].path.path.regexstringMatches an RE2 regular expression. Invalid ones are rejected. 1 to 1024 characters.
match[].path.path.ignoreCasebooleanIgnore upper and lower case.
match[].methodobjectMatches the request method.
match[].method.methodsstring[]The methods to match, such as ["POST", "DELETE"]. At least 1 items.
match[].headerobjectMatches a request header. Set exactly one of present or value.
match[].header.namestringThe header's name. Not case sensitive. 1 to 256 characters.
match[].header.presentbooleantrue matches whenever it's there, whatever its value. One of true.
match[].header.valueobjectHow to compare the header's value. Set exactly one of exact, prefix or regex.
match[].header.value.exactstringMatches the exact value. 1 to 1024 characters.
match[].header.value.prefixstringMatches values that start with this. 1 to 1024 characters.
match[].header.value.regexstringMatches an RE2 regular expression. Invalid ones are rejected. 1 to 1024 characters.
match[].header.value.ignoreCasebooleanIgnore upper and lower case.
match[].queryParamobjectMatches a query parameter. Set exactly one of present or value.
match[].queryParam.namestringThe parameter's name. Case sensitive. 1 to 256 characters.
match[].queryParam.presentbooleantrue matches whenever it's there, whatever its value. One of true.
match[].queryParam.valueobjectHow to compare the parameter's value. Set exactly one of exact, prefix or regex.
match[].queryParam.value.exactstringMatches the exact value. 1 to 1024 characters.
match[].queryParam.value.prefixstringMatches values that start with this. 1 to 1024 characters.
match[].queryParam.value.regexstringMatches an RE2 regular expression. Invalid ones are rejected. 1 to 1024 characters.
match[].queryParam.value.ignoreCasebooleanIgnore upper and lower case.
match[].remoteIpobjectMatches the client's IP address, taken from the connection, not from headers. Set exactly one of in or notIn.
match[].remoteIp.instring[]Matches clients inside any of these ranges, such as 203.0.113.0/24 or 203.0.113.7. 1 to 100 items.
match[].remoteIp.notInstring[]Matches clients outside all of these ranges. 1 to 100 items.
firewallobjectMakes this a Firewall policy, which blocks matching requests with 403.
firewall.actionstringWhat to do with a matching request. ACTION_DENY blocks it. One of ACTION_DENY.
loggingobjectMakes this a Logging policy, which records more about matching requests.
logging.requestHeadersbooleanRecord request headers, the user agent and the client IP. Default false.
logging.responseHeadersbooleanRecord response headers. Default false.
logging.requestBodybooleanRecord the request body, up to a size limit. Default false.
logging.responseBodybooleanRecord the response body, up to a size limit. Default false.
logging.querybooleanRecord the query string. URLs sometimes contain secrets, so this is separate. Default false.

Error statuses: 400, 401, 403, 404, 429, 500. See Errors for the codes behind them.


Replace policies

POST /v1/gateway.setPolicies

Replaces all of an environment's policies with the list you send, in that order. An empty list removes them all. If any policy is invalid, nothing changes. Every policy gets a new ID.

Permissions: the key needs one of environment.*.set_policies, environment.<environment_id>.set_policies.

Request

FieldTypeDescription
projectstring, requiredThe project, by ID or slug. 3 to 255 characters.
appstring, requiredThe app, by ID or slug. 3 to 255 characters.
environmentstring, requiredThe environment: production, preview, or its ID. 3 to 255 characters.
policiesobject[], requiredThe complete list, in the order they should run. At most 50. At most 50 items.
policies[].namestring, requiredA name to recognize the policy by. 1 to 256 characters.
policies[].enabledboolean, requiredWhether it runs. Disabled policies are kept but skipped.
policies[].matchobject[]The conditions. All of them must match for the policy to apply. Missing or empty means every request. At most 10 items.
policies[].match[].pathobjectMatches the request path, without the query string.
policies[].match[].path.pathobject, requiredHow to compare. Set exactly one of exact, prefix or regex.
policies[].match[].path.path.exactstringMatches the exact value. 1 to 1024 characters.
policies[].match[].path.path.prefixstringMatches values that start with this. 1 to 1024 characters.
policies[].match[].path.path.regexstringMatches an RE2 regular expression. Invalid ones are rejected. 1 to 1024 characters.
policies[].match[].path.path.ignoreCasebooleanIgnore upper and lower case.
policies[].match[].methodobjectMatches the request method.
policies[].match[].method.methodsstring[], requiredThe methods to match, such as ["POST", "DELETE"]. At least 1 items.
policies[].match[].headerobjectMatches a request header. Set exactly one of present or value.
policies[].match[].header.namestring, requiredThe header's name. Not case sensitive. 1 to 256 characters.
policies[].match[].header.presentbooleantrue matches whenever it's there, whatever its value. One of true.
policies[].match[].header.valueobjectHow to compare the header's value. Set exactly one of exact, prefix or regex.
policies[].match[].header.value.exactstringMatches the exact value. 1 to 1024 characters.
policies[].match[].header.value.prefixstringMatches values that start with this. 1 to 1024 characters.
policies[].match[].header.value.regexstringMatches an RE2 regular expression. Invalid ones are rejected. 1 to 1024 characters.
policies[].match[].header.value.ignoreCasebooleanIgnore upper and lower case.
policies[].match[].queryParamobjectMatches a query parameter. Set exactly one of present or value.
policies[].match[].queryParam.namestring, requiredThe parameter's name. Case sensitive. 1 to 256 characters.
policies[].match[].queryParam.presentbooleantrue matches whenever it's there, whatever its value. One of true.
policies[].match[].queryParam.valueobjectHow to compare the parameter's value. Set exactly one of exact, prefix or regex.
policies[].match[].queryParam.value.exactstringMatches the exact value. 1 to 1024 characters.
policies[].match[].queryParam.value.prefixstringMatches values that start with this. 1 to 1024 characters.
policies[].match[].queryParam.value.regexstringMatches an RE2 regular expression. Invalid ones are rejected. 1 to 1024 characters.
policies[].match[].queryParam.value.ignoreCasebooleanIgnore upper and lower case.
policies[].match[].remoteIpobjectMatches the client's IP address, taken from the connection, not from headers. Set exactly one of in or notIn.
policies[].match[].remoteIp.instring[]Matches clients inside any of these ranges, such as 203.0.113.0/24 or 203.0.113.7. 1 to 100 items.
policies[].match[].remoteIp.notInstring[]Matches clients outside all of these ranges. 1 to 100 items.
policies[].firewallobjectMakes this a Firewall policy, which blocks matching requests with 403.
policies[].firewall.actionstring, requiredWhat to do with a matching request. ACTION_DENY blocks it. One of ACTION_DENY.
policies[].loggingobjectMakes this a Logging policy, which records more about matching requests.
policies[].logging.requestHeadersbooleanRecord request headers, the user agent and the client IP. Default false.
policies[].logging.responseHeadersbooleanRecord response headers. Default false.
policies[].logging.requestBodybooleanRecord the request body, up to a size limit. Default false.
policies[].logging.responseBodybooleanRecord the response body, up to a size limit. Default false.
policies[].logging.querybooleanRecord the query string. URLs sometimes contain secrets, so this is separate. Default false.
curl -X POST https://api.teral.dev/v1/gateway.setPolicies \
  -H "Authorization: Bearer $TERAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "project": "shop",
    "app": "web",
    "environment": "production",
    "policies": [
      {
        "name": "Admin only from the office",
        "enabled": true,
        "match": [
          {
            "path": {
              "path": {
                "prefix": "/admin"
              }
            }
          },
          {
            "remoteIp": {
              "notIn": [
                "203.0.113.0/24"
              ]
            }
          }
        ],
        "firewall": {
          "action": "ACTION_DENY"
        }
      }
    ]
  }'

Response

On success the status is 200 OK.

Error statuses: 400, 401, 403, 404, 429, 500. See Errors for the codes behind them.


Update a policy

POST /v1/gateway.updatePolicy

Changes one policy and leaves the others and the order alone. Fields you leave out stay as they are. Sending firewall or logging replaces the policy's rule.

Permissions: the key needs one of environment.*.update_policy, environment.<environment_id>.update_policy.

Request

FieldTypeDescription
projectstring, requiredThe project, by ID or slug. 3 to 255 characters.
appstring, requiredThe app, by ID or slug. 3 to 255 characters.
environmentstring, requiredThe environment: production, preview, or its ID. 3 to 255 characters.
policyIdstring, requiredThe policy's ID, from gateway.listPolicies. 1 to 512 characters.
namestringA new name. 1 to 256 characters.
enabledbooleanTurns the policy on or off.
matchobject[] or nullReplaces all conditions. null removes them, so the policy applies to every request. At most 10 items.
match[].pathobjectMatches the request path, without the query string.
match[].path.pathobject, requiredHow to compare. Set exactly one of exact, prefix or regex.
match[].path.path.exactstringMatches the exact value. 1 to 1024 characters.
match[].path.path.prefixstringMatches values that start with this. 1 to 1024 characters.
match[].path.path.regexstringMatches an RE2 regular expression. Invalid ones are rejected. 1 to 1024 characters.
match[].path.path.ignoreCasebooleanIgnore upper and lower case.
match[].methodobjectMatches the request method.
match[].method.methodsstring[], requiredThe methods to match, such as ["POST", "DELETE"]. At least 1 items.
match[].headerobjectMatches a request header. Set exactly one of present or value.
match[].header.namestring, requiredThe header's name. Not case sensitive. 1 to 256 characters.
match[].header.presentbooleantrue matches whenever it's there, whatever its value. One of true.
match[].header.valueobjectHow to compare the header's value. Set exactly one of exact, prefix or regex.
match[].header.value.exactstringMatches the exact value. 1 to 1024 characters.
match[].header.value.prefixstringMatches values that start with this. 1 to 1024 characters.
match[].header.value.regexstringMatches an RE2 regular expression. Invalid ones are rejected. 1 to 1024 characters.
match[].header.value.ignoreCasebooleanIgnore upper and lower case.
match[].queryParamobjectMatches a query parameter. Set exactly one of present or value.
match[].queryParam.namestring, requiredThe parameter's name. Case sensitive. 1 to 256 characters.
match[].queryParam.presentbooleantrue matches whenever it's there, whatever its value. One of true.
match[].queryParam.valueobjectHow to compare the parameter's value. Set exactly one of exact, prefix or regex.
match[].queryParam.value.exactstringMatches the exact value. 1 to 1024 characters.
match[].queryParam.value.prefixstringMatches values that start with this. 1 to 1024 characters.
match[].queryParam.value.regexstringMatches an RE2 regular expression. Invalid ones are rejected. 1 to 1024 characters.
match[].queryParam.value.ignoreCasebooleanIgnore upper and lower case.
match[].remoteIpobjectMatches the client's IP address, taken from the connection, not from headers. Set exactly one of in or notIn.
match[].remoteIp.instring[]Matches clients inside any of these ranges, such as 203.0.113.0/24 or 203.0.113.7. 1 to 100 items.
match[].remoteIp.notInstring[]Matches clients outside all of these ranges. 1 to 100 items.
firewallobjectMakes this a Firewall policy, which blocks matching requests with 403.
firewall.actionstring, requiredWhat to do with a matching request. ACTION_DENY blocks it. One of ACTION_DENY.
loggingobjectMakes this a Logging policy, which records more about matching requests.
logging.requestHeadersbooleanRecord request headers, the user agent and the client IP. Default false.
logging.responseHeadersbooleanRecord response headers. Default false.
logging.requestBodybooleanRecord the request body, up to a size limit. Default false.
logging.responseBodybooleanRecord the response body, up to a size limit. Default false.
logging.querybooleanRecord the query string. URLs sometimes contain secrets, so this is separate. Default false.
curl -X POST https://api.teral.dev/v1/gateway.updatePolicy \
  -H "Authorization: Bearer $TERAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "project": "shop",
    "app": "web",
    "environment": "production",
    "policyId": "pol_4f2…",
    "enabled": false
  }'

Response

On success the status is 200 OK.

Error statuses: 400, 401, 403, 404, 429, 500. See Errors for the codes behind them.

Edit on GitHub

On this page