Repository navigation
🐛 fix(proxy): forward the original versioned path on the hijack upstream leg - #203
Conversation
…eam leg
writeHijackUpstreamRequest built the outbound attach/exec-start request
from the filter-normalized (version-stripped) path instead of the
client's original path. dockerd tolerates a bare unversioned path, but
real Podman requires the version prefix (/v5.x.y/libpod/...) on every
libpod route but the bare _ping, so a hijacked POST
/libpod/exec/{id}/start proxied through sockguard 404ed against a real
daemon even when policy allowed it. The non-hijack reverse-proxy path
(proxy.go's Rewrite, which only touches Scheme/Host) never had this bug.
- newUpstreamHijackRequest now takes the wire path directly; the
production caller passes r.URL.Path. The normalized path is still
used for endpoint matching (isHijackEndpointNormalized) and logging.
- New internal/proxy/hijack_libpod_test.go regression test
(TestHandleHijack_LibpodExecStartPreservesVersionPrefix) reproduces
the mangle directly; two existing tests that pinned the old
stripped-path behavior (hijack_test.go, internal/cmd/serve_chain_test.go)
are updated to assert the fixed contract.
- New podmanintegration-tagged acceptance test
(TestLibpodExecStartEndToEndHijackAgainstRealPodman) drives a real
create -> exec-create -> exec-start round trip through the hijack
path against a live Podman daemon, closing the gap PR #192 left open.
- Removes the now-resolved "Known Limitations" entry from the Podman
guide and records the fix in CHANGELOG.md.
Fixes #194
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 44 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughHijack forwarding now sends the client’s original URL path, including API version prefixes, to the upstream. Normalized paths remain used for logging and errors. Regression tests cover path, query, host, and fallback behavior. A new integration test runs libpod Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/internal/proxy/hijack.go (1)
479-498: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winPreserve
RawPathfor upstream hijack requests.
writeHijackUpstreamRequestpassesr.URL.Path, butr.URL.Pathis decoded and the new URL has noRawPath. A request like%2Fbecomes/in the emitted request.Set
RawPathwhenpath == r.URL.Path, and add a regression check on the forwarded request target.Proposed fix
func newUpstreamHijackRequest(r *http.Request, path string) *http.Request { rawQuery := "" + rawPath := "" if path == "" && r.URL != nil { path = r.URL.Path } if r.URL != nil { + if path == r.URL.Path { + rawPath = r.URL.RawPath + } rawQuery = r.URL.RawQuery } upstreamReq := &http.Request{ - URL: &url.URL{Scheme: "http", Host: "docker", Path: path, RawQuery: rawQuery}, + URL: &url.URL{Scheme: "http", Host: "docker", Path: path, RawPath: rawPath, RawQuery: rawQuery},🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/internal/proxy/hijack.go` around lines 479 - 498, Update newUpstreamHijackRequest to preserve the original URL encoding by carrying r.URL.RawPath into the constructed upstream URL when the supplied path equals r.URL.Path; otherwise leave RawPath unset. Add a regression check around writeHijackUpstreamRequest that verifies an encoded target such as %2F remains encoded in the forwarded request.
🧹 Nitpick comments (2)
app/integration/podman_libpod_integration_test.go (1)
254-384: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoffUse a table-driven test structure.
Move the fixed scenario into a test-case table and run each case with
t.Run. Keep the real Podman setup and raw TCP hijack assertion inside the subtest.As per coding guidelines, “
**/*_test.go: Write tests as table-driven tests usingtesting.Tandhttptest.”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/integration/podman_libpod_integration_test.go` around lines 254 - 384, Refactor TestLibpodExecStartEndToEndHijackAgainstRealPodman into a table-driven test with a scenario table and t.Run subtests. Move the complete Podman setup, exec-create flow, raw TCP hijack request, and echoed-output assertions inside each subtest, preserving the existing behavior and cleanup.Source: Coding guidelines
app/internal/proxy/hijack_libpod_test.go (1)
154-208: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse a table-driven test.
Convert this regression test to a test-case table. Keep the per-case request target, expected path, and expected query in the table. This makes additional Podman version-path cases local changes.
As per coding guidelines, “Write tests as table-driven tests using
testing.Tandhttptest.”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/internal/proxy/hijack_libpod_test.go` around lines 154 - 208, Convert TestHandleHijack_LibpodExecStartPreservesVersionPrefix into a table-driven test with cases containing the request target, expected forwarded path, and expected query. Run each case with t.Run while preserving the existing hijack setup, status, Host, URL, and raw forwarded-request assertions.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@app/internal/proxy/hijack.go`:
- Around line 479-498: Update newUpstreamHijackRequest to preserve the original
URL encoding by carrying r.URL.RawPath into the constructed upstream URL when
the supplied path equals r.URL.Path; otherwise leave RawPath unset. Add a
regression check around writeHijackUpstreamRequest that verifies an encoded
target such as %2F remains encoded in the forwarded request.
---
Nitpick comments:
In `@app/integration/podman_libpod_integration_test.go`:
- Around line 254-384: Refactor
TestLibpodExecStartEndToEndHijackAgainstRealPodman into a table-driven test with
a scenario table and t.Run subtests. Move the complete Podman setup, exec-create
flow, raw TCP hijack request, and echoed-output assertions inside each subtest,
preserving the existing behavior and cleanup.
In `@app/internal/proxy/hijack_libpod_test.go`:
- Around line 154-208: Convert
TestHandleHijack_LibpodExecStartPreservesVersionPrefix into a table-driven test
with cases containing the request target, expected forwarded path, and expected
query. Run each case with t.Run while preserving the existing hijack setup,
status, Host, URL, and raw forwarded-request assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 8fce1d65-5cd3-47cf-8cfb-ec15be051297
⛔ Files ignored due to path filters (1)
CHANGELOG.mdis excluded by!CHANGELOG.md
📒 Files selected for processing (6)
app/integration/podman_libpod_integration_test.goapp/internal/cmd/serve_chain_test.goapp/internal/proxy/hijack.goapp/internal/proxy/hijack_libpod_test.goapp/internal/proxy/hijack_test.godocs/content/docs/podman.mdx
💤 Files with no reviewable changes (1)
- docs/content/docs/podman.mdx
newUpstreamHijackRequest built the outbound URL from r.URL.Path alone, which is decoded (%2F becomes a literal /). With no RawPath set, a url.URL re-derives EscapedPath() from the decoded Path, so an encoded segment in a hijacked attach/exec-start target would collapse into a different path on the wire than the client actually sent. Now carries r.URL.RawPath into the constructed upstream URL whenever path equals r.URL.Path (the production caller's case); left unset when a caller substitutes a different path, since a stale RawPath wouldn't describe it. New tests: TestNewUpstreamHijackRequest_PreservesRawPathForEncodedSegments and its negative counterpart (unit level), plus TestHandleHijack_PreservesEncodedPathBytesUpstream, which checks the actual forwarded bytes rather than just the parsed URL struct. CodeRabbit review on #203.
Convert TestHandleHijack_LibpodExecStartPreservesVersionPrefix and TestLibpodExecStartEndToEndHijackAgainstRealPodman to table-driven tests per repo coding guidelines (t.Run subtests, case table for what varies), matching the existing convention across the suite. hijack_libpod_test.go gains a two-part Docker-style version prefix case alongside the original three-part Podman semver case, plus a case covering the RawPath/%2F fix from the preceding commit — an encoded exec-ID segment must survive onto the wire unchanged. podman_libpod_integration_test.go's acceptance test now runs the full create -> exec-create -> exec-start round trip for two commands (echo, with a trailing newline; printf, without), proving the hijack frame decoding path for both shapes. Re-verified against a real Podman machine (Podman 6.0.2 client / Libpod 5.8.1 server): both subtests pass. CodeRabbit review on #203.
|
Fixed — newUpstreamHijackRequest now carries r.URL.RawPath into the constructed upstream URL when path == r.URL.Path, so %2F etc. survive onto the wire instead of getting flattened. Added a unit test on the URL struct plus a wire-bytes check on the actual forwarded request. bd2cea9. |
|
Done — hijack_libpod_test.go's TestHandleHijack_LibpodExecStartPreservesVersionPrefix is table-driven now, added a two-part version-prefix case and a %2F-encoding case (ties into the RawPath fix above). 337afb6. |
|
Done — TestLibpodExecStartEndToEndHijackAgainstRealPodman is table-driven now (echo w/ trailing newline + printf w/o), setup/assertions moved inside the subtest. Re-ran it live against a real podman machine, both cases pass. 337afb6. |
Root cause
internal/proxy/hijack.go'swriteHijackUpstreamRequestbuilt the outbound attach/exec-start request from the filter-normalized (version-stripped) path, the same forminternal/filteruses for rule matching, instead of the client's original request path. That's harmless against dockerd (accepts bare unversioned paths), but real Podman requires the version prefix (/v5.x.y/libpod/...) on every libpod route except the bare_ping. A hijackedPOST /libpod/exec/{id}/startproxied through sockguard therefore 404ed against a real Podman daemon even when policy allowed it. The non-hijack reverse-proxy path (proxy.go'sRewrite, which only touchesScheme/Hostand leavesPathuntouched) never had this bug — the hijack path was the sole inconsistency.Fix
newUpstreamHijackRequestnow takes the literal wire path; the production caller (writeHijackUpstreamRequest) passesr.URL.Pathdirectly. The normalized/stripped path is still used for endpoint matching (isHijackEndpointNormalized) and logging — unchanged.Tests
TestHandleHijack_LibpodExecStartPreservesVersionPrefix(app/internal/proxy/hijack_libpod_test.go) reproduces the path mangle directly — confirmed failing before the fix (404), passing after.TestHandleHijack_PreservesOriginalRequestPathUpstream(renamed from...RebuildsUpstreamRequestTargetFromNormalizedPath,hijack_test.go) andTestFullProxyChainHijackIntegration(internal/cmd/serve_chain_test.go).podmanintegration-tagged acceptance test:TestLibpodExecStartEndToEndHijackAgainstRealPodman(app/integration/podman_libpod_integration_test.go) drives a real create → exec-create → exec-start round trip through the hijack path against a live Podman daemon (Podman 6.0.2 client / Libpod 5.8.1 server, verified locally against a realpodman machine) — closing the gap PR 🧪 test(integration): Podman rootful+rootless CI integration for libpod surface (#148) #192 had to leave open, and matching the issue's suggested acceptance criterion. Verified this test fails withstatus = 404against the pre-fix code and passes after.Verification
go test -race -count=1 ./...— all packages pass.go test -tags podmanintegration ./integration/...— full libpod integration suite passes against a real Podman daemon.golangci-lint run— clean.docs/content/docs/podman.mdxremoved.Fixes #194
Changelog
exec-startrequests.Concerns