librelist archives

« back to archive

Getting acces to the mod_ssl environment variables through flask

Getting acces to the mod_ssl environment variables through flask

From:
Nicolas Pedneault
Date:
2014-03-09 @ 16:23
Good day,

I just started using flask, and I am running though some problems trying to
access mod_ssl variables (such as SSL_CLIENT_S_DN) for logging purposes.  I
had no problem setting up the server for client-server PKI authentication,
but I need I also need my application to be able to handle these variables.
 I am pretty sure I have configured apache2 to pass these variables (SSLOptions
+StdEnvVars), but when I try to get to them with
os.environ['SSL_CLIENT_S_DN'] in my application, I do not get anything back.

Thank you for your assistance.

Re: [flask] Getting acces to the mod_ssl environment variables through flask

From:
Kevin Houlihan
Date:
2014-03-09 @ 16:44
Hi Nicolas,

I'd say those probably go in the WSGI environment rather than the OS
environment:


http://flask.pocoo.org/mailinglist/archive/2011/3/22/accessing-wsgi-environment-variables/#cdac1d35b7e3ca68c23704549e741437

--
Kevin


On 9 March 2014 16:23, Nicolas Pedneault <npedno@gmail.com> wrote:

> Good day,
>
> I just started using flask, and I am running though some problems trying
> to access mod_ssl variables (such as SSL_CLIENT_S_DN) for logging purposes.
>  I had no problem setting up the server for client-server PKI
> authentication, but I need I also need my application to be able to handle
> these variables.  I am pretty sure I have configured apache2 to pass these
> variables (SSLOptions +StdEnvVars), but when I try to get to them with
> os.environ['SSL_CLIENT_S_DN'] in my application, I do not get anything back.
>
> Thank you for your assistance.
>

Re: [flask] Getting acces to the mod_ssl environment variables through flask

From:
Nicolas Pedneault
Date:
2014-03-10 @ 15:18
Thanks.  It helps, but I have tried things, and it still does not bring
back what I am looking for.

I have looked for example on how to use Request.environ, but nothing seems
to work.  I swear than when I do get it to work, I will publish my
solution!!!


On Sun, Mar 9, 2014 at 12:44 PM, Kevin Houlihan <kevin@crimsoncookie.com>wrote:

> Hi Nicolas,
>
> I'd say those probably go in the WSGI environment rather than the OS
> environment:
>
>
> 
http://flask.pocoo.org/mailinglist/archive/2011/3/22/accessing-wsgi-environment-variables/#cdac1d35b7e3ca68c23704549e741437
>
> --
> Kevin
>
>
> On 9 March 2014 16:23, Nicolas Pedneault <npedno@gmail.com> wrote:
>
>> Good day,
>>
>> I just started using flask, and I am running though some problems trying
>> to access mod_ssl variables (such as SSL_CLIENT_S_DN) for logging purposes.
>>  I had no problem setting up the server for client-server PKI
>> authentication, but I need I also need my application to be able to handle
>> these variables.  I am pretty sure I have configured apache2 to pass these
>> variables (SSLOptions +StdEnvVars), but when I try to get to them with
>> os.environ['SSL_CLIENT_S_DN'] in my application, I do not get anything back.
>>
>> Thank you for your assistance.
>>
>
>

Re: [flask] Getting acces to the mod_ssl environment variables through flask

From:
Nicolas Pedneault
Date:
2014-03-10 @ 17:14
I actually got it to work!!!

Here is how I wrote hello.py (straight out of the Flask hello world
example, but with a small modification):

################ hello.py
from flask import * #here, you could import "Flask" and "request" only)

app=Flask(__name__)

@app.route('/')
def hello_world():
    req=request.environ['SSL_CLIENT_S_DN'] #or any other mod_ssl
environment variables
    return req
if __name__='__main__':
    app.run()

################

In my case, I set up apache2 with
SSLOptions +StdEnvVars

(frankly, I am not sure it was required, but I did it anyway!)

Last but not least.  I had already configured my app to have PKI
client-server authentication.  For that, I used this example:
http://www.subdimension.co.uk/2012/11/10/flask_modwsgi_ssl_oh_my.html

Hope this helps someone.

Nick


On Mon, Mar 10, 2014 at 11:18 AM, Nicolas Pedneault <npedno@gmail.com>wrote:

> Thanks.  It helps, but I have tried things, and it still does not bring
> back what I am looking for.
>
> I have looked for example on how to use Request.environ, but nothing seems
> to work.  I swear than when I do get it to work, I will publish my
> solution!!!
>
>
> On Sun, Mar 9, 2014 at 12:44 PM, Kevin Houlihan <kevin@crimsoncookie.com>wrote:
>
>> Hi Nicolas,
>>
>> I'd say those probably go in the WSGI environment rather than the OS
>> environment:
>>
>>
>> 
http://flask.pocoo.org/mailinglist/archive/2011/3/22/accessing-wsgi-environment-variables/#cdac1d35b7e3ca68c23704549e741437
>>
>> --
>> Kevin
>>
>>
>> On 9 March 2014 16:23, Nicolas Pedneault <npedno@gmail.com> wrote:
>>
>>> Good day,
>>>
>>> I just started using flask, and I am running though some problems trying
>>> to access mod_ssl variables (such as SSL_CLIENT_S_DN) for logging purposes.
>>>  I had no problem setting up the server for client-server PKI
>>> authentication, but I need I also need my application to be able to handle
>>> these variables.  I am pretty sure I have configured apache2 to pass these
>>> variables (SSLOptions +StdEnvVars), but when I try to get to them with
>>> os.environ['SSL_CLIENT_S_DN'] in my application, I do not get anything back.
>>>
>>> Thank you for your assistance.
>>>
>>
>>
>