User name in access logs

View: New views
3 Messages — Rating Filter:   Alert me  

User name in access logs

by Nicolas Thauvin-3 :: Rate this Message:

| View Threaded | Show Only this Message

Hi to the list,

  I would like to be able to dump an authenticated user name in the access  
logs. The problem is: in our application, the user name is fetched from a  
cookie hash using yaws_session_server. That means we cannot use the 'real'  
authorization header, and arg_rewrite_mod acts too late for this purpose.

I made a quick patch to use a custom module in order to fill the  
'authorization' structure from a cookie :

https://github.com/nthauvin/yaws/commit/840ee7021b1b3fca751661637cad3e3b7bd7f697

I am not really sure this is an appropriate way to do this. Any advice ?

Cheers,

-- Nicolas

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@...
https://lists.sourceforge.net/lists/listinfo/erlyaws-list

Re: User name in access logs

by Christopher Faulet :: Rate this Message:

| View Threaded | Show Only this Message

Le 22/02/2012 00:45, Nicolas Thauvin a écrit :

> Hi to the list,
>
>   I would like to be able to dump an authenticated user name in the access  
> logs. The problem is: in our application, the user name is fetched from a  
> cookie hash using yaws_session_server. That means we cannot use the 'real'  
> authorization header, and arg_rewrite_mod acts too late for this purpose.
>
> I made a quick patch to use a custom module in order to fill the  
> 'authorization' structure from a cookie :
>
> https://github.com/nthauvin/yaws/commit/840ee7021b1b3fca751661637cad3e3b7bd7f697
>
> I am not really sure this is an appropriate way to do this. Any advice ?
>
Hi Nicolas,

If it is just about logging, a solution is to write your own logger.
This feature is not well documented but there are some information in
the manpage of yaws.conf.
Of course, in this module, you can call the default logger of Yaws.

Here is an example:


%% ===================================================================
-module(simplelogger).

-behaviour(yaws_logger).

-include_lib("yaws/include/yaws.hrl").
-include_lib("yaws/include/yaws_api.hrl").

%% API
-export([
         open_log/3,
         close_log/3,
         wrap_log/4,
         write_log/4
        ]).

open_log(ServerName, Type, Dir) ->
    yaws_log:open_log(ServerName, Type, Dir).

close_log(ServerName, Type, Ident) ->
    yaws_log:close_log(ServerName, Type, Ident).

wrap_log(ServerName, Type, Data, LogWrapSize) ->
    yaws_log:wrap_log(ServerName, Type, Data, LogWrapSize).

write_log(ServerName, Type, Ident, {Ip, Req, InH, OutH, Time}) ->
    Auth = {"foo", undefined, undefined},
    InH1 = InH#headers{authorization = Auth},
    yaws_log:write_log(ServerName, Type, Ident, {Ip, Req, InH1, OutH,
Time}).
%% ===================================================================

--
Christopher



------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@...
https://lists.sourceforge.net/lists/listinfo/erlyaws-list

signature.asc (270 bytes) Download Attachment

Re: User name in access logs

by Nicolas Thauvin-3 :: Rate this Message:

| View Threaded | Show Only this Message

Oh yeah, this logger_mod option can do the trick, thanks !

The little drawback is that Authorization is computed just before writing.  
That would have been cool to compute it once for all before request  
processing, so that it can be reused afterwards. But no matter, the aim  
was the access logs.

Thanks again !

Nicolas

On Wed, 22 Feb 2012 18:04:55 +0100, Christopher Faulet  
<christopher.faulet@...> wrote:

> Le 22/02/2012 00:45, Nicolas Thauvin a écrit :
>> Hi to the list,
>>
>>   I would like to be able to dump an authenticated user name in the  
>> access
>> logs. The problem is: in our application, the user name is fetched from  
>> a
>> cookie hash using yaws_session_server. That means we cannot use the  
>> 'real'
>> authorization header, and arg_rewrite_mod acts too late for this  
>> purpose.
>>
>> I made a quick patch to use a custom module in order to fill the
>> 'authorization' structure from a cookie :
>>
>> https://github.com/nthauvin/yaws/commit/840ee7021b1b3fca751661637cad3e3b7bd7f697
>>
>> I am not really sure this is an appropriate way to do this. Any advice ?
>>
>
> Hi Nicolas,
>
> If it is just about logging, a solution is to write your own logger.
> This feature is not well documented but there are some information in
> the manpage of yaws.conf.
> Of course, in this module, you can call the default logger of Yaws.
>
> Here is an example:
>
>
> %% ===================================================================
> -module(simplelogger).
>
> -behaviour(yaws_logger).
>
> -include_lib("yaws/include/yaws.hrl").
> -include_lib("yaws/include/yaws_api.hrl").
>
> %% API
> -export([
>          open_log/3,
>          close_log/3,
>          wrap_log/4,
>          write_log/4
>         ]).
>
> open_log(ServerName, Type, Dir) ->
>     yaws_log:open_log(ServerName, Type, Dir).
>
> close_log(ServerName, Type, Ident) ->
>     yaws_log:close_log(ServerName, Type, Ident).
>
> wrap_log(ServerName, Type, Data, LogWrapSize) ->
>     yaws_log:wrap_log(ServerName, Type, Data, LogWrapSize).
>
> write_log(ServerName, Type, Ident, {Ip, Req, InH, OutH, Time}) ->
>     Auth = {"foo", undefined, undefined},
>     InH1 = InH#headers{authorization = Auth},
>     yaws_log:write_log(ServerName, Type, Ident, {Ip, Req, InH1, OutH,
> Time}).
> %% ===================================================================

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@...
https://lists.sourceforge.net/lists/listinfo/erlyaws-list