Hardening Synology Remote Entry: Cloudflare IP Allowlist and AOP
The previous post explained how to route Synology remote access cleanly through Cloudflare’s orange cloud when port 443 is blocked. Cloudflare hides the home public IP; the router exposes a single entry; Synology’s reverse proxy fans traffic out to Photos, Drive, File Station, and the rest.
At that point the layout was already fairly tidy:
- All external access goes through Cloudflare (proxied / orange cloud);
- Cloudflare rewrites the origin HTTPS port from 443 to 2096;
- OpenWrt only opens TCP 2096;
- Synology handles reverse proxy and per-app routing.
But one gap remained.
Even though outsiders cannot see my real public IP, anyone who learns the IP and open port could still bypass Cloudflare and try to hit the NAS directly.
Once the login UI is reachable, attacks become plausible—October’s ransomware wave, plus serious patches Synology pushed recently, made that feel very real. My take: Synology does a fine job keeping me out of trouble; it does less for keeping everyone else out…
So this round goes one step further: normal traffic must still go through Cloudflare, and the origin must be sure the peer is Cloudflare—and the Cloudflare I authorized.
Two independent layers:
- The router only allows Cloudflare’s published IPv4 ranges to hit the public entry.
- Docker NGINX validates Cloudflare’s Authenticated Origin Pull (AOP) client certificate on the path from Cloudflare to origin.
Even with my public IP known, direct access to the NAS front door should fail.
1. Final architecture
The domain layout and Synology reverse-proxy rules stay as before. The new piece is an NGINX entry between OpenWrt and DSM.
End-to-end path:
1Internet browser / apps
2 │
3 ▼
4Cloudflare DNS (orange cloud)
5 │
6 │ User: HTTPS 443
7 ▼
8Cloudflare Origin Rules
9 │
10 │ Origin port rewritten to 2096
11 ▼
12Home public IP
13 │
14 ▼
15OpenWrt router
16 │
17 │ TCP 2096
18 │ Cloudflare IPv4 only
19 ▼
20Synology DS218+
21 │
22 │ Port forward 8443
23 ▼
24Docker NGINX
25 │
26 │ AOP client cert verification
27 │ Reverse proxy when OK
28 ▼
29DSM NGINX (443) <----- LAN browser / apps
30 │
31 ├── Photos
32 ├── Drive
33 ├── File Station
34 ├── Music
35 ├── Jellyfin
36 └── Other internal services
Ports worth separating:
| Port | Role |
|---|---|
| 443 | User-facing HTTPS at Cloudflare |
| 2096 | Cloudflare → home public IP |
| 8443 | OpenWrt → Docker NGINX on Synology host |
| 443 | Docker NGINX → DSM NGINX (internal) |
8443 is only the Docker entry on the NAS—users never type it in the browser.
2. Router: allow only Cloudflare IPs
This is the first gate.
Cloudflare publishes IPv4 and IPv6 ranges. Allow only those at the public entry; drop everything else.
Here I use a Cloudflare IPv4 set in OpenWrt nftables.
Plan:
- Define a
cloudflare4address set; - Import and periodically refresh IPv4-CIDR from Cloudflare’s official list;
- Restrict TCP 2096 DNAT so the source must be in
cloudflare4; - Forward hits to Synology
192.168.X.X:8443.
Core logic:
1TCP 2096
2Source IP ∈ cloudflare4
3 │
4 ▼
5DNAT 192.168.X.X:8443
Example nftables rule:
1tcp dport 2096 ip saddr @cloudflare4 \
2dnat ip to 192.168.X.X:8443
The point is not “open 2096”—it’s only connections whose source is in the Cloudflare IPv4 set match this forward rule.
Then:
- Legitimate orange-cloud hostnames show Cloudflare source IPs and get through;
- Hitting
home-ip:2096from a non-Cloudflare IP does not match; - Forcing the hostname to the home IP via hosts still cannot bypass this.
This answers: who is allowed to touch my public entry.
3. Cloudflare: zone-level AOP
The second gate is AOP—Authenticated Origin Pulls.
By default, when Cloudflare proxies to origin, the origin only sees a Cloudflare network IP.
IP allowlisting proves the TCP peer is on Cloudflare’s network, not that your zone’s authorized client certificate was used—someone else could theoretically scan via Cloudflare’s proxy too (at that point it already feels “secure enough” to me, but AOP closes the gap).
With AOP, Cloudflare presents a client certificate on origin connect; NGINX verifies it with your own CA.
This setup uses zone-level AOP, not global AOP: a dedicated client cert for the igerm.ee zone only, not the shared global cert.
Console path:
1SSL/TLS
2 └── Origin Server
3 └── Authenticated Origin Pulls
4 └── Zone-level AOP
After enabling zone-level AOP, Cloudflare offers the matching client certificate during the origin TLS handshake.
Notes:
- This cert is only between Cloudflare and origin—phones, PCs, and browsers need nothing installed.
- End users only notice if the IP is Cloudflare and the TLS handshake lacks the cert; normal Synology Photos / Files / Drive over orange cloud keep working. DSM admin is different—see Access below.
4. Private CA and client certificate
Rather than repurposing a public web PKI cert for client auth, I stood up a small CA on the Mac with OpenSSL:
1AOP-CA/
2├── root/
3│ ├── rootca.key
4│ └── rootca.crt
5│
6└── client/
7 ├── aop-client.key
8 ├── aop-client.csr
9 └── aop-client.crt
| File | Purpose |
|---|---|
| rootca.key | Root CA private key |
| rootca.crt | Root CA cert—NGINX trusts client certs signed here |
| aop-client.key | Cloudflare client private key |
| aop-client.csr | CSR |
| aop-client.crt | Client cert signed by root CA |
Parameters used:
- Root CA: RSA 4096;
- Client cert: RSA 2048;
- Extended key usage: TLS Web Client Authentication;
- Root CA validity: 10 years;
- Client cert validity: 2 years.
Verify:
1openssl verify \
2 -CAfile root/rootca.crt \
3 -purpose sslclient \
4 client/aop-client.crt
Expect:
1client/aop-client.crt: OK
Upload client cert + private key to Cloudflare’s zone-level AOP certificate list.
Keep rootca.key offline—do not upload to Cloudflare or put it in the NAS Docker tree.
The NAS only needs rootca.crt to verify Cloudflare’s client cert.
5. Docker NGINX in front of DSM
Deploy a dedicated NGINX container on Synology.
Layout:
1/volume1/docker/aop-nginx/
2├── compose.yaml
3├── nginx/
4│ └── conf.d/
5│ └── default.conf
6├── aop/
7│ └── rootca.crt
8├── certs/
9│ ├── fullchain.pem
10│ └── privkey.pem
11└── logs/
rootca.crt—your CA root;fullchain.pem/privkey.pem—site TLS server cert;logs—access and error logs.
Server cert remains the existing *.igerm.ee wildcard.
Two cert roles:
- Server cert—proves the site to browsers and Cloudflare for HTTPS.
- AOP client cert—proves authorized Cloudflare origin pull; verified by NGINX.
They are not interchangeable.
Map host 8443 → container 443:
1ports:
2 - "8443:443/tcp"
OpenWrt forwards to 8443; traffic lands on HTTPS 443 inside the container.
6. NGINX: verify, then proxy to DSM
Core server block:
1server {
2 listen 443 ssl;
3 server_name _;
4
5 ssl_certificate /etc/nginx/certs/fullchain.pem;
6 ssl_certificate_key /etc/nginx/certs/privkey.pem;
7
8 ssl_protocols TLSv1.2 TLSv1.3;
9
10 # Verify Cloudflare client cert with private CA
11 ssl_client_certificate /etc/nginx/aop/rootca.crt;
12
13 # Start with optional; tighten after logs look good
14 ssl_verify_client optional;
15
16 location / {
17 proxy_pass https://172.18.0.1:443;
18
19 proxy_http_version 1.1;
20
21 # Preserve Host for DSM vhost routing
22 proxy_set_header Host $host;
23
24 proxy_set_header X-Real-IP $http_cf_connecting_ip;
25 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
26 proxy_set_header X-Forwarded-Proto https;
27 proxy_set_header CF-Connecting-IP $http_cf_connecting_ip;
28
29 proxy_set_header Upgrade $http_upgrade;
30 proxy_set_header Connection $connection_upgrade;
31
32 proxy_ssl_server_name on;
33 proxy_ssl_name $host;
34 proxy_ssl_verify off;
35
36 proxy_request_buffering off;
37 proxy_buffering off;
38
39 proxy_connect_timeout 60s;
40 proxy_send_timeout 3600s;
41 proxy_read_timeout 3600s;
42 }
43}
AOP knobs
1ssl_client_certificate /etc/nginx/aop/rootca.crt;
2ssl_verify_client optional;
optional requests a client cert but does not hard-fail missing ones yet—watch logs for Cloudflare presenting the right cert, then consider:
1ssl_verify_client on;
You could fold everything into one reverse proxy, but I already had eight vhosts configured—standalone AOP NGINX felt cleaner. DSM’s existing rules stay untouched; this only adds verification in front.
7. Logs: prove AOP actually works
“Site loads” is not enough—check ssl_client_verify.
Custom log format:
1log_format aop '$remote_addr [$time_local] '
2 '"$request" $status '
3 'client_verify=$ssl_client_verify '
4 'client_dn="$ssl_client_s_dn" '
5 'host="$host" '
6 'upstream=$upstream_addr '
7 'upstream_status=$upstream_status';
Fields:
| Field | Meaning |
|---|---|
| client_verify | Client cert verification result |
| client_dn | Client cert subject |
| host | Original Host |
| upstream | DSM upstream |
| upstream_status | DSM HTTP status |
Tail logs:
1sudo tail -n 20 \
2/volume1/docker/aop-nginx/logs/access.log
Live follow:
1sudo tail -f \
2/volume1/docker/aop-nginx/logs/access.log
A good line:
1GET /?... HTTP/1.1" 200
2client_verify=SUCCESS
3client_dn="CN=XXXX.COM AOP Client"
4host="photo.xx.com"
5upstream=xxx.xxx.0.1:443
6upstream_status=200
That confirms:
- Cloudflare presented a client cert;
- NGINX validated it with your CA;
- Host header preserved;
- Request reached DSM;
- HTTP 200 from DSM.
That’s AOP working—not just a toggle in the dashboard.
8. Cloudflare Access for DSM admin
Non-admin apps are largely done here. While I was at it, Synology mailed about updates and I still wanted admin reachable from outside, so I kept Cloudflare Access on the DSM admin hostname XX. XXXX.com: orange cloud plus an identity check before DSM, not “URL secrecy alone.”
Roles:
- Cloudflare Access—who may open the admin page (visitor-facing).
- AOP—whether the Cloudflare origin pull holds your authorized client cert (origin-facing).
- Router Cloudflare IP set—which source IPs may connect to the home entry.
Different layers—not duplicates, not substitutes.
Existing Access on XX. XXXX.com stayed when AOP NGINX went in; Access stays at Cloudflare, not on the NAS. Mobile/desktop/Synology apps still do not install AOP client certs.
Admin path from the internet:
1Visitor opens XX. XXXX.com
2 │
3 ▼
4Cloudflare Access
5 │
6 │ Identity check
7 ▼
8Cloudflare proxy / origin pull
9 │
10 ▼
11OpenWrt: Cloudflare IPv4 only → 2096
12 │
13 ▼
14Docker NGINX: AOP client cert
15 │
16 ▼
17DSM admin (443)
Access applies per application/domain policy—not one login wall for every Synology service. Here only the XX. XXXX.com admin entry keeps Access; other hostnames behave as before.
9. Security outcome
Two independent constraints.
Gate 1: IP allowlist
OpenWrt allows only Cloudflare IPv4 on TCP 2096. Random public IPs cannot open a session to the NAS entry.
Gate 2: AOP client certificate
Even from Cloudflare’s network, Docker NGINX checks for a client cert signed by your CA before proxying to DSM.
| Source | Outcome |
|---|---|
| Normal orange-cloud hostname | Allowed |
| Cloudflare origin pull with valid AOP cert | Pass verification |
| Direct public IP to origin | Blocked at router |
| DNS/hosts bypass to origin IP | Blocked at router |
| Origin connection without authorized client cert | NGINX deny (when on) |
Three layers in practice:
- Cloudflare Access—who may reach specific apps;
- Router IP set—who may connect to the entry;
- NGINX AOP—whether the pull is certificate-authorized.
10. Wrap-up
App layout on Synology is unchanged; no extra public ports per service.
One Docker NGINX entry was added; DSM still does app routing.
Pipeline in short:
- Orange cloud hides origin IP;
- Origin Rules: user 443 → origin 2096;
- Router: Cloudflare IPv4 only on 2096;
- DNAT to NAS Docker NGINX 8443;
- NGINX verifies AOP client cert;
- On success, proxy to DSM 443;
- DSM routes by original hostname.
Early remote-access work focused on reachability. This pass adds: let legitimate traffic in, keep the rest off the porch.
Ports are just doors; what matters is who may knock, and what happens after they do.
Existing Synology services keep working; the public side stays a single Cloudflare-fronted entry with IP allowlist and AOP on the path in.

