MantisBT

View Issue Details Jump to Notes ] Wiki ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0012458mantisbtapi soappublic2010-10-18 10:552013-05-14 16:52
Reporterzigo73 
Assigned Torombert 
PrioritynormalSeverityminorReproducibilityalways
StatusassignedResolutionopen 
PlatformOSOS Version
Product Version1.2.3 
Target Version1.3.xFixed in Version 
Summary0012458: Problem with HTTP_AUTH and Web Services
DescriptionMy MantisBT site is authenticated by Apache using mod_auth_kerb over HTTPS with both SPNEGO and BASIC_AUTH enabled.

I have applied the patch described at http://www.eiben.weite-welt.com/2007/04/mantis_iwa/ [^] to enable SPNEGO authentication.

function mci_check_login() is used for every web services method to check authentication, but it expects username and password being provided for each call, which is not the case for authentication managed by Apache.

I have patched the mci_api.php file this way to make it work:


# return user_id if successful, otherwise false.
function mci_check_login( $p_username, $p_password ) {

    # Alberto Zigoni: patch for auth_attempt_script_login to work
    $t_login_method = config_get( 'login_method' );
    if(HTTP_AUTH == $t_login_method) {
        $p_username = auth_prepare_username('');
    }
    if( mci_is_mantis_offline() ) {
        return false;
    }

    # if no user name supplied, then attempt to login as anonymous user.
    if( is_blank( $p_username )) {
        $t_anon_allowed = config_get( 'allow_anonymous_login' );
        if( OFF == $t_anon_allowed ) {
            return false;
        }

        $p_username = config_get( 'anonymous_account' );

        # do not use password validation.
        $p_password = null;
    }

    if( false === auth_attempt_script_login( $p_username, $p_password ) ) {
        return false;
    }

    return auth_get_current_user_id();
}


authentication.api is patched as follows (sso_user_regex is a regex used to strip the '@DOMAIN' suffix from the username in HTTP header):

function auth_prepare_username( $p_username ) {
    switch( config_get( 'login_method' ) ) {
        case BASIC_AUTH:
            $f_username = $_SERVER['REMOTE_USER'];
            break;
        case HTTP_AUTH:
            if( !auth_http_is_logout_pending() ) {
                if (isset($_SERVER['REMOTE_USER'])) { # $_SERVER['AUTH_TYPE'] == 'Negotiate' )
                    preg_match(config_get('sso_user_regex'), $_SERVER['REMOTE_USER'], $user_match);
                    $f_username = $user_match[1];
                }
                if( isset( $_SERVER['PHP_AUTH_USER'] ) ) {
                    $f_username = $_SERVER['PHP_AUTH_USER'];
                }
            } else {
                auth_http_set_logout_pending( false );
                auth_http_prompt();

                /* calls exit */
                return;
            }
            break;
        default:
            $f_username = $p_username;
            break;
    }
    return $f_username;
}
Steps To ReproduceAccess MantisBT via Eclipse 3.6 and mylyn-mantis 3.4.0. (use the latest nightly build, to avoid NullPointerException) and configure task repository to use HTTP Authentication. Patch MantisBT as described above to enable SPNEGO.
Tagspatch
Attached Filespatch file icon http_auth_web_services_mantisbt1.2.3.patch [^] (3,147 bytes) 2010-10-19 06:17 [Show Content]
patch file icon 0001-Enable-MantisBT-to-participate-in-SSO-scenarios.patch [^] (3,691 bytes) 2011-02-07 18:54 [Show Content]

- Relationships
related to 0011084acknowledged Login Dialog keeps popping up when using HTTP_AUTH 

-  Notes
User avatar (0027075)
rombert (developer)
2010-10-18 16:48

Thanks for the patch and for the detailed explanation. Can you provide a git patch as outlined at http://docs.mantisbt.org/master/en/developers.html#DEV.CONTRIB.SUBMIT [^] ?
User avatar (0027083)
zigo73 (reporter)
2010-10-19 06:18

Here is the patch. It is my first time with Git, I hope I have not messed up with it.
User avatar (0027094)
rombert (developer)
2010-10-20 04:47

The patch looks fine so far. Excellent even, given that it's your first git patch :-)

A couple of comments:

1. You don't need the patch start/patch end comments, it's clear from the git history who introduced them.
2. There are some whitespace-only changes, which should be removed..
3. If you can leave the $g_sso_user_regex configuration out, do that. If you think that it must be added, please add it to config_defaults_inc.php and document it in docbook/Admin_Guide/en-US/Customizing.xml .
User avatar (0027103)
rombert (developer)
2010-10-20 17:28

If you require the g_ sso_user_regex parameter, how about making it something which is globally useful, like (.*)(@.* )? Don't know top of my head if that really works but I would like to make it as easy as usable out-of-the-box as possible.
User avatar (0027104)
zigo73 (reporter)
2010-10-20 17:39

Well, the thing is that only in Kerberos based authentication the user takes the form of username@KERBEROS.REALM. When using other kinds of HTTP authentication (like for example using a db) there is no need to strip off the '@REALM' part.

In fact, your regex (.*)(@.*) would not even work in case of non kerberos based HTTP authentication:
- in case of LDAP authentication the username would be something like cn=username,dn=acme,dn=com
- with NTLM you would have DOMAIN\username

This is the reason behind using a regular expression. Anyway, I have only experimented with mod_auth_kerb so far.
User avatar (0027105)
rombert (developer)
2010-10-20 17:57

Thanks for pointing this out. Then I suggest adding a default regexp like (.*) , and suggesting what good values you have for mod_auth_kerb in the default value documentation and in the reference guide . We can add more documentation later, if available.
User avatar (0027713)
zigo73 (reporter)
2010-12-27 05:34

Rombert,

that's fine for me. I am not a PHP developer, I just needed to make things work, so I've done it "quick and dirty".

Let me know if you need more help, I will be glad to help testing this feature in upcoming versions. I think Integrated Windows Authentication is something very interesting to provide as a standard Mantis feature.
User avatar (0027714)
rombert (developer)
2010-12-27 05:44

OK then. Can you please add ( either in the patch, or as an issue comment ) some suggestions regarding the good values for 'sso_user_regex' that you know of?
User avatar (0027730)
zigo73 (reporter)
2010-12-27 10:32

I think that for mod_auth_kerb based authentication, a good regular expression is

'/^(.*)@YOUR\.KERBEROS\.REALM$/i'

To make it simpler, you could define a boolean variable called something like "spnego_strip_off_realm" to decide, in case of SPNEGO authentication, if the realm should be stripped off or not. In this case, you can simply evaluate a substring of the REMOTE_USER env variable.

Anyway, I think the best way to implement this would be as a Mantis plugin.
User avatar (0027733)
rombert (developer)
2010-12-27 10:57

Thanks.

I'm going to focus on getting the patch implemented and documented. We'll see about convenience later.
User avatar (0028194)
rombert (developer)
2011-02-08 17:01

I've added all the core devs here, since this is as far as I can go with my review. I do not know that part of the code well, and will not be able to commit it.

@core devs: I would appreciate if one of you could take it from here, as I've done all I dare for this issue.
User avatar (0028256)
dhx (developer)
2011-02-18 21:28

Agreed with the idea. Just some comments on the patch from 2011-02-07:

* Documentation inside config_inc.php (and anywhere else for that matter) should not contain SGML tags (<tt>, etc) as the documentation in this context is plaintext.

* Documentation of new and updated configuration values needs to be placed in the docbook documentation too.

* Code style for the patch chunk in auth_prepare_username() is not consistent (lack of spacing around parenthesis) with the remainder of the code and the style guidelines for MantisBT.

* Can we change the name of the new configuration option "sso_user_regex" to something more descriptive such as "http_auth_username_extraction_regex"? This will make the code easier to read for people not accustomed to the concept of SSO and how MantisBT handles it.

Otherwise the patch seems OK from what I can see.

I have changed the target version from 1.2.x to 1.3.x as the stable branch should not be seeing new features - that should be reserved for the development branch.

Well done!
User avatar (0033418)
iwan (reporter)
2012-11-03 06:47

Is this issue still alive? I took a look at the nightly build towards 1.3.x, but last night I couldn't see any of the proposed changes in mc_api.php and authentication_api.php

Ofcourse I will adjust my 1.2.x installation using the ziggo73's explanation, tnx! :)
User avatar (0034225)
rombert (developer)
2012-11-04 13:39

I'm going to have a look after the next release.

- Issue History
Date Modified Username Field Change
2010-10-18 10:55 zigo73 New Issue
2010-10-18 16:48 rombert Note Added: 0027075
2010-10-18 16:48 rombert Severity major => minor
2010-10-18 16:48 rombert Status new => feedback
2010-10-18 16:48 rombert Target Version => 1.2.4
2010-10-19 06:17 zigo73 File Added: http_auth_web_services_mantisbt1.2.3.patch
2010-10-19 06:18 zigo73 Note Added: 0027083
2010-10-19 06:18 zigo73 Status feedback => new
2010-10-20 04:47 rombert Note Added: 0027094
2010-10-20 04:47 rombert Assigned To => rombert
2010-10-20 04:47 rombert Status new => assigned
2010-10-20 04:47 rombert OS Centos =>
2010-10-20 04:47 rombert OS Version 5.5 =>
2010-10-20 04:47 rombert Platform Linux =>
2010-10-20 04:47 rombert Description Updated View Revisions
2010-10-20 04:51 rombert Tag Attached: patch
2010-10-20 17:28 rombert Note Added: 0027103
2010-10-20 17:39 zigo73 Note Added: 0027104
2010-10-20 17:57 rombert Note Added: 0027105
2010-10-20 17:57 rombert Assigned To rombert => scoates
2010-10-29 16:44 rombert Assigned To scoates => rombert
2010-12-14 21:05 jreese Target Version 1.2.4 => 1.2.5
2010-12-25 15:38 rombert Status assigned => feedback
2010-12-27 05:34 zigo73 Note Added: 0027713
2010-12-27 05:34 zigo73 Status feedback => assigned
2010-12-27 05:44 rombert Note Added: 0027714
2010-12-27 10:32 zigo73 Note Added: 0027730
2010-12-27 10:57 rombert Note Added: 0027733
2011-02-07 18:54 rombert File Added: 0001-Enable-MantisBT-to-participate-in-SSO-scenarios.patch
2011-02-08 17:01 rombert Note Added: 0028194
2011-02-18 21:18 dhx Target Version 1.2.5 => 1.3.x
2011-02-18 21:18 dhx Description Updated View Revisions
2011-02-18 21:28 dhx Note Added: 0028256
2012-11-03 06:47 iwan Note Added: 0033418
2012-11-04 13:39 rombert Note Added: 0034225
2013-05-14 16:52 atrol Relationship added related to 0011084


MantisBT 1.2.16dev master-1.2.x-8c2bd07 [^]
Copyright © 2000 - 2013 MantisBT Team
Time: 0.1386 seconds.
memory usage: 2,956 KB
Powered by Mantis Bugtracker