Firewall
Choose who can reach a service, by address, range, country or CDN.
Pyo's firewall decides who can reach a service over public traffic, and how often. You set it per service on the service's Firewall tab, under Access. With no rules, everyone gets in. Developers can change the rules. The web application firewall has its own section on the same tab.
Rules
Choose Add rule, then say which clients the rule matches:
- IP address, like
203.0.113.7 - IP range, IPv4 or IPv6, like
198.51.100.0/24 - Country
- Network, a preset like Cloudflare or Tailnet
- Any client
For the first four, pick is in or is not in, and list up to 50 values. Then pick the action:
- Block turns the client away. Websites answer with a plain "access denied" page, status
403. - Allow lets the client in.
- Rate limit lets the client in, up to a number of requests a second or a minute.
You can give the rule a Name. Each service can have up to 500 rules.
Order
Allow and block rules are checked from the top, in the order they're numbered. The first rule that matches decides, and the rest are skipped. If no rule matches a client, it gets in. Use Move up and Move down in a rule's menu to change the order. New rules go last.
To let in only some clients, allow them, then block everyone else:
- Allow if client IP is in
203.0.113.0/24 - Block any client
Or in one rule: Block if client IP is not in 203.0.113.0/24.
A TCP port's own IP filter is checked before the service's rules. It can only narrow them.
Presets
A preset is a named list of address ranges that Pyo keeps up to date. Use it in a rule like any address or range.
| Preset | What it holds |
|---|---|
| Cloudflare | Cloudflare's edge, from cloudflare.com/ips |
| Fastly | Fastly's edge, from its public IP list |
| bunny.net | bunny.net's edge servers, from its edge server list for IPv4 and IPv6 |
| Amazon CloudFront | The addresses CloudFront reaches your servers from (CLOUDFRONT_ORIGIN_FACING in AWS's IP ranges) |
| Tailnet | Tailscale's addresses, 100.64.0.0/10 and fd7a:115c:a1e0::/48 |
| Private networks | 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 and fc00::/7 |
Pyo fetches the CDN lists from each provider once a day. If a fetch fails, it keeps the last list it got. Pyo also ships with a copy of each list, so presets work on a server without internet access. Rules keep the preset's name, so they always use the current list.
To let only a CDN reach a service: Block if client IP is not in Cloudflare. To see who the visitors are behind it, turn on Behind Cloudflare instead.
A CDN's list can hold hundreds of ranges, so rate limits can't use one. Tailnet and Private networks work in rate limits, and count as 2 and 4 of the 16 values. A service's rules can list up to 8,192 ranges in all, with presets counted by their ranges.
Behind Cloudflare
Turn on Behind Cloudflare on the service's Firewall tab when your service's domains are proxied by Cloudflare (the orange cloud). Then:
- Only Cloudflare can reach the service's websites. The rule list shows this first, as Added by Behind Cloudflare.
- The firewall, rate limits and analytics see the real visitor, the address Cloudflare sends in
CF-Connecting-IP. Country rules use the visitor's country.
Pyo Gateway only reads the visitor's address from a connection that comes from Cloudflare's current ranges. It takes the address Cloudflare adds to X-Forwarded-For, which is the same one it sends in CF-Connecting-IP. A client that connects directly is turned away, whatever headers it sends.
Domains through Cloudflare Tunnel don't need this switch. Pyo Gateway takes their visitor only from the tunnel's connectors, and once a domain is switched, only the tunnel gets in.
Set Cloudflare's SSL/TLS mode to Full (strict). Over plain HTTP, Pyo Gateway only checks that the request came from Cloudflare. Your other rules and rate limits apply over HTTPS. Behind Cloudflare applies to websites. It doesn't change TCP and UDP ports.
Let's Encrypt can always reach /.well-known/acme-challenge/, whatever the firewall says, so certificates keep renewing. This holds for every service, behind Cloudflare or not.
Rate limits
Rate limits apply to websites. They count the requests that got past the allow and block rules. They're listed last, without a number, because their order doesn't matter. Every rate limit that matches a request counts it. Each client IP is counted separately, and each server keeps its own count. Over a limit, the client gets 429 Too Many Requests.
A rate limit can't match countries. With is not in, it takes one address or range. A service's rate limits can have up to 16 values in total. Any client uses 2 of them.
What it covers
| Traffic | Addresses and ranges | Countries | Rate limits |
|---|---|---|---|
| Websites | Yes | Yes | Yes |
| TCP ports through Pyo Gateway | Yes | No | No |
| UDP ports, and ports with the gateway turned off | Yes | No | No |
The firewall doesn't cover Port on every server ports, or your servers' own SSH and system ports. For those, see Hardening your server.
Countries only work for websites. TCP and UDP ports never see a client's country. On those ports, a country is never in a list and always not in one. So a rule like Block if country is not in Germany blocks everyone on those ports. Use address rules for them.
Countries
Pyo finds a visitor's country with an IP-location database (GeoLite2 Country) built into the gateway. The gateway doesn't download anything for it.
Country rules work on every website domain. On a domain behind Cloudflare or through Cloudflare Tunnel, Pyo uses the country Cloudflare sends with each request. Cloudflare's IP geolocation must be on (it is by default). If it's off, country rules match no one there, and "is not in" rules block everyone. Visitors that Cloudflare can't place count as country XX.
Elsewhere, websites identify visitors by the address they connect from, or by the PROXY protocol header. They don't trust the X-Forwarded-For header, because a client could put any address there. So behind another CDN or proxy, every visitor looks like that proxy, and country rules see its location.
See what was turned away
Under Analytics, the service's Firewall tab shows the requests and TCP connections that were turned away. You see them over time, with the top rules, countries, addresses and paths. The latest ones show the rule that matched:
- the rule's name
- Behind Cloudflare, if the request didn't come from Cloudflare
- A removed rule, if the rule has since been deleted
- A firewall rule or Over a rate limit, if no rule matches the client now
UDP ports and ports with the gateway turned off aren't counted. Findings from the web application firewall show up in the same list.
Don't lock yourself out
If the dashboard runs on the service's cluster and the change would block your own address, Pyo warns you with This would block you. Type confirm to apply it anyway.
From the API and MCP
Change the firewall with the addFirewallRule, updateFirewallRule, reorderFirewallRules and removeFirewallRule operations. A rule's action is allow, block or rateLimit. Its operator is in or notIn. Its sources are the addresses, ranges or country codes, or presets: cloudflare, fastly, bunny, cloudfront, tailnet and private. Leave sources empty to match any client. A rate limit adds requests and per (second or minute). Turn Behind Cloudflare on or off with setServiceBehindCdn and cdn set to cloudflare or null. Services show it as behindCdn. AI assistants use the add_firewall_rule, update_firewall_rule, reorder_firewall_rules, remove_firewall_rule, set_service_behind_cdn and get_firewall_blocked tools. From the CLI, use pyo firewall.
Web application firewall
To check the content of website requests for attacks like SQL injection, turn on the web application firewall on the service's Firewall tab.