Skip to content

Add a firewall rule

POST/v1/firewall-policies/{uid}/rules

Adds an allow rule to the policy and queues a firewall.apply operation for every resource the policy is attached to. The response's operation_id is the first of those operations, or an empty string when the policy is not attached to anything.

Defaults and limits:

  • direction defaults to inbound, action to allow and protocol to tcp.
  • Leave out both ports (or send 0 for both) to match all ports.
  • Send only port_start to match a single port.
  • cidr is required. A single address needs a prefix length, such as 198.51.100.7/32.

Authentication

Send your API key as Authorization: Bearer <token>. The request is scoped to the workspace in X-Workspace-Slug.

Path parameters

uidstringRequired

The firewall policy's uid.

Headers

X-Workspace-SlugstringRequired

Slug of the workspace the request acts on. You can also pass it as the workspace_slug query parameter.

Request body

directionstring

Traffic direction the rule applies to. Case-insensitive.

Default inboundOne ofinboundoutbound

actionstring

What to do with matching traffic. Only allow is supported.

Default allowOne ofallow

protocolstring

IP protocol to match. Case-insensitive.

Default tcpOne oftcpudpall

port_startinteger

First port of the range, from 1 to 65535. 0 together with port_end 0 (or both omitted) matches all ports.

min 0 · max 65535

port_endinteger

Last port of the range. Defaults to port_start. Must not be lower than port_start.

min 0 · max 65535

cidrstringRequired

Source address range in CIDR notation, IPv4 or IPv6. Use 0.0.0.0/0 to allow any IPv4 source.

descriptionstring

Optional note about what the rule is for. Leading and trailing spaces are trimmed.

Response

201

The rule was created.

successbooleanRequired

true when the request succeeded.

messagestringRequired

Human-readable status message.

dataobject
Show attributes
operation_idstringRequired

On Add a firewall rule and Update a firewall rule, the UID of the first firewall.apply operation queued for the change. An empty string when no operation was queued, and always empty when rules are returned inside a policy.

uidstringRequired

Unique identifier of the rule.

directionstringRequired

Traffic direction the rule applies to.

One ofinboundoutbound

actionstringRequired

What happens to matching traffic. Always allow.

One ofallow

protocolstringRequired

IP protocol the rule matches.

One oftcpudpall

port_startintegerRequired

First port of the range. 0 with port_end 0 means all ports.

port_endintegerRequired

Last port of the range.

cidrstringRequired

Source address range in CIDR notation.

descriptionstring

Note about the rule. Omitted when empty.

is_defaultbooleanRequired

true for the SSH and app-port rules added automatically when the policy was created.

Errors

StatusMeaning
400Validation failed. Possible messages: invalid request (malformed JSON), direction must be inbound or outbound, only allow firewall rules are supported, protocol must be tcp, udp, or all, port range must be between 1 and 65535, cidr is required, or cidr must be a valid CIDR block.
401The API key is missing, invalid, expired or revoked.
403You cannot access the workspace, your role does not allow this action, or the account is suspended.
404No firewall policy with this uid exists in the workspace.

Errors use the standard error format.