Git Product home page Git Product logo

mod_auth_tkt's Introduction

Introduction

See the INSTALL file for installation instructions.

NOTE: this version of mod_auth_tkt (2.0.x) works with Apache 1.3.x, 2.0.x, and 2.2.x. The older mod_auth_tkt 1.3.x is now deprecated, and all users are encouraged to upgrade.

mod_auth_tkt is a lightweight cookie-based authentication module for Apache, written in C. It implements a single-signon framework that works across multiple apache instances and multiple machines. The actual authentication is done by a user-supplied CGI or script in whatever language you like (examples are provided in Perl), meaning you can authenticate against any kind of user repository you can access (password files, ldap, databases, etc.)

mod_auth_tkt supports inactivity timeouts (including the ability to control how aggressively the ticket is refreshed), the ability to include arbitrary user data within the cookie, configurable cookie names and domains, and token-based access to subsections of a site.

mod_auth_tkt works by checking incoming Apache requests for a (user- defined) cookie containing a valid authentication ticket. The ticket is checked by generating an MD5 checksum for the username and any (optional) user data from the ticket together with the requesting IP address and a shared secret available to the server. If the generated MD5 checksum matches the ticket's checksum, the ticket is valid and the request is authorised. Requests without a valid ticket are redirected to a configurable URL which is expected to validate the user and generate a ticket for them. This package includes a Perl module for generating the cookies; implementations for other environments should be relatively straightforward.

Pros and Cons

The mod_auth_tkt scheme has several advantages and only one significant disadvantage:

Advantages -

  1. Usable on any apache webserver: because it's written in C using only the Apache C API, mod_auth_tkt should be usable on the simplest stripped down Apache server - no mod_perl, mod_php, or servlets required. mod_auth_tkt's only requirement is that the Apache supports DSO (Dynamic Shared Objects).

  2. Single-signon across Apaches and machines, including mixed environments: mod_auth_tkt enables a user to login once and then be seamlessly authorised across multiple Apaches or machines. Mixed environments work fine too - lightweight static HTML Apache with heavier mod_perl/mod_php/servlet enabled Apache, or a mixed Unix/Windows environment. Only requirements are a shared secret across all the servers.

  3. Pluggable authentication and authorisation: mod_auth_tkt hands off the authentication and authorisation problem to the URL of your choice. This means that you can use whatever technology (CGI, Perl, PHP, ASP, Java etc.) and whatever repositories (passwd files, LDAP, NIS, RDBMS, radius, or any combination thereof) you like - as long as the authorising page or script generates a valid ticket for a valid user everything should work just fine.

  4. Drop-in replacement for Basic Authentication: mod_auth_tkt sets the Basic Authentication REMOTE_USER environment variable on authorised requests, so that existing scripts that work with Basic Authentication should work unchanged in a mod_auth_tkt environment.

  5. No server-side storage requirements: because cookies are basically a client-side storage technology, there are no storage requirements on the server side - no session database is required (although you're free to use one if it already exists).

  6. Supports cross-domain authentication (as of version 1.3.8): although cookies are domain specific, the newest version of mod_auth_tkt allows initial tickets to be passed via URLs, allowing single-signon across completely unrelated domains (www.foo.com and www.bar.com).

Disadvantages -

  1. Requires cookies: browsers without cookie support will never have a valid ticket and will therefore never be authorised by mod_auth_tkt. There are no current plans to support non-cookie-based authentication.

Protocol Details

  1. Login procedure (by user script/CGI)

1.1 User logs in by supplying user credentials to server-side login module. Login module is implemented e.g., as CGI or servlet.

1.2 Login module has access to a login database that has following information: user credentials and additional information such as user class/groups etc.

1.3 If login module finds that user credentials supplied matches the ones in database, an authentication cookie is constructed.

1.4 Contents of authentication cookie: user ID, client IP address, timestamp, optional token list, optional user data, plus an MD5 checksum to ensure the integrity of the cookie. The MD5 checksum is generated from following information: - shared secret - user ID - client IP address - timestamp - token list, if supplied - user data, if supplied

1.5 The basic format of the ticket / authentication cookie value is as follows:

ticket := <MD5-checksum> <timestamp> <uid> ['\0' <tokens>] ['\0' <user-data>]

tokens := ! <token1> [ , <token2> ... ]

user-data := ! <arbitrary-user-data>
  1. Request authentication by mod_auth_tkt

2.1 If no authentication cookie is present in a request, request is redirected to a configurable login URL.

2.2 If authentication cookie is present and timeout checking is enabled, timestamp in the cookie is compared with the current time on the server. If the cookie has expired, request is redirected to a configurable timeout URL.

2.3 If authentication cookie is present and not expired, MD5 checksum is generated as described in 1.4. The MD5 checksum in cookie is compared with the one generated. If they match the user is successfully authenticated.

2.4 If a TKTAuthToken is also required for this url/area, mod_auth_tkt will then check the first field of the user_data (which has been checked via the MD5 checksum in the previous step) for a comma- separated list of tokens for this user. If the required token is not found in this list, the request is redirected to a configurable unauthorised URL.

2.4 Upon successful authentication authentication mod_auth_tkt sets environment variables for user ID and user data. User data is also placed in query string.

2.5 If authentication fails, request is redirected as in 2.1.

2.6 Upon redirection in 2.1, 2.2 or 2.4 mod_auth_tkt attempts to pass the requested URL as a 'back' link so that after checking user credentials login module can bounce the request back again. If the TktAuthBackCookieName parameter is set, mod_auth_tkt will set a cookie with that name to hold this link; otherwise it will pass it as a GET parameter to the authenticating URL (back=).

Cookie Format

The TKTAuthCookieName cookie is constructed using following algorithm:

('+' is concatenation operation)

cookie := digest + hextimestamp + user_id + '!' + user_data

or if using tokens:

cookie := digest + hextimestamp + user_id + '!' + token_list + '!' + user_data

digest := MD5(digest0 + key)

digest0 := MD5(iptstamp + key + user_id + '\0' + token_list + '\0' + user_data)

iptstamp is a 8 bytes long byte array, bytes 0-3 are filled with client's IP address as a binary number in network byte order, bytes 4-7 are filled with timestamp as a binary number in network byte order.

hextimestamp is 8 character long hexadecimal number expressing timestamp used in iptstamp.

token_list is an optional comma-separated list of access tokens for this user. This list is checked if TKTAuthToken is set for a particular area.

user_data is optional

Credits and Disclaimer

This is the Open Fusion version of the mod_auth_tkt Apache module. mod_auth_tkt was originally written by Raimondas Kiveris for Liquid Digital Information Systems, Inc. (see http://www.ldis.com/tkt_auth/), and further developed by Nelio Alves Pereira Filho (see http://www.ime.usp.br/~nelio/software/apache/). This version is the work of Gavin Carr of Open Fusion Pty. Ltd. (Australia), and the contributors cited in the CREDITS file in the distribution. The definitive site for this version is http://www.openfusion.com.au/labs.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

mod_auth_tkt's People

Contributors

gavincarr avatar mpeters avatar nugget avatar sshambar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mod_auth_tkt's Issues

Apache 2.4 release?

Can the current support for Apache 2.4 be summarized?

From quickly reading the tickets/PR's and code notes it seems 2.4 support is still in beta? Since the last commit seems to be circa 2015 is it fair to say this is stable and could be released?

Any details on this would be greatly appreciated a 2.4 release would be great for this very useful module. Thanks in advance!

cookie breaks with UID with email

Hi,

I am using python here, whenever I create the cookie with the userid (UID) with the email it breaks, it works fine with other strings but with the @ it replaces it with %40 and makes the cookie invalid.

Is there a workaround or something?

This is my python code:
from paste.auth import auth_tkt
ticket = auth_tkt.AuthTicket('TOP SECRET!', userid='[email protected]', ip='0.0.0.0', user_data="[email protected]")
print ticket.cookie()

Error log:
TKT valid_ticket: (parsed) uid 'felipe.torres.cs%40gmail.com', tokens '', user_data 'test', ts '1474047351', ...
mod_auth_tkt.c(820): TKT ticket_digest: using secret 'TOP SECRET!', ip '0.0.0.0', ...
TKT valid_ticket: ticket hash (current secret) is invalid, and no old secret set - digest 'ae4f4372680e13a00481301', ticket 'e302f8654678876567876767dc2d77felipe.torres.cs%40gmail.com!test', referer: ...

set protocol https or http in case of using ProxyPass

this would be to complete the patch Charlie Brady did submit to you years ago for X-Forward-Host.

please find attached a patch that allow to add X-Forward-Proto directive in order to rewrite correctly the URL when a 307 redirection occurs.

without this, in case of a proxy using https, this will prevent recent browser to refresh the destination if inside an iframe.

In term of documentation , the proxying isntance of httpd should add where necessary :

RequestHeader set X-Forwarded-Proto "https"

please feel free to rewrite it with better syntax !

mod_auth_tkt-2.3.99b1-betterredirection.patch.txt

IPv6 support

As far as I was able to tell, the cookie only has 4 bytes for the client IP address, meaning that IPv6 could be an issue. I propose an update to the format to allow for the larger size of v6 addresses.

SameSite attribute

Hi, do you plan to add SameSite=[Lax|Strict] for authentication cookies?

Using X-Forwarded-Host/Host header to construct redirect URLs is insecure

The code to create the redirect URL (and the back URL) appears to use the HTTP headers to construct said URLs. This is vulnerable to cache-poisoning attacks isn't it?

http://www.skeletonscribe.net/2013/05/practical-http-host-header-attacks.html

On a local setup I can set an 'evil' X-Forwarded-Host header and if TKTAuthLoginURL uses a relative path, it will redirect to the 'evil' host to login. This can be worked around using a fully-qualified URL for TktAuthLoginURL, but the 'back' link after the user successfully logs in still goes to the 'evil' host.

Unique TKTAuthToken when using VirtualDocumentRoot

I am using VirtualDocumentRoots in my Apache setup: http://httpd.apache.org/docs/2.2/vhosts/mass.html

Is it possible to create a unique TKTAuthToken for each Virtual Host?

For example:

foo.example.com -> /home/sites/foo - accessible by users with "foo" token
bar.example.com -> /home/sites/bar - accessible by users with "bar" token

Here is my conf:

<VirtualHost *:80>
    ServerAlias *.example.com
    VirtualDocumentRoot "/home/sites/%1/
    TKTAuthPublicKey /home/private/tkt_pubkey_dsa.pem
</VirtualHost>

<Directory "/home/sites/*">
   Order allow,deny
   AuthType mod_auth_pubtkt
   TKTAuthLoginURL http://login.example.com/
   TKTAuthTimeoutURL https://login.example.com/?timeout=1
   TKTAuthUnauthURL https://login.example.com/?unauth=1

   TKTAuthToken "?" - Unique for each site

   require valid-users
</Directory>

mod_auth_tkt & mod_proxy...reverse proxy removes query string?

I have an issue with mod_auth_tkt when used with mod_proxy in a reverse proxy setup.

I used this previous mod_auth_tkt thread as reference...
http://sourceforge.net/mailarchive/forum.php?thread_name=07A4A9EC53C2B841A7015A2E2FAFD19506C8CA58%40flybe06.flybe.local&forum_name=modauthtkt-users

Any URL with a query string has the query string removed when it is proxy'ed to the backend application.

eg

https://config.mycompany.com/app1/csdmain.vmgw ...works
http://app1.mycompany.com:8080/csdmain.vmgw sent

https://config.mycompany.com/app1/csdsrch.vmgw ...works
http://app1.mycompany.com:8080/csdsrch.vmgw sent

https://config.mycompany.com/app1/csdshow.vmgw?mode=text&fname=HIGHPT&ftype=AB1234 ..doesn't work
http://app1.mycompany.com:8080/csdshow.vmgw is sent to the backend application

debug dump...
[ mod_auth_tkt config ]
the_request: GET /app1/csdshow.vmgw?mode=text&fname=HIGHPT&ftype=AB1234 HTTP/1.1
URI: /app1/csdshow.vmgw
unparsed URI: /app1/csdshow.vmgw?mode=text&fname=HIGHPT&ftype=AB1234
Args: mode=text&fname=HIGHPT&ftype=AB1234
Filename: proxy:http://app1.mycompany.com:8080/csdshow.vmgw
TKTAuthSecret: wx4qJ3XWKLrN1f7EQbgP
TKTAuthSecretOld: (null)
TKTAuthDigestType: MD5
digest_sz: 32
directory: /app1
TKTAuthLoginURL: https://www.salesforce.com/secur/login.jsp
TKTAuthTimeoutURL: (null)
TKTAuthPostTimeoutURL: (null)
TKTAuthUnauthURL: (null)
TKTAuthCookieName: GBTicket
TKTAuthDomain: .mycompany.com
TKTAuthCookieExpires: 7200
TKTAuthBackCookieName: back
TKTAuthBackArgName: back
TKTAuthIgnoreIP: -1
TKTAuthRequireSSL: -1
TKTAuthCookieSecure: 1
TKTAuthTimeoutMin: 7200
TKTAuthTimeoutRefresh: 0.500000
TKTAuthGuestLogin: -1
TKTAuthGuestCookie: -1
TKTAuthGuestUser: (null)
TKTAuthGuestFallback -1
TKTAuthDebug: 3

I am using...

CentOS 5.6
Apache 2.2
mod_auth_tkt 2.1

My config is as follows...

<VirtualHost *:443>

ServerName config.mycompany.com
ServerAlias config.mycompany.com

TKTAuthSecret "secret"

all requests for /back/* must be authenticated

<Location /csd>
    #AuthType Basic
    Require valid‐user
    TKTAuthLoginURL  https://www.salesforce.com/secur/login.jsp
    TKTAuthCookieName GBTicket
    TKTAuthCookieSecure on
    TKTAuthDomain .mycompany.com
    #TKTAuthBackArgName 
    TKTAuthBackCookieName back 
    TKTAuthTimeout 2h
    TKTAuthCookieExpires 2h
    TKTAuthDebug 0  
</Location>
ProxyRequests off
ProxyPass /app1/  http://app1.mycompany.com:8080/

RewriteEngine on

RewriteRule ^/app1/?$ http://app1.mycompany.com:8080/ [P,L]

RewriteRule ^/app1/(.+)$ http://app1.mycompany.com:8080/$1 [P,L]

ProxyPassReverse  /app1/      http://app1.mycompany.com:8080/
WSGIScriptAlias /login    /var/www/public_html/config.mycompany.com/login/adapter.wsgi

The application receives a federated login from a salesforce app, and a Python wsgi app creates the GBTicket secure cookie.

I have tried both mod_proxy and mod_rewrite for the reverse proxy, with the same result. I have also tried to add the query string back in to the request using mod_rewrite, but it still gets removed.

When I disable mod_auth_tkt, the reverse proxy works as normal, and the query string is passed through to the backend application.

Do you have any idea why this is happening?

Thanks,
Brian M

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.