Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-39402] Cap the number of group headers printed by AccessDeniedException2 #2727

Conversation

jglick
Copy link
Member

@jglick jglick commented Jan 27, 2017

JENKINS-39402

@reviewbybees

r.createWebClient().login("user").goTo("confgure");
fail("should not have been allowed to access anything");
} catch (FailingHttpStatusCodeException x) {
assertEquals(HttpURLConnection.HTTP_FORBIDDEN, x.getStatusCode());
Copy link
Member Author

Choose a reason for hiding this comment

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

Without fix, fails here with a 500 from Jetty as reported in the field.

}
assertThat("capped at a reasonable number", reportedGroups, Matchers.<List<String>>allOf(
Matchers.<String>hasSize(11), // 10 groups plus final warning
Matchers.<String>hasItem("<991 more>"))); // 1000 + SecurityRealm.AUTHENTICATED_AUTHORITY.getAuthority() - 10
Copy link
Member Author

Choose a reason for hiding this comment

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

order may be arbitrary

Copy link
Member

@daniel-beck daniel-beck left a comment

Choose a reason for hiding this comment

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

Looks good, although I'm not convinced that with the low limit any useful behavior in nontrivial security realms (where this is actually needed) will remain.

@@ -12,6 +12,9 @@
* @author Kohsuke Kawaguchi
*/
public class AccessDeniedException2 extends AccessDeniedException {

private static final int MAX_REPORTED_AUTHORITIES = 10;
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

tbh I'm not sure reporting this is ever useful, given the whoAmI url

@rsandell
Copy link
Member

🐝

@jglick
Copy link
Member Author

jglick commented Jan 30, 2017

any useful behavior in nontrivial security realms

I think this is more a place to start diagnosis. You can always go to /whoAmI etc. to see the gory details. I do not want to print many headers for fear of pushing against limits in haproxy and the like.

@daniel-beck
Copy link
Member

Should this not rather count both headers and individual authority name length as well? I.e. cap individual names at ~50 chars long or something?

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

I agree with @daniel-beck that the limit seems to be too small. In order to avoid negative, the limit should be modifiable via SystemProperties at least

@jglick
Copy link
Member Author

jglick commented Jan 30, 2017

These suggestions are more effort than they are worth. I would rather just delete the functionality altogether.

@@ -38,8 +41,14 @@ public AccessDeniedException2(Throwable t, Authentication authentication, Permis
*/
public void reportAsHeaders(HttpServletResponse rsp) {
rsp.addHeader("X-You-Are-Authenticated-As",authentication.getName());
for (GrantedAuthority auth : authentication.getAuthorities()) {
rsp.addHeader("X-You-Are-In-Group",auth.getAuthority());
GrantedAuthority[] authorities = authentication.getAuthorities();
Copy link
Member

Choose a reason for hiding this comment

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

do we even need to report this given there is a whoAmI which reports this in a much nicer way (and most users won't check the headers, and most scripts can't take any action)

@jtnord
Copy link
Member

jtnord commented Jan 30, 2017

These suggestions are more effort than they are worth. I would rather just delete the functionality altogether.

I do not see a use for this funcationality given there is a whoAmI so +1 to that. but 🐝 as it stands as it fixes the issue

Copy link
Member

@jtnord jtnord left a comment

Choose a reason for hiding this comment

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

Fixes the issue - but not sure it makes sense to leave something capped in the code that you can get from whoAmI with a full list.

… omitting them altogether by default.

Test still reproduces the original issue when flag is set on:
… org.eclipse.jetty.server.HttpChannel$CommitCallback failed
WARNING: Commit failed
java.io.IOException: Response header too large
	at org.eclipse.jetty.http.HttpGenerator.generateResponse(HttpGenerator.java:402)
	at org.eclipse.jetty.server.HttpConnection$SendCallback.process(HttpConnection.java:655)
	at …
	at hudson.security.AccessDeniedHandlerImpl.handle(AccessDeniedHandlerImpl.java:57)
	at …
Caused by: java.nio.BufferOverflowException
	at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:189)
	at java.nio.ByteBuffer.put(ByteBuffer.java:859)
	at org.eclipse.jetty.http.HttpGenerator.putTo(HttpGenerator.java:1087)
	at org.eclipse.jetty.http.HttpGenerator.generateHeaders(HttpGenerator.java:705)
	at org.eclipse.jetty.http.HttpGenerator.generateResponse(HttpGenerator.java:387)
	... 66 more
java.lang.AssertionError: expected:<403> but was:<500>
	at org.junit.Assert.fail(Assert.java:88)
	at org.junit.Assert.failNotEquals(Assert.java:834)
	at org.junit.Assert.assertEquals(Assert.java:645)
	at org.junit.Assert.assertEquals(Assert.java:631)
	at hudson.security.AccessDeniedException2Test.youAreInGroupHeaders(AccessDeniedException2Test.java:56)
@oleg-nenashev
Copy link
Member

I would rather like to see a test demonstrating the correct behavior in both modes than just removal of the test logic for the disabled logic

@jglick
Copy link
Member Author

jglick commented Jan 31, 2017

a test demonstrating the correct behavior in both modes

If it is disabled by default, who cares? There was no test before and patch merely conditionally runs the original code. The test logic in the initial version of the patch was to verify that the more complicated capping logic worked.

@@ -38,8 +43,10 @@ public AccessDeniedException2(Throwable t, Authentication authentication, Permis
*/
public void reportAsHeaders(HttpServletResponse rsp) {
rsp.addHeader("X-You-Are-Authenticated-As",authentication.getName());
for (GrantedAuthority auth : authentication.getAuthorities()) {
rsp.addHeader("X-You-Are-In-Group",auth.getAuthority());
if (REPORT_GROUP_HEADERS) {
Copy link
Member

Choose a reason for hiding this comment

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

If false, I would rather return a message like "Disabled due to JENKINS-39402; use /whoAmI to diagnose groups. Or set the XXX system property to true" within the Header value

Copy link
Member

@jtnord jtnord left a comment

Choose a reason for hiding this comment

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

🐝

@jglick jglick added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Feb 6, 2017
@daniel-beck daniel-beck merged commit f8b26a3 into jenkinsci:master Feb 10, 2017
@jglick jglick deleted the AccessDeniedException2-header-size-JENKINS-39402 branch February 10, 2017 16:09
daniel-beck added a commit that referenced this pull request Feb 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants