You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7e09416
Browse filesBrowse the repository at this point in the historyBrowse files
feat(server)!: sign in through a trusted reverse proxy (#1574)
* feat(server): trusted-proxy sign-in behind a stock reverse proxy
[trusted_proxy] gains username_header (default X-SQB-User), optional
display_name_header and email_header, unknown_users (provision_viewer,
the default, or reject) and proxy_logout_url; identities become optional
pre-bindings. The origin may be plain HTTP, with a start-up warning.
A newcomer gets a principal named by the canonical username, with an id
derived from it, and the installation-wide viewer role; a username that
already names another principal is refused rather than taken over.
Requests from trusted peers may report the browser host in
X-Forwarded-Host, as Apache's mod_proxy does without ProxyPreserveHost.
Each untrusted peer that sends the username header is logged once,
without header values. Change feeds send Cache-Control: no-cache,
no-transform and X-Accel-Buffering: no.
* feat(ui): show the proxy's display name and sign-out link
* docs(server): sign in through a reverse proxy
* fix(server): trusted-proxy writes under any host name, loopback peers by default, case-insensitive name check
- A request from a trusted peer may use any host name the proxy serves;
a write needs the X-SQB-CSRF header, which the UI now always sends,
or the configured Origin. The server still allows no cross-origin
requests, so a cross-site page cannot send the header. Password, OIDC
and untrusted-peer requests keep the exact Host and Origin checks.
- trusted_peers defaults to 127.0.0.1 and ::1 when unset.
- A newcomer whose username matches another principal's name in any
case is refused rather than provisioned, without a schema change.
- Proxy-Authorization, Via, X-Forwarded-Proto, X-Real-IP and any Sec-
header are reserved identity-header names.
* docs(server): reverse-proxy usernames, identity headers, loopback binding and access removal
* test(server): prove only a loopback TCP peer asserts a proxy identity by default
Drive the sign-in routes in process with a chosen socket peer, so the
default `trusted_peers` is checked against real non-loopback IPv4, IPv6
and IPv4-mapped peers, against forwarding headers that claim loopback,
and against a server without `[trusted_proxy]`. State in the server docs
that the default lets any process on the host assert an identity, and
that listing the proxy's own address narrows it.
* refactor(orchestration): group authorization entry points by concern
The trusted-proxy resolver made `authorization/main` hold 21 modules, one
over the container limit. Group them one level deep, as `credentials/main`
already is: `roles` for role definitions, assignments and administrator
grants; `decisions` for per-person, scope and row decisions and the
security audit; `people` for the first administrator, proxy usernames and
each person's access. Only module paths change.
* test(server): prove a non-loopback peer's username header is logged and ignored
Start the server on this machine's routed address with the default
trusted peers and send the username header to it, with a forwarding
header claiming loopback. The server refuses both requests, logs the
peer once and never logs the username. Drop history wording from the
server page.
* fix(server): serve trusted proxy peers only under their own host names
A DNS-rebinding page in a browser on a trusted-peer host reaches the
server under its own host name, and could then send the username and
CSRF headers. Refuse every request from a trusted peer, reads included,
unless its real Host is 127.0.0.1, localhost or [::1] with any port,
the host of `origin`, or a name in the new `allowed_hosts` list, which
only a proxy that keeps the browser's host name needs. X-Forwarded-Host
never counts. A refused Host gets 403 and is logged once with the
setting that allows it. The CSRF rule and the loopback trusted_peers
default are unchanged.
* docs(server): a proxy on another host lists its backend address in allowed_hosts
A stock proxy on another host forwards with its backend address as Host,
which is not a loopback name, so it needs allowed_hosts too. Say so in
the docs and in the refused-Host warning.
"warning: refused a request from trusted proxy peer 127.0.0.1 with Host 'evil.example:8000', which is not a loopback name, the [trusted_proxy] origin's host or in [trusted_proxy] allowed_hosts; if your proxy keeps the browser's host name (ProxyPreserveHost On) or forwards to this server by another name or address, add it to allowed_hosts",
283
+
1,
284
+
)],
285
+
},
286
+
];
287
+
let runtime = tokio::runtime::Builder::new_current_thread()
288
+
.enable_all()
289
+
.build()
290
+
.expect("runtime");
291
+
for test_case in test_cases {
292
+
runtime.block_on(async{
293
+
let directory = tempfile::tempdir().expect("proxy installation");
294
+
std::fs::write(
295
+
directory.path().join("server.toml"),
296
+
test_case.configuration,
297
+
)
298
+
.expect("server configuration");
299
+
letmut control = start_control_in(
300
+
directory,
301
+
&[
302
+
"server",
303
+
"--host",
304
+
"127.0.0.1",
305
+
"--port",
306
+
"0",
307
+
"--no-scheduler",
308
+
"--config",
309
+
"server.toml",
310
+
],
311
+
);
312
+
let url = api_ready(&mut control).await;
313
+
let client = Client::builder()
314
+
.timeout(std::time::Duration::from_secs(5))
315
+
.build()
316
+
.expect("HTTP client");
317
+
letmut statuses = Vec::new();
318
+
for _ in0..2{
319
+
let response = client
320
+
.get(format!("{url}/api/control/bootstrap"))
321
+
.header(header::HOST, test_case.host)
322
+
.header("x-forwarded-host","control.example.com")
323
+
.header("x-example-user", test_case.username)
324
+
.send()
325
+
.await
326
+
.expect("refused proxy request");
327
+
statuses.push(response.status());
328
+
}
329
+
let log = std::fs::read_to_string(&control.stderr).expect("server log");
0 commit comments