Skip to content

Route only /v3 paths in the router - #16294

Open
HarshitJain09 wants to merge 1 commit into
developfrom
router-block-v3internal
Open

HarshitJain09 wants to merge 1 commit into
developfrom
router-block-v3internal

Conversation

@HarshitJain09

@HarshitJain09 HarshitJain09 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What was wrong

The router forwards every request whose first path segment isn't v3 to 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

  • The router forwards only /v3/** and returns 404 Not Found for everything else (including /ping and all /v3Internal/** paths), with no non-v3 exceptions.
  • / and /status don't change: the router answers both itself, before this lookup.
  • The path checks (including a null requestPath guard 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 than GET, PUT, POST and DELETE (for example PATCH or HEAD) to app-fabric without looking at the path.
  • Refused paths get 404 instead of 503, because clients such as the CLI retry a 503. A real outage still gets 503.
  • Existing /ping callers and tests that went through the router (MetaClient.ping(), StandaloneTester.waitForStandalone(), PingHandlerTestRun, MetricsReporterHookTestRun) now use /v3/system/services/appfabric/status (and PingHandlerTestRun verifies /ping returns 404 through the router).
  • Router tests whose stub servers used non-v3 paths 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

  • Unit tests: RouterPathLookupTest and RouterServiceLookupTest (47 tests) cover every HTTP method; empty and null paths; /ping and /v3Internal artifact paths; encoded, dot-segment, repeated-slash, and opaque URIs; and /v3/metadata-internals/*.
  • Router tests through a real NettyRouter, run locally against the 6.11.4 jars: NettyRouterTestBase (HTTP), NettyRouterPipelineTest, NettyRouterPipelineAuthTest, AuditLogTest and ConfigBasedRequestBlockingTest (24 tests, 71 total with the unit tests above) pass. They include a test that a non-v3 path that the backend serves gets 404 and never reaches it.
  • Checkstyle (checkstyle.xml) verified locally on all modified Java files: 0 errors and 0 new warnings.
  • Full multi-module build and client/CLI/standalone tests (PingHandlerTestRun, MetricsReporterHookTestRun, MetaClientAvailableTest, ClientTestsSuite, CLIMainTest, etc.) running on GitHub Actions CI.

@HarshitJain09 HarshitJain09 added the build Triggers github actions build label Nov 13, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@HarshitJain09
HarshitJain09 force-pushed the router-block-v3internal branch from e31543f to 39a297d Compare November 13, 2026 11:21
@HarshitJain09
HarshitJain09 marked this pull request as ready for review November 13, 2026 12:50
@HarshitJain09
HarshitJain09 force-pushed the router-block-v3internal branch 4 times, most recently from fbeba42 to 4ab9ad5 Compare November 17, 2026 03:32
}
if (isMetadataInternalsPath(uriParts)) {
return DONT_ROUTE;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply return DONT_ROUTE when it is not v3 path or uriParts.length == 0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, an allowlist is simpler and safer. Before switching, I checked what relies on the default route for non-v3 paths:

  • GET /ping has to keep working: the CLI calls it on every connect (MetaClient.ping() expects OK.\n from app-fabric's PingHandler), cdap-ui's GraphQL status resolver calls it, and StandaloneTester, PingHandlerTestRun, and MetricsReporterHookTestRun hit it through the router.
  • The two tethering artifact GETs under /v3Internal stay routed, as before.
  • / and /status need no route in RouterPathLookup: 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.

Comment on lines +93 to +94
String method = httpRequest.method().name();
AllowedMethod requestMethod = AllowedMethod.valueOf(method);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

This check is already present in RouterPathLookup.getRoutingService(...).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test class name should map with the source class name: RouterServiceLookup -> RouterServiceLookupTest

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@HarshitJain09
HarshitJain09 force-pushed the router-block-v3internal branch from 4ab9ad5 to 4998cde Compare November 17, 2026 15:11
@HarshitJain09 HarshitJain09 changed the title Do not route the internal /v3Internal API in the router Route only /v3 paths in the router Nov 17, 2026
@HarshitJain09
HarshitJain09 force-pushed the router-block-v3internal branch from 4998cde to 24403f7 Compare November 18, 2026 02:29
@deepika-lalwani123
deepika-lalwani123 removed their request for review November 18, 2026 06:39
@HarshitJain09
HarshitJain09 force-pushed the router-block-v3internal branch from 24403f7 to c002faa Compare November 19, 2026 15:27
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/...
@HarshitJain09
HarshitJain09 force-pushed the router-block-v3internal branch from c002faa to e7b0757 Compare November 19, 2026 16:20
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Triggers github actions build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants