How do I make the admin panel accessible only from specific IPs?
Short answer
Two conditions are created that define the management path (e.g. Path, Regex ^/+admin(/.*)?$, Case Insensitive) and the allowed addresses (Source IP → Manual); in the Block action, the path condition and the negated form of the allowed address condition (!ofis) are combined with and, and the action is added to the Actions field of the vService. In this way, requests to the management path that do not come from the allowed addresses are blocked with 403. Dynamic List can be used for long address lists, and Show Content for a branded block page; if TR7 is behind a CDN or proxy, Trusted Proxy is defined first.
Problem: The Admin Panel Is Open to Everyone
When the admin panel is open to the internet, it becomes the target of password guessing and scanning requests. It is desired that the panel is accessed only from office or VPN addresses, and that other requests are blocked before they reach the Backend Service.
Solution: Six Methods
All the methods rely on two conditions: a condition that recognizes the management path (or the domain name) and a condition that recognizes the allowed addresses. The difference is in the response given to the unauthorized request. The Source IP condition must see the real address of the client; if there is a CDN or a reverse proxy in front of TR7, There is a CDN such as Cloudflare / Akamai in front of TR7; how do I get the Real client IP (trusted proxy)? is applied first.
| Your situation | Suitable method |
|---|---|
| Path-based (or domain-name-based) restriction, 403 for the unauthorized | Method 1: Block + Path + negative Source IP |
| A long or frequently changing address list | Method 2: Dynamic list |
| Showing a branded page to the blocked user | Method 3: Show content |
| Sending the blocked user to an information page | Method 4: Location redirection |
| A management service published with L7 TCP (RDP, SSH) | Method 5: TCP Connection Management |
| From the command line | Method 6: WEB-CLI |
Method 1: Block + Path + Negative Source IP Recommended
- How it works If the path condition is met and the request does not come from the allowed addresses, the request is blocked with 403 without going to the Backend Service.
- Where it is openedLoad Balancer → Conditions · Load Balancer → Actions → Block
- Requirement Source IP sees the real client address (Trusted proxy when behind a proxy)
- vService type HTTP
Step-by-Step Configuration
Load Balancer → Conditions → Add is clicked (how to add).
Criteria = Path, matching Regex, value ^/+admin(/.*)?$, Case Insensitive checked (admin panel scenario). The result of the pattern:
| Path | Does it match? |
|---|---|
/admin, /admin/, /admin/login, /ADMIN/login, //admin/ | Yes |
/administrator, /adminx/, /static/admin/x | No |
If the panel is on a separate domain name (e.g. admin.example.com), the HTTP Header condition is used instead of the path: Header name = Request Host, Exact match, Case insensitive, value admin.example.com. If the panel is on its own vService, the path condition is not needed.
Add is clicked.
Load Balancer → Conditions → Add is clicked.
Criteria = Source IP, Source IP Type = Manual. Addresses and CIDR blocks are written separated by a space or a line break; a comment is written only at the beginning of the line with #:
# Office
198.51.100.0/24
# VPN exit
198.51.100.77Add is clicked.
Load Balancer → Actions → Add is clicked (how to add).
Action Name is entered, and Action Type = Block is selected.
- Execution Level = On request (default).
- Deny Type = Standard (default); the other options are Tarpit and Silent drop.
- Status Code = 403 (default); 404 to hide the existence of the path.
- Conditions: the path condition (
admin-yolu) and the!-prefixed negated form of the allowed address condition (!ofis) are added to the same group, and the operator between them is left as and (Can I use a condition in negated form ("if not")?). - If Hit Counter is turned on, the blocked requests are counted.
Add is clicked.
On the Load Balancer → Load Balancer vService List screen, the HTTP vService is selected and Edit is clicked.
Save is clicked. The change is applied without dropping open connections; in a cluster, it is also sent to the peer device with the default auto-sync (if Manual Sync Mode is on, with Synchronize).
Verification
From outside the office network, curl -sI https://www.example.com/admin/ and curl -sI --path-as-is https://www.example.com//ADMIN/
403 ForbiddenThe same request is sent from the office network; the status codes of the two requests are compared on the HTTP Logs screen.
200 from the office · 403 from outsideMethod 2: Dynamic List (IP/cidr match)
- How it works The allowed addresses are kept in a long list; the negated form of the list is combined with the path condition.
- Where it is openedLoad Balancer → Conditions → Dynamic List
- Requirement The path condition in Method 1
- vService type HTTP
Step-by-Step Configuration
Load Balancer → Conditions → Add is clicked.
Criteria = Dynamic List; Key to Search is left at the default client IP variable; Search Method = IP/cidr match; the allowed addresses and blocks are written in the List field.
Add is clicked.
Load Balancer → Actions → Add is clicked.
Action Name is entered, and Action Type = Block is selected; it is filled in as in step 8 of Method 1, and instead of the allowed address condition, the !-prefixed negated form of this list is selected.
Add is clicked.
On the Load Balancer → Load Balancer vService List screen, the HTTP vService is selected and Edit is clicked.
The action is selected in the Details → Actions field.
Save is clicked.
Verification
From an address that is not in the list and from one that is in the list, curl -sI https://www.example.com/admin/
Not in the list 403 · in the list 200Method 3: Block Page with Show Content
- How it works A branded access block page is shown to the blocked requests with the 403 code.
- Where it is openedLoad Balancer → Actions → Show Content
- Requirement The two conditions in Method 1; the block page in Content Pages or the built-in Access Denied Page
- vService type HTTP
Step-by-Step Configuration
Load Balancer → Actions → Add is clicked.
Action Name is entered, and Action Type = Show content is selected. Execution Level = On request; Content Page = Access Denied Page (Turkish) or a custom page (What is the Content Pages profile; how do I prepare my own HTML page?); Status Code = 403 (default 200); Conditions are set up as in Method 1.
Add is clicked.
On the Load Balancer → Load Balancer vService List screen, the HTTP vService is selected and Edit is clicked.
The action is selected in the Details → Actions field.
Save is clicked.
Verification
From outside the office network, curl -i https://www.example.com/admin/
HTTP/1.1 403 + block pageMethod 4: Location Redirection
- How it works The blocked requests are redirected to an information page with 302.
- Where it is openedLoad Balancer → Actions → Location Redirection
- Requirement The two conditions in Method 1; the target address outside the management path
- vService type HTTP
Step-by-Step Configuration
Load Balancer → Actions → Add is clicked.
Action Name is entered, and Action Type = Location Redirection is selected. Redirect Code = 302: Found (Moved Temporarily); Redirect Location = /erisim-bilgisi; Conditions are set up as in Method 1.
Add is clicked.
On the Load Balancer → Load Balancer vService List screen, the HTTP vService is selected and Edit is clicked.
The action is selected in the Details → Actions field.
Save is clicked.
Verification
From outside the office network, curl -sI https://www.example.com/admin/
302 + Location: /erisim-bilgisiMethod 5: L7 TCP Services: TCP Connection Management
- How it works On management services published with an L7 TCP vService, such as RDP or SSH, the connections that do not come from the allowed addresses are closed.
- Where it is openedLoad Balancer → Actions → TCP Connection Management
- Requirement The allowed address condition in Method 1
- vService type L7 TCP
Step-by-Step Configuration
Load Balancer → Actions → Add is clicked.
Action Name is entered, and Action Type = TCP Connection Management is selected. Execution level = On request (default); Action = Reject (default); in the Conditions field, the negated form of the allowed address condition (!ofis) is selected (Is it possible to reject or silently drop a connection at the TCP level (TCP Connection Management)?).
Add is clicked.
On the Load Balancer → Load Balancer vService List screen, the L7 TCP vService is selected and Edit is clicked.
The action is selected in the Details → Actions field.
Save is clicked.
Verification
A connection to the service is made from outside the office network (e.g. an RDP client).
The connection is closed by TR7Method 6: WEB-CLI
- How it works The two conditions in Method 1, the Block action and the vService binding are created with WEB-CLI commands.
- Where it is opened TR7 WEB-CLI →
lb condition·lb action·lb service - Requirement WEB-CLI access; the identifiers (IDs) of the two conditions
- vService type HTTP
Step-by-Step Configuration
Since the pattern does not contain |, it can be written on the command line:
lb condition add criteria path query "^/+admin(/.*)?$" --content_placement regex --caseInsensitive true --name admin-yoluThe addresses are separated by spaces:
lb condition add criteria src_ip srcIpType manual src "198.51.100.0/24 198.51.100.77" --name ofisThe action binds the conditions by their IDs, not by their names; lb condition add produces no output when it succeeds; the IDs are seen in the id column of the lb condition list output.
In the condition expression, ! indicates the negated form and and indicates combination; the expression is written in double quotes. If Deny type and Status code are not written, Standard and 403 are used:
lb action add type deny name admin-kilidi --cond "<path-id> and !<office-id>"lb service show <vService>--rules.N replaces the action at that position; the new action is written to the first empty position.
If the vService has two actions (0 and 1), the new action is written to position 2; if it has no actions, --rules.0 is used:
lb service update id <vService> --rules.2 admin-kilidiVerification
From outside the office network, curl -sI https://www.example.com/admin/
403 ForbiddenCommon Mistakes
While the allowed address list is empty, its negated form blocks everyone
If the Source IP → Manual list is left empty or consists only of comment lines starting with #, the condition does not match any client; in this case, its negated form (!ofis) is met for everyone, and the management path is closed from the office as well.
- Not defining Trusted proxy while TR7 is behind a CDN or proxy. The Source IP condition sees the address of the proxy; either everyone is allowed or everyone is blocked. First, the real client IP is resolved (There is a CDN such as Cloudflare / Akamai in front of TR7; how do I get the Real client IP (trusted proxy)?).
- Using Exact match.
/admin/with Exact match misses the/admin/loginrequest; Regex or Start is used. - Not taking the different spellings of the path into account. The Path condition evaluates the path as it was sent in the request; Case insensitive is needed for
/ADMIN/, and^/+in the pattern for//admin/. A Start/admin/condition does not catch these two spellings. - Writing the comment next to the address. A comment is written only at the beginning of the line with
#; an inline comment such as198.51.100.0/24 # ofiscauses the subsequent addresses in the list not to be taken into account. - Testing the rule from one direction only. Tests are made from both an allowed and an unauthorized address; the internet egress address (NAT) of the office must be in the list.
How it is done in the documentation
Related questions
- Can I use a condition in negated form ("if not")?
- There is a CDN such as Cloudflare / Akamai in front of TR7; how do I get the Real client IP (trusted proxy)?
- Can I return content directly for certain requests without going to the backend (Show Content)?
- Is it possible to reject or silently drop a connection at the TCP level (TCP Connection Management)?
