Skip to content

Commit 216be37

Browse files
committed
cloud: Fix forward_auth to use handle_response for unauthorized redirect
- Use handle_response inside forward_auth instead of handle_errors - Remove redundant /rest/rpc/auth_gate route (handled by /rest/*) - Remove redundant (error_handlers) snippet from site blocks
1 parent d5096ad commit 216be37

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

cloud/Caddyfile.example

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@
5353
handle /pgadmin* {
5454
forward_auth localhost:{args[0]} {
5555
uri /rpc/auth_gate
56-
copy_headers Cookie
56+
57+
# Handle unauthorized - redirect to login
58+
@unauthorized status 401
59+
handle_response @unauthorized {
60+
redir /?login=required&redirect={uri} 302
61+
}
5762
}
5863
reverse_proxy localhost:{$PGADMIN_PORT:5050} {
5964
header_up Host {host}
@@ -73,26 +78,12 @@
7378
reverse_proxy localhost:{args[1]}
7479
}
7580

76-
# Auth gate endpoint (for pgAdmin forward_auth)
77-
handle /rest/rpc/auth_gate {
78-
reverse_proxy localhost:{args[1]}
79-
}
80-
8181
# Next.js application (catch-all)
8282
handle {
8383
reverse_proxy localhost:{args[0]}
8484
}
8585
}
8686

87-
(error_handlers) {
88-
handle_errors {
89-
@unauthorized expression {http.error.status_code} == 401
90-
handle @unauthorized {
91-
redir /?login=required&redirect={uri} 302
92-
}
93-
}
94-
}
95-
9687
# =============================================================================
9788
# TENANT SITE BLOCKS
9889
# =============================================================================
@@ -101,21 +92,18 @@
10192
ma.statbus.org {
10293
import pgadmin_route 3023
10394
import tenant_routes 3022 3023
104-
import error_handlers
10595
}
10696

10797
# Norway tenant (slot offset 3: ports 3030-3035)
10898
no.statbus.org {
10999
import pgadmin_route 3033
110100
import tenant_routes 3032 3033
111-
import error_handlers
112101
}
113102

114103
# Albania tenant (slot offset 4: ports 3040-3045)
115104
al.statbus.org {
116105
import pgadmin_route 3043
117106
import tenant_routes 3042 3043
118-
import error_handlers
119107
}
120108

121109
# =============================================================================

cloud/caddy-pgadmin.snippet

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@
3939
# The {args[0]} placeholder receives the tenant's REST port
4040
forward_auth localhost:{args[0]} {
4141
uri /rpc/auth_gate
42-
# Copy cookies for JWT authentication
43-
copy_headers Cookie
42+
43+
# Handle unauthorized - redirect to login
44+
@unauthorized status 401
45+
handle_response @unauthorized {
46+
redir /?login=required&redirect={uri} 302
47+
}
4448
}
4549

4650
# If authenticated, proxy to shared pgAdmin
@@ -52,14 +56,6 @@
5256
header_up X-Forwarded-Host {host}
5357
}
5458
}
55-
56-
# Redirect unauthenticated users to login page
57-
handle_errors {
58-
@unauthorized expression {http.error.status_code} == 401
59-
handle @unauthorized {
60-
redir /?login=required&redirect=/pgadmin 302
61-
}
62-
}
6359
}
6460

6561
# Example tenant site blocks (customize for your deployment)

0 commit comments

Comments
 (0)