Skip to content

YARN-11941: Follow-up to YARN-11937: Improve the yarn.web-proxy.redirect-flag parameter detection in HTTP requests#8357

Open
roczei wants to merge 1 commit intoapache:trunkfrom
roczei:YARN-11941
Open

YARN-11941: Follow-up to YARN-11937: Improve the yarn.web-proxy.redirect-flag parameter detection in HTTP requests#8357
roczei wants to merge 1 commit intoapache:trunkfrom
roczei:YARN-11941

Conversation

@roczei
Copy link

@roczei roczei commented Mar 19, 2026

Description of PR

Problem Statement

The fix for YARN-11937 introduced a mechanism to handle yarn_knox_proxy=true (yarn.web-proxy.redirect-flag=yarn_knox_proxy) parameter in the HTTP query. However the current implementation might not correctly identify this parameter when it is part of a larger query string containing multiple parameters. For example in the following URL:

...?parameter1=true&parameter2=true&yarn_knox_proxy=true&doAs=user

Currently the logic expects the query string to be exactly yarn_knox_proxy=true, it will fail to recognize the flag when other parameters (like doAs, parameter1, or parameter2) are present.

https://github.com/apache/hadoop/blob/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/ hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxyServlet.java#L555

      String redirectFlagName = conf.get(YarnConfiguration.PROXY_REDIRECT_FLAG, "");
      if (!redirectFlagName.isBlank() && toFetch.getQuery().equals(redirectFlagName + "=true")) {
        ProxyUtils.sendRedirect(req, resp, toFetch.toString());
        return;
      }

Proposed Change:

The parameter detection should be improved to properly parse the query string and identify the yarn_knox_proxy=true
key-value pair regardless of its position or the presence of other parameters.

How was this patch tested?

  • Updated the testRedirectFlagProxyServlet unit test to cover this scenario as well
  • Deployed a cluster with YARN, SPARK, KNOX and checked it there

For code changes:

  • Does the title or this PR starts with the corresponding JIRA issue id (e.g. 'HADOOP-17799. Your PR title ...')?
  • Object storage: have the integration tests been executed and the endpoint declared according to the connector-specific documentation?
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE, LICENSE-binary, NOTICE-binary files?

AI Tooling

If an AI tool was used:

…ect-flag parameter detection in HTTP requests

Problem Statement

The fix for YARN-11937 introduced a mechanism to handle yarn_knox_proxy=true (yarn.web-proxy.redirect-flag=yarn_knox_proxy)
parameter in the HTTP query. However the current implementation might not correctly identify this parameter when
it is part of a larger query string containing multiple parameters. For example in the following URL:

...?parameter1=true&parameter2=true&yarn_knox_proxy=true&doAs=user

Currently the logic expects the query string to be exactly yarn_knox_proxy=true, it will fail to recognize
the flag when other parameters (like doAs, parameter1, or parameter2) are present.

https://github.com/apache/hadoop/blob/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/
hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxyServlet.java#L555

      String redirectFlagName = conf.get(YarnConfiguration.PROXY_REDIRECT_FLAG, "");
      if (!redirectFlagName.isBlank() && toFetch.getQuery().equals(redirectFlagName + "=true")) {
        ProxyUtils.sendRedirect(req, resp, toFetch.toString());
        return;
      }

Proposed Change:

The parameter detection should be improved to properly parse the query string and identify the yarn_knox_proxy=true
 key-value pair regardless of its position or the presence of other parameters.
Copy link
Contributor

@K0K0V0K K0K0V0K left a comment

Choose a reason for hiding this comment

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

Thanks @roczei for fixing this up!
LGTM!

@hadoop-yetus
Copy link

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 38s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ trunk Compile Tests _
+1 💚 mvninstall 47m 29s trunk passed
+1 💚 compile 0m 46s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 compile 0m 46s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 checkstyle 0m 42s trunk passed
+1 💚 mvnsite 0m 49s trunk passed
+1 💚 javadoc 0m 44s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 0m 41s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 1m 7s trunk passed
+1 💚 shadedclient 31m 20s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 0m 22s the patch passed
+1 💚 compile 0m 20s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javac 0m 20s the patch passed
+1 💚 compile 0m 20s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 javac 0m 20s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 0m 18s the patch passed
+1 💚 mvnsite 0m 23s the patch passed
+1 💚 javadoc 0m 21s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 0m 20s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 0m 49s the patch passed
+1 💚 shadedclient 27m 9s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 1m 27s hadoop-yarn-server-web-proxy in the patch passed.
+1 💚 asflicense 0m 35s The patch does not generate ASF License warnings.
120m 50s
Subsystem Report/Notes
Docker ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8357/1/artifact/out/Dockerfile
GITHUB PR #8357
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 9dc290e0cf99 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 154de95
Default Java Ubuntu-17.0.18+8-Ubuntu-124.04.1
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8357/1/testReport/
Max. process+thread count 612 (vs. ulimit of 5500)
modules C: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy U: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8357/1/console
versions git=2.43.0 maven=3.9.11 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

@hadoop-yetus
Copy link

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 1m 0s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ trunk Compile Tests _
+1 💚 mvninstall 49m 53s trunk passed
+1 💚 compile 0m 54s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 compile 0m 48s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 checkstyle 0m 48s trunk passed
+1 💚 mvnsite 0m 56s trunk passed
+1 💚 javadoc 0m 49s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 0m 46s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 1m 7s trunk passed
+1 💚 shadedclient 34m 30s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 0m 21s the patch passed
+1 💚 compile 0m 21s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javac 0m 21s the patch passed
+1 💚 compile 0m 21s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 javac 0m 21s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 0m 17s the patch passed
+1 💚 mvnsite 0m 24s the patch passed
+1 💚 javadoc 0m 20s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 0m 20s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 0m 52s the patch passed
+1 💚 shadedclient 34m 32s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 1m 33s hadoop-yarn-server-web-proxy in the patch passed.
+1 💚 asflicense 0m 41s The patch does not generate ASF License warnings.
134m 44s
Subsystem Report/Notes
Docker ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8357/2/artifact/out/Dockerfile
GITHUB PR #8357
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 03db5d979b26 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 154de95
Default Java Ubuntu-17.0.18+8-Ubuntu-124.04.1
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8357/2/testReport/
Max. process+thread count 572 (vs. ulimit of 5500)
modules C: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy U: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8357/2/console
versions git=2.43.0 maven=3.9.11 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

@roczei
Copy link
Author

roczei commented Mar 20, 2026

Found another bug. The issue isn't just with multiple parameters. If the toFetch.getQuery() doesn't have a path , it throws a java.lang.NullPointerException. I was able to reproduce it with this:

$ git diff
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java
index d59beecd91..92456bcfbc 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java
@@ -373,6 +373,9 @@ void testRedirectFlagProxyServlet() throws IOException, ServletException {
     appReportFetcher.answer = 9;
     servlet.doGet(request, response);
 
+    appReportFetcher.answer = 10;
+    servlet.doGet(request, response);
+
     ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class);
     Mockito.verify(response, Mockito.times(3)).setStatus(statusCaptor.capture());
     assertEquals(HttpServletResponse.SC_OK, statusCaptor.getAllValues().get(0));
@@ -711,6 +714,11 @@ public FetchedAppReport getApplicationReport(ApplicationId appId)
         result.getApplicationReport().setOriginalTrackingUrl("localhost:"
             + originalPort + "/foo/bar?parameter1=true&yarn_knox_proxy=true&doAs=user");
         return result;
+      }  if (answer == 10) {
+        FetchedAppReport result = getDefaultApplicationReport(appId);
+        result.getApplicationReport().setOriginalTrackingUrl("localhost:"
+                + originalPort);
+        return result;
       }
       return null;
     }
$ 
2026-03-20 21:32:20,957 [main] INFO  webproxy.WebAppProxyServlet (WebAppProxyServlet.java:methodAction(519)) - dr.who is accessing unchecked http://localhost:60879 which is the app master GUI of application_00_0 owned by dr.who

java.lang.NullPointerException: Cannot invoke "String.contains(java.lang.CharSequence)" because the return value of "java.net.URI.getQuery()" is null

	at org.apache.hadoop.yarn.server.webproxy.WebAppProxyServlet.methodAction(WebAppProxyServlet.java:556)
	at org.apache.hadoop.yarn.server.webproxy.WebAppProxyServlet.doGet(WebAppProxyServlet.java:375)
	at org.apache.hadoop.yarn.server.webproxy.TestWebAppProxyServlet.testRedirectFlagProxyServlet(TestWebAppProxyServlet.java:377)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

Related line: WebAppProxyServlet.java:556

      if (!redirectFlagName.isBlank() && toFetch.getQuery().contains(redirectFlagName + "=true")) {

I'll fix it in this PR and update the Jira ticket too.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants