Repository navigation
Expand file tree
/
Copy pathCaddyfile.example
More file actions
146 lines (139 loc) · 7.06 KB
/
Copy pathCaddyfile.example
File metadata and controls
146 lines (139 loc) · 7.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Example of exposing Caddy + AegisGate to the public internet
#
# Architecture: client → https://api.example.com/v1/__gw__/t/8317/... → Caddy → AegisGate:18080 → localhost:8317
#
# Pick the reverse_proxy target to match your deployment:
# - Caddy and the gateway on the same docker compose network: aegisgate:18080 (Docker service-name resolution)
# - Caddy on the host, gateway in Docker: 127.0.0.1:18080 (compose already maps the port)
# - Caddy and the gateway both on the host: 127.0.0.1:18080
# - Caddy on another machine: <gateway-machine-IP>:18080
#
# Key points:
# - flush_interval -1: required, so SSE streams are not buffered
# - response_header_timeout 660s: long inference runs must not time out
# - /__gw__/* returns 403: the admin API is never exposed publicly
# - X-Aegis-Proxy-Token: the Caddy ↔ AegisGate trust credential (optional). Once enabled, the gateway
# accepts non-token /v1/... and /v2/... from Caddy regardless of client IP and routes them to
# AEGIS_UPSTREAM_BASE_URL — i.e. it lifts the internal-only restriction, so guard the key accordingly.
# For container deployments, scripts/caddy-entrypoint.sh reads config/aegis_proxy_token.key from the
# shared config volume and exports it as AEGIS_PROXY_TOKEN before starting Caddy.
# - Give the admin console its own domain pointing straight at the upstream, bypassing the gateway
# - Caddy only does TLS + forwarding; all routing logic lives inside the gateway
#
# Ports 80/443 must be open; Caddy requests the certificate automatically
# Static frontend site (optional, unrelated to the gateway; delete the whole block if unused)
# example.com, www.example.com {
# header {
# X-Content-Type-Options "nosniff"
# X-Frame-Options "SAMEORIGIN"
# Referrer-Policy "strict-origin-when-cross-origin"
# Permissions-Policy "geolocation=(), microphone=(), camera=()"
# -Server
# }
# header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
# root * /srv/www
# file_server
# }
# API: inspected and filtered by AegisGate first, then forwarded upstream by the gateway
# Fill in the reverse_proxy target for your deployment (see the notes at the top of this file)
api.example.com {
header {
X-Content-Type-Options "nosniff"
X-Frame-Options "SAMEORIGIN"
Referrer-Policy "strict-origin-when-cross-origin"
X-XSS-Protection "1; mode=block"
-Server
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
}
# The admin endpoints stay off the public internet, so /__gw__ admin operations cannot be triggered through the proxy
@gw_admin path /__gw__ /__gw__/*
respond @gw_admin "forbidden" 403
# Absorb the static-asset paths scanners probe instead of forwarding them to the gateway (less log noise)
@scanner_probe {
path /assets/* /static/* /js/* /css/* /images/* /img/* /fonts/*
path /robots.txt /favicon.ico /sitemap.xml /.env /wp-login.php /wp-admin/*
path /.git/* /.svn/* /.DS_Store /server-status /server-info
path /phpmyadmin/* /pma/* /admin/* /administrator/* /cgi-bin/*
}
respond @scanner_probe 404
# Allow only the API paths (/v1/, /v2/) through; every other path returns 404
@not_api {
not path /v1/* /v2/*
}
respond @not_api 404
# Use 127.0.0.1:18080 when Caddy runs on the host (see the notes at the top of this file)
# Also set AEGIS_TRUSTED_PROXY_IPS=127.0.0.1 on the gateway so X-Forwarded-For from this
# proxy is trusted. With the default AEGIS_XFF_STRICT_INTERNAL=true, an empty trusted-proxy
# list makes any XFF look like a public client (admin / default /v1 / UI / upstream whitelist).
# Start uvicorn with --no-proxy-headers (aegisgate-local.py and the Dockerfile do): its
# default trusts 127.0.0.1 and would replace this proxy with the client before the gateway
# sees it, so the trusted-proxy entry never matches and loopback-only rejects everything.
reverse_proxy 127.0.0.1:18080 {
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
header_up X-Real-IP {remote_host}
# Caddy ↔ AegisGate trust credential (optional)
# The value comes from config/aegis_proxy_token.key (generated on first start)
# To enable: set the AEGIS_PROXY_TOKEN environment variable for Caddy, then uncomment the line below
# header_up X-Aegis-Proxy-Token {env.AEGIS_PROXY_TOKEN}
flush_interval -1
transport http {
response_header_timeout 660s
read_timeout 660s
write_timeout 660s
}
}
}
# ─── Whole-domain (baseUrl) forwarding ──────────────────────────────────────
#
# The block above routes on the URL path (`/v1/__gw__/t/<token>/...`). If you want clients to
# change only the domain — baseUrl = the gateway domain — enable AEGIS_ENABLE_GATEWAY_FORWARD=true
# and add a rule per host in config/gw_forwards.json (or via the console).
#
# Differences from the token block that matter here:
# - The WHOLE domain is proxied: the upstream's own console, OAuth callbacks and static assets
# come through this domain too, so there is no @not_api 404 filter. Keep /__gw__ and /__ui__
# blocked at the edge as well; the gateway itself refuses /__ui__ on a forward host (403
# forward_console_blocked), so open the console on the gateway's own address.
# - header_up Host {host} is what the gateway routes on; X-Forwarded-Host is what a trusted
# proxy (AEGIS_TRUSTED_PROXY_IPS) is allowed to override it with. Set both.
# - AEGIS_TRUSTED_PROXY_IPS must list this proxy, or every forwarded request looks public.
# - The gateway still answers /metrics, /health, /ready, /robots.txt and /favicon.ico itself,
# shadowing an upstream with the same paths.
#
# *.gw.example.com {
# @gw_admin path /__gw__ /__gw__/* /__ui__ /__ui__/*
# respond @gw_admin "forbidden" 403
#
# reverse_proxy 127.0.0.1:18080 {
# header_up Host {host}
# header_up X-Forwarded-Host {host}
# header_up X-Forwarded-Proto {scheme}
# header_up X-Forwarded-For {remote_host}
# header_up X-Real-IP {remote_host}
# header_up -Forwarded
# flush_interval -1
# transport http {
# response_header_timeout 660s
# read_timeout 660s
# write_timeout 660s
# }
# }
# }
# Upstream admin console (optional): connects straight to the upstream, bypassing the gateway.
# Replace with your real upstream address and port (CLIProxyAPI=8317, Sub2API=8080, AIClient-2-API=3000).
# In production, add an IP allowlist to restrict public access.
# panel.example.com {
# @allowed remote_ip <your-admin-IP>/32
# handle @allowed {
# reverse_proxy localhost:8317 {
# flush_interval -1
# transport http {
# response_header_timeout 660s
# read_timeout 660s
# write_timeout 660s
# }
# }
# }
# respond "forbidden" 403
# }