mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
acl: a rule's port names the service it came through by @, not by a slash
The part after the @ of a port in a rule names the service: by its port, by the address it listens on, or by both, the address in brackets when IPv6 — connlim 5 60 * * * @1080 connlim 5 60 * * * @10.0.0.1:1080 deny * * * @[::1] A slash, as the delimiter of the first take, would have read as a CIDR habit the day a service is named inside an address list, and @ cannot appear in a port or an address. Digits alone are a port, a dashed pair a port range, anything else an address with a port behind a colon; an @ with nothing after it is refused. The destination port before the @ is unchanged, and so is every rule without one.
This commit is contained in:
1 parent
f951160329
commit
a3e93aa23a
7 files changed
+126
-32
No files matched your search
+30
-11
@@ -1,9 +1,10 @@
|
||||
"""A port in a rule may carry a service port after a slash.
|
||||
"""A port in a rule may name the service the request came through.
|
||||
|
||||
The rules of the limiters are shared by all the services, so there has
|
||||
been no way to limit the connections of one service alone. X/S — or
|
||||
*/S for any destination — matches only requests that came through
|
||||
the service listening on the port S: a deny so written closes one
|
||||
been no way to limit the connections of one service alone. After an @ a
|
||||
port in a rule names that service — by its port, by the address it
|
||||
listens on, or by both: @1080, @10.0.0.1, @[::1]:1080 — and, with no
|
||||
destination written, any destination. A deny so written closes one
|
||||
service, a connlim so written caps one service, and neither touches
|
||||
another service of the same configuration.
|
||||
"""
|
||||
@@ -24,12 +25,12 @@ def run(t):
|
||||
""", ports=[origin])
|
||||
url = f"http://127.0.0.1:{origin}/data"
|
||||
|
||||
# a deny written with a service port closes that service alone
|
||||
# a deny naming a service by its port closes that service alone
|
||||
first, second = t.free_port(), t.free_port()
|
||||
t.start("viaport_deny", f"""
|
||||
log
|
||||
auth iponly
|
||||
deny * * * */{second}
|
||||
deny * * * @{second}
|
||||
allow *
|
||||
proxy -p{first}
|
||||
proxy -p{second}
|
||||
@@ -40,12 +41,12 @@ def run(t):
|
||||
t.ne(200, t.http(url, proxy=f"127.0.0.1:{second}").status,
|
||||
"the service the rule names by its port is refused")
|
||||
|
||||
# a connlim written with a service port caps that service alone
|
||||
# a connlim naming a service by its port caps that service alone
|
||||
third, fourth = t.free_port(), t.free_port()
|
||||
t.start("viaport_connlim", f"""
|
||||
log
|
||||
auth iponly
|
||||
connlim 1 0 * * * */{third}
|
||||
connlim 1 0 * * * @{third}
|
||||
allow *
|
||||
proxy -p{third}
|
||||
proxy -p{fourth}
|
||||
@@ -73,8 +74,26 @@ def run(t):
|
||||
t.eq(200, result.get("status", 0),
|
||||
"and the request the limit waited for finishes whole")
|
||||
|
||||
# a slash with nothing after it, or a bare * in a list, is refused
|
||||
# a service named by its address, and by its address and port
|
||||
if t.has_ipv6():
|
||||
fifth, sixth = t.free_port(), t.free_port()
|
||||
t.start("viaport_ip", f"""
|
||||
log
|
||||
auth iponly
|
||||
deny * * * @[::1]
|
||||
allow *
|
||||
proxy -p{fifth} -i127.0.0.1
|
||||
proxy -p{sixth} -i::1
|
||||
""", ports=[fifth, ("::1", sixth)])
|
||||
|
||||
t.eq(200, t.http(url, proxy=f"127.0.0.1:{fifth}").status,
|
||||
"the service on another address is served")
|
||||
r = t.http(url, proxy=f"[::1]:{sixth}")
|
||||
t.ne(200, r.status if r else 0,
|
||||
"the service the rule names by its address is refused")
|
||||
|
||||
# an @ with nothing after it is refused
|
||||
out = t.run_config("viaport_bad",
|
||||
"log\nallow * * * 443/\nnot_a_command\n")
|
||||
"log\nallow * * * 443@\nnot_a_command\n")
|
||||
t.contains(out, "Invalid port or port range",
|
||||
"a service port with no destination port is refused")
|
||||
"a service with nothing after the @ is refused")
|
||||
Reference in new issue
Block a user