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

support for reverse proxy HTTP-Header based authentication #98

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

MichaelSp
Copy link

This adds a feature similar to what https://github.com/jenkinsci/reverse-proxy-auth-plugin already implements. I couldn't use that plugin however, because of https://issues.jenkins-ci.org/browse/JENKINS-29330
I turned out to be much simpler to add the reverse-proxy authentication into this plugin than to add the recursive group lookup into the reverse-proxy plugin.

@MichaelSp
Copy link
Author

Might be a good idea to check if x-forwarded-proto is set. What do you think?

@jvz
Copy link
Member

jvz commented Sep 3, 2019

This PR is looking decent. I think you might be better off adding the new constructor parameter in the @DataBoundConstructor as a setter method with @DataBoundSetter to avoid having to break backward compatibility with all the constructors you changed. Otherwise, make sure to not delete any old constructors and instead mark them @Deprecated.

@MichaelSp
Copy link
Author

don't merge, yet. We've found a bug in the token based authentication.

@MichaelSp
Copy link
Author

false alert. I just stumbled across this one: https://jenkins.io/security/advisory/2019-07-17/#SECURITY-626 (new crumbIssuer behaviour)

@MichaelSp MichaelSp requested a review from jvz October 17, 2019 20:04
Copy link
Member

@jvz jvz left a comment

Choose a reason for hiding this comment

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

This generally looks good. I did not test this myself as I do not use AD.

@MichaelSp MichaelSp requested a review from jvz July 11, 2020 09:08
@jvz
Copy link
Member

jvz commented Jul 13, 2020

@Wadeck @jtnord thoughts on this?

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.

@Wadeck @jtnord thoughts on this?

personally I think this is the incorrect place for this. The upstream reverse proxy that is authenticating should be made to do the recursive lookup, or make the reverse proxy auth plugin support it even though it may not be as simple.

AD can already do this with a matching OID (matching rule in chain) and thus could just be a question of the correct configuration.

on the code itself, left a couple of comments

}

private String getUserHeader() {
return activeDirectorySecurityRealm.userFromHttpHeader;
Copy link
Member

Choose a reason for hiding this comment

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

if this is the emtpy string how does HttpServletRequest request perform?

Copy link
Author

Choose a reason for hiding this comment

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

from https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getHeader(java.lang.String)

If the request did not include a header of the specified name, this method returns null.

This case is covered in line 95

Copy link
Member

@jtnord jtnord Jul 13, 2020

Choose a reason for hiding this comment

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

I am not talking about the header not being present - I am talking about userFromHttpHeader = ""
thus what does HttpServletRequest.getHeader("") return?

it is certainly undefined at the javadoc level and would (from memory) be in violation of the HTTP spec - so could an implementation potentially throw an arbitrary RuntimeException here?

Copy link
Author

Choose a reason for hiding this comment

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

The running implementation of HttpServletRequest.getHeader is interchangeable.
I've checked it in jetty-9.4.30.v20200611:

  1. https://github.com/eclipse/jetty.project/blob/jetty-9.4.30.v20200611/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java#L852
  2. https://github.com/eclipse/jetty.project/blob/jetty-9.4.30.v20200611/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java#L270-L279

I don't see the potential for a RuntimeException. Either there is a HTTP-Header that matches "" than it is returned or there is no match. That should yield null. Both cases are handled.

@MichaelSp
Copy link
Author

thanks for your comment @jtnord
I'm not quite sure how to go on from here. Since the mentioned ticket in reverse proxy auth is open since 5 years and 3 days and the last commit happened 3 years ago, it doesn't seem very plausible to be addressed there.

If it's a matter of configuration, would you please nudge me in the right direction?

Did I mention? We're running this patch since almost 1 year live in production on ~120 Jenkins.

@jtnord
Copy link
Member

jtnord commented Jul 13, 2020

I'm not quite sure how to go on from here. Since the mentioned ticket in reverse proxy auth is open since 5 years and 3 days

the ticket could have been open that long because no one was interested enough to implement it there.

and the last commit happened 3 years ago, it doesn't seem very plausible to be addressed there.

stable code :)
pinging @oleg-nenashev as he is the mainainer there (IIUC)

If it's a matter of configuration, would you please nudge me in the right direction?

to retrieve all groups a user is a member of (member:1.2.840.113556.1.4.1941:=cn=myuser,cn=users,DC=foo)

I don;t have my test setup anymore, but usign that you special OID you can the AD server to do the legwork. (if bob is a member of cheese and cheese is a meber of food then the query will return both cheese and food when using the OID

(in other words - don't add recursive code to the RP plugin (was probably a big mistake of mine to do that at all here), but ask it to get all the results from AD.

@oleg-nenashev
Copy link
Member

I am not a maintainer here, sorry.

@jvz
Copy link
Member

jvz commented Jul 13, 2020

@oleg-nenashev he was speaking about https://github.com/jenkinsci/reverse-proxy-auth-plugin which you are a maintainer of

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.

Code looks ok - but I still think this should be done in the reverse-proxy plugin.

did you get anywhere with the filters?
https://github.com/jenkinsci/reverse-proxy-auth-plugin/blob/master/src/main/java/org/jenkinsci/plugins/reverse_proxy_auth/ReverseProxySecurityRealm.java#L214-L218

I think something like (member:1.2.840.113556.1.4.1941:={0}) may work - (I'm not sure how the RP plugin works and what filters you would want to use in the various places).

 * import settings
 * Jenkins.getAuthentication
 * DataBoundSetter and don't mess with the constructors

Signed-off-by: Michael Sprauer <[email protected]>
Signed-off-by: Michael Sprauer <[email protected]>
Signed-off-by: Michael Sprauer <[email protected]>
Signed-off-by: Michael Sprauer <[email protected]>
Signed-off-by: Michael Sprauer <[email protected]>
Signed-off-by: Michael Sprauer <[email protected]>
yaroslavafenkin pushed a commit to yaroslavafenkin/active-directory-plugin that referenced this pull request Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants