F: forward the peer's /api/v1 path and un-ignore the proxied tests
The proxy validated the route without its API prefix and handed the transport "/systemd/units", which a peer answered with 404. Validation still works on the bare route; the transport now gets "/api/v1/systemd/units". Un-ignoring the two acceptance tests (a_plain_peer_serves_its_own_data_through_the_proxy and shutdown_ends_a_proxied_follow) is the check for that fix; the unit tests in api/, mcp/ and the registry script their fakes on the peer's real paths again.
This commit is contained in:
1 parent
2455486205
commit
3ae8e74a1d
5 files changed
+93
-86
No files matched your search
+31
-29
@@ -5,9 +5,9 @@
|
||||
//! become an open proxy. Caller credentials are never copied: the transport
|
||||
//! attaches the peer token itself.
|
||||
//!
|
||||
//! Paths are the route under `/api/v1` (`/systemd/units`). A caller that
|
||||
//! includes the `/api/v1` prefix is accepted and that prefix is stripped, so
|
||||
//! the transport always sees one form.
|
||||
//! Callers may name a route with or without the `/api/v1` prefix; validation
|
||||
//! works on the route alone (`/systemd/units`) and forwards the canonical peer
|
||||
//! path (`/api/v1/systemd/units`), which is what a peer serves.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -230,7 +230,9 @@ fn validate(
|
||||
let query = allow_query(peer, &route, query)?;
|
||||
let sse = accept_sse || route_is_follow(&route, &query);
|
||||
Ok(Validated {
|
||||
path: format!("/{route}"),
|
||||
// The allowlist and the query rules work on the route; the peer only
|
||||
// serves it below its own API prefix.
|
||||
path: format!("/api/v1/{route}"),
|
||||
query,
|
||||
sse,
|
||||
})
|
||||
@@ -478,7 +480,7 @@ mod tests {
|
||||
let calls = fake.calls();
|
||||
assert_eq!(calls.len(), 1);
|
||||
let req = &calls[0].1;
|
||||
assert_eq!(req.path, "/journal/follow");
|
||||
assert_eq!(req.path, "/api/v1/journal/follow");
|
||||
assert_eq!(req.query, vec![("lines".to_owned(), "10".to_owned())]);
|
||||
assert_eq!(req.accept.as_deref(), Some("text/event-stream"));
|
||||
assert_eq!(header_of(req, "x-slinuxm-hop"), Some("1"));
|
||||
@@ -491,7 +493,7 @@ mod tests {
|
||||
async fn maps_rejected_with_peer_name() {
|
||||
let fake = FakeTransport::new();
|
||||
fake.peer("beta")
|
||||
.respond_err("/systemd/units", PeerError::Rejected);
|
||||
.respond_err("/api/v1/systemd/units", PeerError::Rejected);
|
||||
let err = get_with(fake.as_ref(), &peer_cfg(), "/systemd/units", &[])
|
||||
.await
|
||||
.unwrap_err();
|
||||
@@ -532,23 +534,23 @@ mod tests {
|
||||
assert_eq!(
|
||||
forwarded(&fake),
|
||||
vec![
|
||||
"/systemd/units",
|
||||
"/systemd/units/nginx.service",
|
||||
"/systemd/timers",
|
||||
"/journal",
|
||||
"/journal/follow",
|
||||
"/docker/ps",
|
||||
"/docker/containers/web",
|
||||
"/docker/containers/web/logs",
|
||||
"/systemd/units",
|
||||
"/systemd/units/user@100.service",
|
||||
"/systemd/units/-.mount",
|
||||
"/systemd/units/-.slice",
|
||||
"/systemd/units/foo%5Cx2dbar.mount",
|
||||
"/systemd/units/mnt-data%5Cx2dbackup.mount",
|
||||
"/systemd/units/dev-disk-by%5Cx2did.device",
|
||||
"/systemd/units/foo..bar.mount",
|
||||
"/docker/containers/foo..bar",
|
||||
"/api/v1/systemd/units",
|
||||
"/api/v1/systemd/units/nginx.service",
|
||||
"/api/v1/systemd/timers",
|
||||
"/api/v1/journal",
|
||||
"/api/v1/journal/follow",
|
||||
"/api/v1/docker/ps",
|
||||
"/api/v1/docker/containers/web",
|
||||
"/api/v1/docker/containers/web/logs",
|
||||
"/api/v1/systemd/units",
|
||||
"/api/v1/systemd/units/user@100.service",
|
||||
"/api/v1/systemd/units/-.mount",
|
||||
"/api/v1/systemd/units/-.slice",
|
||||
"/api/v1/systemd/units/foo%5Cx2dbar.mount",
|
||||
"/api/v1/systemd/units/mnt-data%5Cx2dbackup.mount",
|
||||
"/api/v1/systemd/units/dev-disk-by%5Cx2did.device",
|
||||
"/api/v1/systemd/units/foo..bar.mount",
|
||||
"/api/v1/docker/containers/foo..bar",
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -568,10 +570,10 @@ mod tests {
|
||||
assert_eq!(
|
||||
forwarded(&fake),
|
||||
vec![
|
||||
"/systemd/units/-.mount",
|
||||
"/systemd/units/foo%5Cx2dbar.mount",
|
||||
"/systemd/units/foo%5Cx2dbar.mount",
|
||||
"/systemd/units/mnt-data%5Cx2dbackup.mount",
|
||||
"/api/v1/systemd/units/-.mount",
|
||||
"/api/v1/systemd/units/foo%5Cx2dbar.mount",
|
||||
"/api/v1/systemd/units/foo%5Cx2dbar.mount",
|
||||
"/api/v1/systemd/units/mnt-data%5Cx2dbackup.mount",
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -632,8 +634,8 @@ mod tests {
|
||||
async fn rejects_traversal_excluded_routes_and_bad_query_without_calling() {
|
||||
let fake = FakeTransport::new();
|
||||
fake.peer("beta")
|
||||
.respond("/systemd/units", 200, "application/json", "{}")
|
||||
.respond("/journal/follow", 200, "application/json", "{}");
|
||||
.respond("/api/v1/systemd/units", 200, "application/json", "{}")
|
||||
.respond("/api/v1/journal/follow", 200, "application/json", "{}");
|
||||
let peer = peer_cfg();
|
||||
let bad_paths = [
|
||||
"/ping",
|
||||
|
||||
Reference in new issue
Block a user