Edgewall Software
Modify

Opened 16 years ago

Closed 15 years ago

#208 closed enhancement (fixed)

Authenticate against /login

Reported by: doug.patterson@… Owned by: osimons
Priority: major Milestone: 0.6
Component: Build slave Version: dev
Keywords: auth login Cc: jhampton
Operating System: Linux

Description

This patch authenticates against /login and stores the resulting session cookie, i.e. normal Trac authentication. cookielib requires Python 2.4

Attachments (13)

auth.patch (1.5 KB) - added by doug.patterson@… 16 years ago.
Patch bitten-slave to authenticate against /login
slave.py (15.7 KB) - added by anonymous 16 years ago.
auth.2.patch (1.6 KB) - added by mike@… 16 years ago.
Replace /build with /login
auth.3.patch (1.6 KB) - added by mike@… 16 years ago.
Updated patch for bitten-slave to authenticate against /login
t208-authenticate-r641.diff (1021 bytes) - added by osimons 15 years ago.
Answer to /login/builds as well.
t208-authenticate2-r641.diff (1.9 KB) - added by osimons 15 years ago.
Also returnes correct urls for pointing to build id's…
t208-authenticate-r647.diff (1.8 KB) - added by osimons 15 years ago.
Authentication patch updated to apply cleanly on top of r647.
bitten-208-auth-with-cookies-r653.patch (3.2 KB) - added by ebray 15 years ago.
This patch implements a slightly different authentication solution that addresses the issues brought up in comment:11:ticket:208. I wouldn't necessarily recommend that this be used as is, but it is what "works for me" so to speak.
t208-ebray-auth_with_cookies_r657.diff (3.1 KB) - added by osimons 15 years ago.
Updated ebray's patch.
t208-authenticate-cookie-form.r657.patch (2.2 KB) - added by ludovic <ludovic.mercier@…> 15 years ago.
patch for http-form login
t208-authenticate-cookie-form.r657.2.patch (4.6 KB) - added by ludovic <ludovic.mercier@…> 15 years ago.
t208_jhampton_auth_with_cookies.patch (8.2 KB) - added by jhampton 15 years ago.
Super Magic Auth Support
t208_osimons_auth_and_cookies-r716.diff (6.9 KB) - added by osimons 15 years ago.
Updated the 'magic auth' patch - fix some errors and reworked some parts of it. Untested with form auth…

Download all attachments as: .zip

Change History (41)

Changed 16 years ago by doug.patterson@…

Patch bitten-slave to authenticate against /login

comment:1 Changed 16 years ago by doug.patterson

Maybe the GET to /login should be conditional (e.g. if username and password:) to prevent problems on a Trac where login is not required. I don't have this setup to test against, so will leave this decision.

Changed 16 years ago by anonymous

comment:2 Changed 16 years ago by thomas_mueller_ffb

suggestion: add command line parameter to pass login url like: --logon-url=/login

comment:3 Changed 16 years ago by mike@…

Any reason this can't be merged? It's really unintuitive that bitten, by default, can't authenticate against Trac, despite having a username and password.

Changed 16 years ago by mike@…

Replace /build with /login

comment:4 Changed 16 years ago by anonymous

Added auth.2.patch which seems to work against the latest version.

Changed 16 years ago by mike@…

Updated patch for bitten-slave to authenticate against /login

comment:5 Changed 16 years ago by mike@…

  • Operating System Windows deleted

Whoops, auth.2.patch was an old version...

auth.3.patch works.

Changed 15 years ago by osimons

Answer to /login/builds as well.

comment:6 Changed 15 years ago by osimons

I've made attachment:t208-authenticate-r641.diff as an alternative, and one that follows how some other Trac plugins enforce authentication. http://trac-hacks.org/wiki/XmlRpcPlugin is an example of this.

comment:7 Changed 15 years ago by osimons

  • Cc osimons added

#354 closed as duplicate.

comment:8 Changed 15 years ago by osimons

First attempt was a bit premature and just worked for polling. The second improved patch (attachment:t208-authenticate2-r641.diff) also returns adjusted paths to build id's for use by slaves, and a full build cycle using -u and -p options now works for me (tested using digest auth).

Anyone want to test the patch?

Changed 15 years ago by osimons

Also returnes correct urls for pointing to build id's…

comment:9 Changed 15 years ago by osimons

  • Owner changed from cmlenz to osimons

Could anyone please help test this patch and/or provide feedback? As it changes the primary URL for the build service when using auth, I'd like to hear what people think before committing.

Changed 15 years ago by osimons

Authentication patch updated to apply cleanly on top of r647.

comment:10 Changed 15 years ago by osimons

With Trac 0.11 still supporting Python 2.3, I'd hesitate to use cookielib. Also, due to the digest timeout problem in #330, a new opener is now made for every request anyway so cookies won't be persisted anyway.

comment:11 follow-up: Changed 15 years ago by ebray

The latest patch is very similar to something I came up with when I was struggling with this issue a few months ago (in fact, I had probably seen this ticket and worked off of it but I don't remember).

In most cases it worked, but for some large builds we started running into strange problems. After much debugging I discovered this issue in httplib: http://bugs.python.org/issue5542

Long story somewhat shorter, when the Bitten slave would send a POST request without auth headers, the web server would immediately send a 401 response and close the connection as soon as it finished receiving the headers. But httplib is overeager, so before it even realizes "aha, a 401 response" it keeps trying to send the request body and fails with a 'broken pipe' error.

In many cases this didn't happen, because the request body was short enough that it would finish sending before the server closed the connection. But in larger POSTS (on the order of 32kb in this case) this would happen.

So my solution, anyways, was for the Bitten slave to send an empty GET to /login/builds before doing anything else, and have /login/builds respond to the request by calling trac.web.auth.LoginModule._do_login() and then send an empty response (along with the trac_auth cookie). Bitten slave stores the cookie in a CookieJar and then make all remaining requests to /builds.

I will post an updated patch that incorporates the relevant changes.

Changed 15 years ago by ebray

This patch implements a slightly different authentication solution that addresses the issues brought up in comment:11:ticket:208. I wouldn't necessarily recommend that this be used as is, but it is what "works for me" so to speak.

comment:12 in reply to: ↑ 11 ; follow-up: Changed 15 years ago by cmlenz

Replying to ebray:

So my solution, anyways, was for the Bitten slave to send an empty GET to /login/builds before doing anything else, and have /login/builds respond to the request by calling trac.web.auth.LoginModule._do_login() and then send an empty response (along with the trac_auth cookie). Bitten slave stores the cookie in a CookieJar and then make all remaining requests to /builds.

Sounds like a good idea, except that I'd suggest using a HEAD request here.

comment:13 in reply to: ↑ 12 Changed 15 years ago by ebray

Replying to cmlenz:

Sounds like a good idea, except that I'd suggest using a HEAD request here.

You're right, that would make more sense.

Changed 15 years ago by osimons

Updated ebray's patch.

comment:14 follow-up: Changed 15 years ago by osimons

I've updated the patch to use HEAD and also fixed a wrong import for LoginModule.

I don't like the look of that Python bug either. However, I still also have some concerns about this way of doing it:

  • Slave requires Python 2.4 (up from 2.3)
  • Each POST on my slave is preceeded by a HEAD to login. Does the cookie not get stored and reused correctly? Shouldn't once be enough?
  • What if an alternative login method is used for Trac? Does this work for Account Manager for instance as-is? It disables the Trac login module, so having Trac LoginModule provide cookies may not be what is accepted by the alternative implementation?

comment:15 follow-up: Changed 15 years ago by osimons

BTW, ebray: What frontend/auth mechanism where you using when experiencing the problems you described? A regular Apache digest/basic auth, or? I can't find any issue in Trac-related projects related to 'Broken Pipe' behaviour with regards to auth (just fcgi), so that suggests Apache and does not behave in a way that is problematic for httplib2?

comment:16 in reply to: ↑ 14 ; follow-up: Changed 15 years ago by ebray

Replying to osimons:

  • Each POST on my slave is preceeded by a HEAD to login. Does the cookie not get stored and reused correctly? Shouldn't once be enough?

That's odd...I admit that the patch I submitted is not exactly the same was what I have in production. I updated it to work with the latest in Bitten's trunk, whereas what I have in production is a slightly older version of Bitten. I don't have this issue--it should store the cookie and it should only do the head request once.

  • What if an alternative login method is used for Trac? Does this work for Account Manager for instance as-is? It disables the Trac login module, so having Trac LoginModule provide cookies may not be what is accepted by the alternative implementation?

I do use Account Manager's form-based login. This assumes that the HttpAuthPlugin is in use and configured for /login/builds. Should have mentioned that in the first place.

comment:17 in reply to: ↑ 15 Changed 15 years ago by ebray

Replying to osimons:

BTW, ebray: What frontend/auth mechanism where you using when experiencing the problems you described? A regular Apache digest/basic auth, or? I can't find any issue in Trac-related projects related to 'Broken Pipe' behaviour with regards to auth (just fcgi), so that suggests Apache and does not behave in a way that is problematic for httplib2?

Using mod_python and as I said in my last comment, the Bitten slave is authenticating with Trac through the HttpAuthPlugin.

comment:18 in reply to: ↑ 16 Changed 15 years ago by osimons

Replying to ebray:

Replying to osimons:

  • Each POST on my slave is preceeded by a HEAD to login. Does the cookie not get stored and reused correctly? Shouldn't once be enough?

That's odd...

Chaning one line seems to do the trick - check if cookies have been received already:

if self.username and not self.cookiejar._cookies:

comment:19 follow-up: Changed 15 years ago by osimons

Full updated change for the relevant part:

  • bitten/slave.py

    a b  
    179184            url = urls.pop(0)
    180185            try:
    181186                try:
     187                    if self.username and not self.cookiejar._cookies:
     188                        log.debug('Performing authentication')
     189                        self.request('HEAD', url[:-7] + '/login/builds')
     190                    elif self.cookiejar._cookies:
     191                        log.debug('Reusing authentication cookie.')
     192                    else:
     193                        log.debug('Authentication not provided. Attempting to '
     194                                  'execute build anonymously.')
    182195                    job_done = self._create_build(url)
    183196                    if job_done:
    184197                        continue

One major question remains - is this worth making Python 2.4 a requirement? Hopefully cmlenz and others can weigh in on that question - I'm too fresh and don't have a real sense of the history and usage of Bitten. However, I don't think there are many setups now without at least 2.4 being available so personally I'm fine with moving on from 2.3.

comment:20 in reply to: ↑ 19 Changed 15 years ago by ebray

Replying to osimons:

Full updated change for the relevant part: ...

Problem with that, is that if a user has passed the slave URLs to multiple Tracs that have separate authentication, that check for self.cookiejar._cookies will be a problem. Instead it needs to iterate through the cookiejar for a trac_auth cookie associated with the URL.

One major question remains - is this worth making Python 2.4 a requirement? Hopefully cmlenz and others can weigh in on that question - I'm too fresh and don't have a real sense of the history and usage of Bitten. However, I don't think there are many setups now without at least 2.4 being available so personally I'm fine with moving on from 2.3.

Given that Trac now requires 2.4, and that Bitten trunk is meant for Trac 0.11, I don't imagine it'd be a problem.

comment:21 follow-up: Changed 15 years ago by osimons

You're right, ebray. It needs to handle multiple urls of course. I'll fix.

Trac 0.11 requires Python 2.3 - it is Trac trunk (0.12) that will require 2.4.

comment:22 Changed 15 years ago by ludovic <ludovic.mercier@…>

  • Operating System set to Linux

Hi,

i have Trac 0.11.4 and last Bitten trunk version. And bitten work with anonymous user. But bitten does'nt work with authenticate user. I have trying : "ebray patch" http://bitten.edgewall.org/attachment/ticket/208/t208-ebray-auth_with_cookies_r657.diff and this not work. I have trying http://bitten.edgewall.org/attachment/ticket/208/t208-authenticate-r647.diff and it's not work also. I use the plugin Trac Account Manager?-0.2.1dev_r5837-py2.4.egg, python2.4 and the trac.ini conf :

[account-manager]
account_changes_notify_addresses =
force_passwd_change = False
generated_password_length = 8
hash_method = HtDigestHashMethod
notify_actions = []
password_store = SessionStore

I use mod_python and sessionStore option for stored password information in the trac database. what is the good way (what is the good patch) to use bitten with an authentified user ??

In two case i have slave logs :

[WARNING ] Server returned error 403: Forbidden
[ERROR   ] HTTP Error 403: Forbidden

comment:23 in reply to: ↑ 21 Changed 15 years ago by ebray

Replying to osimons:

You're right, ebray. It needs to handle multiple urls of course. I'll fix.

Trac 0.11 requires Python 2.3 - it is Trac trunk (0.12) that will require 2.4.

Oops, you're right. Since I moved to Python 2.5 I've barely thought about 2.4, not to mention 2.3.

We don't necessarily need to use cookielib. Could use a cookie handling implementation like Trac's. It was just the quickest and easiest implementation for me.

Changed 15 years ago by ludovic <ludovic.mercier@…>

patch for http-form login

comment:24 Changed 15 years ago by ludovic <ludovic.mercier@…>

Hi,

i have uploaded a patch, that work with : python2.4 Trac 0.11.4 Trac Account Manager? 0.2.1dev-r5837 Bitten 0.6dev-r657 this patch use cookie and a first POST request to get TOKEN_FORM value from Trac Account Maanger?. After Bitten is logged via an HTML form instead of using HTTP authentication. This patch only modify the slave.py file.

Changed 15 years ago by ludovic <ludovic.mercier@…>

comment:25 Changed 15 years ago by ludovic <ludovic.mercier@…>

Hi,

new patch : t208-authenticate-cookie-form.r657.2.patch with an option --form-auth for enabling login form authentication.

Changed 15 years ago by jhampton

Super Magic Auth Support

comment:26 Changed 15 years ago by jhampton

  • Cc jhampton added

OK, I took both ludovic's and ebray's/osimons' patches and combined them. I fixed an issue when using tracd+account manager+httpauthplugin. I also fixed it such that it will look for a cookie matching the url path that is given.

So far it's working well for me. It still depends on cookielib, so it has the 2.4 dependence. Personally, I'm all for dropping 2.3 support. I sent a message to the mailing list to see what others think.

So, the patch does form based login via /login and HTTP auth based login via /login/builds. One thing that might be added is an override for those login paths. I don't think /login will ever change for form based. However, if one isn't using form based auth, then they probably have HTTP Auth configured on /login. In this case, setting up HTTP Auth on /login/builds is an extra step.

Changed 15 years ago by osimons

Updated the 'magic auth' patch - fix some errors and reworked some parts of it. Untested with form auth...

comment:27 Changed 15 years ago by osimons

I've updated the 'magic' patch to fix some errors and simplify the cookie handling to just keep track of what urls are already authenticated. Also, all the changes are now contained to slave.py file.

Please test - I don't have account-manager, so that part is completely untested by me...

comment:28 Changed 15 years ago by osimons

  • Cc osimons removed
  • Resolution set to fixed
  • Status changed from new to closed

Last patch committed as [722].

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain osimons.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.