Repository navigation
Route only /v3 paths in the router - #16294
HarshitJain09 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the CDAP gateway router path lookup logic to block routing for internal API paths (/v3Internal) and metadata internals paths (/v3/metadata-internals), while explicitly allowing GET requests for tethered peer artifact reads to be routed. It also introduces comprehensive unit tests in RouterPathLookupTest and a new test class RouterServiceLookupInternalApiTest to verify these routing rules across various edge cases (such as different HTTP methods, percent encoding, and dot segments). I have no feedback to provide as there are no review comments.
e31543f to
39a297d
Compare
fbeba42 to
4ab9ad5
Compare
| } | ||
| if (isMetadataInternalsPath(uriParts)) { | ||
| return DONT_ROUTE; | ||
| } |
There was a problem hiding this comment.
Simply return DONT_ROUTE when it is not v3 path or uriParts.length == 0?
There was a problem hiding this comment.
Agreed, an allowlist is simpler and safer. Before switching, I checked what relies on the default route for non-v3 paths:
GET /pinghas to keep working: the CLI calls it on everyconnect(MetaClient.ping()expectsOK.\nfrom app-fabric'sPingHandler),cdap-ui's GraphQLstatusresolver calls it, andStandaloneTester,PingHandlerTestRun, andMetricsReporterHookTestRunhit it through the router.- The two tethering artifact GETs under
/v3Internalstay routed, as before. /and/statusneed no route inRouterPathLookup: the router answers both itself (HttpRequestRouter,HttpStatusRequestHandler) before the path lookup.
The router now forwards only /v3/**, GET /ping and those two GETs. Everything else, including an empty path and /v1 (#16252), gets 404. The router tests whose stub servers used non-v3 paths now use /v3/test/.... Done in 4998cde.
| String method = httpRequest.method().name(); | ||
| AllowedMethod requestMethod = AllowedMethod.valueOf(method); |
There was a problem hiding this comment.
Why is this needed?
This check is already present in RouterPathLookup.getRoutingService(...).
There was a problem hiding this comment.
It's moved, not duplicated. This PR deletes the old metadata-internals branch in getV3RoutingService, and the two method lines used to be at the top. The checks have to run before AllowedMethod.valueOf(method), because it throws for methods like PATCH or HEAD, and the catch block then sends the request to app-fabric without checking the path. I added a comment there so the order is clear.
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
|
|
||
| public class RouterServiceLookupInternalApiTest { |
There was a problem hiding this comment.
Test class name should map with the source class name: RouterServiceLookup -> RouterServiceLookupTest
There was a problem hiding this comment.
Renamed it to RouterServiceLookupTest. I'd picked another name only because #16252 adds a test class with this name; whichever PR merges second will combine them.
4ab9ad5 to
4998cde
Compare
4998cde to
24403f7
Compare
24403f7 to
c002faa
Compare
The router sent every request whose first path segment isn't v3 to app-fabric, which made internal APIs such as /v3Internal and /v1 reachable from outside. CDAP services call those through service discovery, not through the router. The router now forwards only /v3 paths and returns 404 for everything else, including /ping and all /v3Internal paths. / and /status are unchanged, because the router answers them itself before this lookup. The path checks, including the existing /v3/metadata-internals check and a null requestPath guard for opaque URIs, run before the HTTP method is parsed: methods such as PATCH or HEAD skip the rest of the lookup and go straight to app-fabric. Refused paths get 404 instead of a 503 that clients retry. Existing /ping callers and router tests that sent non-v3 paths are updated for /v3-only routing: - MetaClient.ping(), StandaloneTester.waitForStandalone(), MetricsReporterHookTestRun, and PingHandlerTestRun now use /v3/system/services/appfabric/status (and PingHandlerTestRun verifies /ping returns 404 through the router). - Router test stubs that used non-v3 paths now use /v3/test/...
c002faa to
e7b0757
Compare
|



What was wrong
The router forwards every request whose first path segment isn't
v3to app-fabric. That makes internal APIs such as/v3Internal/**and/v1/**reachable through the router, although CDAP services call them through service discovery.What this changes
/v3/**and returns404 Not Foundfor everything else (including/pingand all/v3Internal/**paths), with no non-v3exceptions./and/statusdon't change: the router answers both itself, before this lookup.nullrequestPathguard for opaque URIs and the existing/v3/metadata-internals/{type}block) run before the HTTP method is parsed, because the router sends any method other thanGET,PUT,POSTandDELETE(for examplePATCHorHEAD) to app-fabric without looking at the path.404instead of503, because clients such as the CLI retry a503. A real outage still gets503./pingcallers and tests that went through the router (MetaClient.ping(),StandaloneTester.waitForStandalone(),PingHandlerTestRun,MetricsReporterHookTestRun) now use/v3/system/services/appfabric/status(andPingHandlerTestRunverifies/pingreturns404through the router).v3paths now use/v3/test/..., so they still exercise forwarding.This also covers the router part of #16252 (
/v1). Whichever PR merges second resolves a few small conflicts, and its router test stubs need to stay under/v3.How it was tested
RouterPathLookupTestandRouterServiceLookupTest(47 tests) cover every HTTP method; empty andnullpaths;/pingand/v3Internalartifact paths; encoded, dot-segment, repeated-slash, and opaque URIs; and/v3/metadata-internals/*.NettyRouter, run locally against the 6.11.4 jars:NettyRouterTestBase(HTTP),NettyRouterPipelineTest,NettyRouterPipelineAuthTest,AuditLogTestandConfigBasedRequestBlockingTest(24 tests, 71 total with the unit tests above) pass. They include a test that a non-v3path that the backend serves gets404and never reaches it.checkstyle.xml) verified locally on all modified Java files: 0 errors and 0 new warnings.PingHandlerTestRun,MetricsReporterHookTestRun,MetaClientAvailableTest,ClientTestsSuite,CLIMainTest, etc.) running on GitHub Actions CI.