Device limits and IP bans
Three settings in [node.controller] turn clients away by who they are and how they behave:
- The device limit holds each user to the number of devices the panel allows, counted as distinct client IP addresses.
- The IP ban turns away, for a while, a client address whose authentications keep failing. An IPv6 client’s whole /64 counts as one address.
- The gRPC carrier limit closes a gRPC connection whose streams keep failing to authenticate.
The first two count client IP addresses, so one switch, enable_device_limit, turns both on, and you turn it on only where katana sees each client’s real address. The third works on every gRPC node without it. A WebSocket node behind a reverse proxy can take each client’s address from a header the proxy adds, with real_ip_header and real_ip_from. Read this page before you turn enable_device_limit on.
Minimal example
Section titled “Minimal example”[[node]]# … panel_type and [node.api] as usual …
[node.controller]enable_device_limit = trueWith the defaults, the node logs this line when it starts:
INFO katana::manager::node: node 1: device limit on, IP ban after 30 failures in 120s for 300s; gRPC connections closed after 8 failed streams in a rowWithout enable_device_limit it logs device limit off, no IP ban, followed by the same gRPC part.
Settings
Section titled “Settings”The keys belong to [node.controller]. The table shows the whole section.
| Key | Type | Required | Default | Description |
|---|---|---|---|---|
listen_ip | string | no | "0.0.0.0" | Address the listener binds: UDP for Hysteria 2 nodes, TCP for every other node type. The port always comes from the panel (or from [node.hysteria].port). Write an IPv4 or IPv6 address without brackets, such as "0.0.0.0", "::" or "203.0.113.10". 0.0.0.0 means every address, IPv6 included: where this host's IPv6 sockets also take IPv4, katana binds ::, and the start-up log reads listening on [::]:<port>. Where they do not, katana binds 0.0.0.0; with net.ipv6.bindv6only set it warns IPv6 sockets here take IPv6 alone (net.ipv6.bindv6only), so listen_ip 0.0.0.0 serves IPv4 only. Any other address is bound as written. The value as written is also part of the node tag, such as V2ray_0.0.0.0_443. A node on one address also puts it in its handoff socket's name; see handoff_dir. |
send_ip | string | no | "0.0.0.0" | Has no effect: katana does not bind outgoing connections to a source address; the operating system chooses it. |
update_periodic | u64 | no | 60 | Seconds between poll cycles. One timer drives everything: fetching the node settings and users, refreshing the audit rules, and reporting traffic. 0 counts as 1. The panel's own push and pull intervals are not read. The first cycle runs one full period after the node is up. It also caps the wait between attempts while a node retries its first start, which otherwise grows to 60 seconds. A hot reload that changes it restarts the timer. |
disable_upload_traffic | bool | no | false | Stop reporting user traffic to the panel. Speed limits and audit rules still apply. Traffic counted while it is on is discarded, so turning it off again reports only what moves from then on. Read on every cycle, so a hot reload applies it at the next cycle. |
disable_get_rule | bool | no | false | Stop fetching audit rules, both from the panel and from rule_list_path. Set at startup, the node runs with no audit rules. |
disable_sniffing | bool | no | false | Stop reading the TLS SNI or HTTP Host from the first bytes of each TCP flow. The sniffed name feeds both the routing rules and the audit rules, so with sniffing off, a flow addressed by IP matches neither a domain rule nor an audit rule. The destination katana connects to is never changed. A hot reload that changes it drops every connection on the node. |
disable_vmess_clock_check | bool | no | false | VMess nodes only (a V2ray node serving VMess). By default a VMess handshake is accepted only while its timestamp is within 120 seconds of the server clock, either way. With true, any plausible timestamp passes, so a client whose clock is wrong still connects. The cost is replay protection: a handshake replayed more than 240 seconds after it first arrived is served again. When it is on, the node logs node <id>: VMess clock check off at start. A hot reload that changes it runs one poll at once, logs VMess clock check on or off, applies to new connections and keeps the open ones. |
enable_device_limit | bool | no | false | Hold each user to the device limit the panel sends, and ban client IPs that keep failing to authenticate. Both count client IP addresses, so turn it on only where katana sees them: clients connect directly, the relays in front of the node send a PROXY protocol v2 header, or, on a WebSocket node, a trusted reverse proxy names them in real_ip_header. On helium it also makes katana report the client addresses users connect from. The Device limits and IP bans page describes both. A hot reload that changes it applies to new connections and keeps the open ones. |
real_ip_header | string | depends | — | WebSocket nodes behind a reverse proxy: the header of each WebSocket upgrade request that names the client, such as "X-Real-IP" or "X-Forwarded-For". Unset, the node reads no header. The header counts only on a connection from an address in real_ip_from; from anyone else it is ignored. A list names the rightmost address outside real_ip_from, or the leftmost when every address is inside it. A trusted proxy that sends no such header, or one that is not a list of IP addresses, is served as the client itself. The address it names is what the device limit, the IP ban and helium's reports count. Set it together with real_ip_from: alone it fails with real_ip_header needs real_ip_from: the proxies trusted to set it, and a value that is not a header name fails with real_ip_header "<value>" is not a header name. katana checks both keys on every node, at --test, at start and on a reload, but only nodes over WebSocket read the header. A hot reload that changes it runs one poll at once, applies to new connections and keeps the open ones. |
real_ip_from | array of strings | depends | [] | The reverse proxies trusted to set real_ip_header, as CIDRs such as "127.0.0.1/32" or "::1/128", like nginx's set_real_ip_from. A bare address is a single host. Set host bits ("192.0.2.1/24") or a value that is not a CIDR fail with real_ip_from "<value>": <reason>. Needed with real_ip_header, and only with it: set alone, it fails with real_ip_from is set without real_ip_header. A hot reload that changes it runs one poll at once, applies to new connections and keeps the open ones. |
ban_max_failures | u32 | no | 30 | Under enable_device_limit: ban a client IP once this many of its authentications fail within ban_window_secs. An IPv6 client's whole /64 counts and is banned as one IP, and an IPv4-mapped address counts as its IPv4 address. 0 bans no one. Counts failures on VMess, VLESS, Trojan, Shadowsocks and AnyTLS nodes. sss streams refused before authentication and connections a REALITY node passes to its cover site are not counted; Hysteria 2 connections are neither counted nor refused. |
ban_window_secs | u64 | no | 120 | The window, in seconds, in which ban_max_failures failures ban an IP. A window that has passed starts the count afresh. |
ban_secs | u64 | no | 300 | How long a ban lasts, in seconds. A banned IP's new connections are dropped before the TLS handshake; its open connections continue. |
carrier_max_failures | u32 | no | 8 | gRPC nodes only: close a gRPC connection once this many of its streams in a row fail to authenticate. A stream that authenticates resets the count. 0 never closes one. Independent of enable_device_limit. |
handoff_dir | path | no | — | Also take the TCP connections that a relay running on the same host accepted for this node and hands over, on a Unix socket of the node's own in this directory. A node on every address (listen_ip 0.0.0.0 or ::) names it after its port, <handoff_dir>/<port>.sock, such as /run/katana/handoff/443.sock for a node on port 443. A node on one address puts the address first, <handoff_dir>/<listen_ip>-<port>.sock, such as /run/katana/handoff/203.0.113.5-443.sock, with an IPv6 address as katana prints it, such as 2001:db8::1-443.sock; so nodes on one port and different addresses get different sockets. The relay sends each connection with a PROXY protocol v2 header that names its client, and katana serves it as if its own listener had accepted it. Every stream node, that is every node type but Hysteria 2, gets a socket; a Hysteria 2 node gets none. The socket has mode 0660, so only its owner and its group can connect. A missing directory is created, mode 0750 and in handoff_group; a directory that already exists is left as it is. Unset, no socket is bound. Write an absolute path short enough that the directory, a / and the node's socket name at port 65535, the longest any port gives, fit in the 107 bytes a Unix socket's path may have: at most 96 bytes on a node on every address, and less on a node on one address, such as 84 bytes with listen_ip = "203.0.113.5". A relative path fails with handoff_dir "<value>" must be an absolute path, a longer one with handoff_dir "<value>" is too long: with "<name>" in it, a socket's path would pass the 107 bytes a Unix socket's path may have, where <name> is that longest name, such as 65535.sock. katana checks it on every node, at --test, at start and on a reload. A hot reload that changes it runs one poll at once, which binds, moves or removes the socket and keeps every open connection, the handed-over ones included. |
handoff_group | string | no | — | The group the handoff sockets, and a directory katana creates for them, are given: the relay's, so that it can connect. Write the group's name as /etc/group lists it, such as "relay"; the relay's user must be in the group. katana looks the name up in /etc/group itself, not through NSS, at --test, at start, on a reload and at every poll, and refuses a name it does not find there with handoff_group "<value>" is not a group in /etc/group. Needs handoff_dir: set alone, it fails with handoff_group is set without handoff_dir. Unset, the sockets keep katana's own group. Unless katana runs as root, its own user must be in the group too, because a process can give a file only a group it belongs to. A hot reload that changes it runs one poll at once, which binds the socket again with the new group and keeps every open connection. The directory keeps the group it has, even one katana created, so give it the new group yourself. |
cert | table | depends | {} | The listener certificate, written as [node.controller.cert]. Required with mode = "file" for Trojan and Hysteria 2 nodes, and for V2ray nodes the panel marks as TLS. katana reads the files again at every poll, so a renewed certificate reaches new connections at the next poll while open ones continue. A hot reload that changes any of its keys drops every connection on the node. |
Every key here applies to connections that arrive after an edit: a hot reload keeps the open ones. The node logs the line above again whenever an edit changes the device limit, the ban or the gRPC carrier limit. Turning the IP ban off lifts every ban at once.
When to turn it on
Section titled “When to turn it on”katana counts a device by the IP address its connection comes from. That address must be the client’s:
| Clients reach the node | Turn enable_device_limit on? |
|---|---|
| Directly | Yes. |
| Through relays that send a PROXY protocol v2 header | Yes. katana takes the client address from the header. |
| Through a reverse proxy or CDN in front of a WebSocket node, which names each client in a header of the WebSocket upgrade | Yes, with real_ip_header and real_ip_from set; see Behind a reverse proxy. |
| Handed over by a relay on the same host, on the node’s handoff socket | Yes. katana takes the client address from the PROXY protocol v2 header the relay sends with each connection; see Handed-over connections. |
| Through relays or a CDN that send neither | No. Every connection comes from a relay’s address, so each relay counts as one device for every user, and a relay whose clients fail to authenticate gets banned. |
PROXY protocol v2
Section titled “PROXY protocol v2”Every TCP listener of a katana node reads a PROXY protocol v2 header when a connection starts with one, and serves a connection without one as it is, so one listener can take relayed and direct clients. There is no setting for it.
- Only version 2, the binary form, is read. A version 1 text header is not.
- The header must arrive within 10 seconds of the connection being accepted.
- A header with the
LOCALcommand, or one that names no TCP source, leaves the connection’s own peer address in place. - A malformed header drops the connection, logged at
DEBUGlevel asdropping a connection from Some(<peer>): PROXY protocol v2: <reason>. - Hysteria 2 runs on UDP and reads no header: its clients must reach the node directly for their addresses to count.
Behind a reverse proxy
Section titled “Behind a reverse proxy”A reverse proxy such as nginx opens its own connection to the node for every client, so every connection comes from the proxy’s address. On a WebSocket node the proxy can name the client in a header of the WebSocket upgrade request instead, and two keys in [node.controller] make katana read it:
[node.controller]listen_ip = "127.0.0.1" # only the proxy on this host connectsenable_device_limit = truereal_ip_header = "X-Real-IP"real_ip_from = ["127.0.0.1/32"]real_ip_headernames the header, for exampleX-Real-IPorX-Forwarded-For. Header names are case-insensitive.real_ip_fromlists the proxies trusted to set it, as CIDRs. The header counts only on a connection from an address inreal_ip_from. On a connection from any other address it is ignored, so a client that reaches the node directly cannot pass itself off as someone else.- Set both or neither. katana checks the pair on every node, at
--test, at start and on a reload, and refuses half of it or a typo in it:real_ip_header needs real_ip_from: the proxies trusted to set it,real_ip_from is set without real_ip_header,real_ip_header "<value>" is not a header name, orreal_ip_from "<value>": <reason>for an entry that is not a CIDR. - Only nodes over WebSocket read the header: VMess, VLESS, Trojan, Shadowsocks, SOCKS, HTTP and sss nodes whose transport is WebSocket. TCP, TLS, REALITY and gRPC nodes, AnyTLS and Hysteria 2 read none, whatever the keys say.
What katana does with the trusted proxy’s header:
| The upgrade request carries | The client katana serves |
|---|---|
One address, such as X-Real-IP: 203.0.113.7 |
That address |
A list, such as X-Forwarded-For: 198.51.100.9, 203.0.113.7, 192.0.2.10 |
The rightmost address outside real_ip_from, or the leftmost when every address is inside it |
| No such header | The proxy itself, logged at DEBUG level as trusted proxy <ip> sent no <header> header; serving it as the client |
| Anything but a list of IP addresses | The proxy itself, logged at DEBUG level as trusted proxy <ip> sent a <header> header that lists no addresses; serving it as the client |
- Every line of the header counts, in order, as one comma-separated list. Each entry must be a bare IPv4 or IPv6 address, without a port or brackets; an IPv4-mapped IPv6 address counts as IPv4. An entry that is not an address, an empty entry or more than 32 addresses make the whole header malformed.
- Each proxy on the way appends the address it heard from, and a client can write any entries it likes in front of them. So katana reads the list from the right, skips the addresses inside
real_ip_from, and takes the first one outside it. For the list in the table, withreal_ip_from = ["127.0.0.1/32", "192.0.2.0/24"], that is203.0.113.7; the198.51.100.9the client wrote itself is ignored. - The address katana takes is the client for everything after it: the device limit counts it, the IP ban counts its failed authentications against it rather than against the proxy and turns its connections away, and helium’s reports carry it. A banned client’s connection is dropped right after its WebSocket upgrade.
- A trusted proxy that sends no header, or a malformed one, is a client itself: every connection without a usable header counts under the proxy’s address.
A minimal nginx location that passes the client’s address on as X-Real-IP, for the example above:
location = /ws { proxy_pass http://127.0.0.1:10000; # the node's port proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr;}$remote_addr is the address nginx’s own client connected from. When nginx itself sits behind a CDN or another proxy, its realip module can set $remote_addr to the client first:
set_real_ip_from 192.0.2.0/24; # the CDN's addressesreal_ip_header X-Forwarded-For;You can also pass the whole list on with proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;, set real_ip_header = "X-Forwarded-For", and put the CDN’s ranges into real_ip_from beside nginx’s address. The other directives a WebSocket proxy needs, such as its timeouts, are explained in the VLESS over WebSocket and TLS recipe.
The device limit
Section titled “The device limit”A user’s device limit is the number of distinct client addresses their connections may come from at the same time. katana takes it from the panel:
| Panel | Where the limit comes from |
|---|---|
| Xboard, V2board | device_limit of each entry in the user list. A missing or null value means no limit. |
| helium | device_limit in the limits of the users answer, said once for every user |
0 means no limit. [node.api].device_limit in katana’s own file has no effect.
katana counts the addresses of the user’s open connections on the node:
- A connection from an address the user already has a connection from is always admitted.
- A connection from one more address is refused at its first request, once the user’s open connections already come from as many addresses as the limit. katana logs the reason at
DEBUGlevel:the user's sessions already come from as many IPs as their device limit. - An address stops counting when its last connection ends.
- Lowering a limit closes nothing: connections already open stay open, and the lower limit applies to new ones.
The limit holds on every node type, Hysteria 2 included. It is per node: one katana process serving several nodes counts each node’s connections on their own.
On helium, the same switch makes katana report the client addresses users connect from; see helium.
The IP ban
Section titled “The IP ban”On VMess, VLESS, Trojan, Shadowsocks and AnyTLS nodes, katana counts, per client address, the handshakes whose credential matches no user. Handshakes that fail for another reason, such as a timeout or a malformed request, are not counted. An sss stream refused before authentication and a connection that a REALITY node passes on to its cover site never count either: a prober must not see the node react to them.
An IPv4 client is counted by its address. An IPv6 client is counted by the /64 its address is in: it can pick any address in its /64 and changes it on its own (privacy addresses), so katana treats the whole /64 as one address. Failures from every address in it add to one count, a success from any of them clears that count, and a ban turns all of them away. An IPv4-mapped IPv6 address, such as ::ffff:203.0.113.7, counts as its IPv4 address. The device limit still counts each IPv6 address on its own.
| Event | What happens |
|---|---|
ban_max_failures failures within ban_window_secs |
The address is banned for ban_secs, logged at INFO level: banned <ip> for <ban_secs>s after <n> failed authentications. For an IPv6 client the line names the /64, such as banned 2001:db8:1:2::/64 for 300s after 30 failed authentications. |
| A new connection from a banned address | Dropped as soon as it is accepted, before any TLS handshake |
| The banned address’s open connections | Keep running |
| A successful authentication | Clears the address’s count. A ban runs to its end. |
| The window passes without a ban | The count starts afresh |
Hysteria 2 connections are neither counted nor refused. ban_max_failures = 0 bans no one.
The gRPC carrier limit
Section titled “The gRPC carrier limit”A gRPC connection carries many streams, and each stream authenticates on its own. katana counts the streams in a row on one connection that fail to authenticate; a stream that authenticates resets the count. When the count reaches carrier_max_failures (8 by default), katana closes the connection, logged at DEBUG level: closing a gRPC connection from Some(<ip>) after <n> failed streams in a row.
This limit does not depend on enable_device_limit and counts no addresses. carrier_max_failures = 0 turns it off.
Related
Section titled “Related”- Speed limits: the other per-user limit.
- Nodes: the rest of
[node.controller]. - helium and Xboard and V2board: where the device limits come from.