django-mama-cas icon indicating copy to clipboard operation
django-mama-cas copied to clipboard

LOGOUT_URL doesnot work if its not HTTPS & SLO (Single log out) messages not being sent.

Open ghost opened this issue 7 years ago • 26 comments

Hi, I got Single Sign-On working with different python apps in different virtual environments. Its combination of django-mama-cas as a server, and django-cas-ng on the clients. SSO is piece of cake. 9I referred the documentation and this article as well.

But, I have noticed that on Logout from one app, I am still Signed into the other apps. On the terminal (after running manage.py runserver), I see that the SLO (Single log out) messages are not sent to any other app if the LOGOUT_URL is not HTTPS.

But, when I set LOGOUT_URL = 'https://', it tries to send the Logout message. But, since I am running in development environment, so I get the following error:

requests.exceptions.ProxyError: HTTPSConnectionPool(host='127.0.1.1', port=9898): Max retries exceeded with url: /admin/callback (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden',)))

That most likely due to the self-signed SSL certificates. Can you please tell me if this is the desired behavior to have LOGOUT_URL as HTTPS? And, any specific procedure to look at the logs of django-mama-cas only which will help to troubleshoot this?

ghost avatar Feb 08 '18 23:02 ghost

FYI I am using:

django-mama-cas==2.3.0 (as server) django-cas-ng==3.5.8 (on the client side)

ghost avatar Feb 08 '18 23:02 ghost

Hi @amanjots,

Of course you want HTTPS every time sensitive information like tokens or cookies travel across the network.

I'd say it is trying to use a proxy and it is not configured correctly, or you are not listening on the 443 port, I mean, it doesn't look like a CAS problem, but a network configuration problem.

manelclos avatar Feb 09 '18 08:02 manelclos

@manelclos I agree that sensitive information should be HTTPS. But my question is that in a development environment, where it may not have HTTPS all the time, does django-mama-cas still needs HTTPS in LOGOUT_URL?

ghost avatar Feb 09 '18 15:02 ghost

I tried to trace all the django requests being sent or received. with django-request. And, I found that when a user clicks on Logout, he is logged out of the app, but there is no POST request sent for SLO messages to the other apps. So, user remains signed in the other apps.

ghost avatar Feb 09 '18 22:02 ghost

I don't think so. I'll try to do some testing using the repository from https://github.com/jbittel/django-mama-cas/issues/59 to check for both issues.

manelclos avatar Feb 09 '18 23:02 manelclos

Ops, previous response if for previous comment. About your new comment, I think there is some bad configuration on your side.

manelclos avatar Feb 09 '18 23:02 manelclos

Can you check that in the client you are using

CAS_LOGOUT_COMPLETELY = True
CAS_VERSION = '3'

and that you have this in your urls.py?

from django_cas_ng import views as cas_views

urlpatterns = [
    ...
    url(r'^accounts/login/$', cas_views.login, name='login'),
    url(r'^accounts/logout/$', cas_views.logout, name='logout'),
    url(r'^admin/logout/$', cas_views.logout),
    ....

manelclos avatar Feb 09 '18 23:02 manelclos

@manelclos yes the client has settings (CAS_LOGOUT_COMPLETELY = True & CAS_VERSION = '3'). In the URLs of the first django virtual environment, the Wagtail's admin authentication is to be handled by the django-ng-cas client, so the urls are:

    url(r'^admin/login/$', cas_views.login, name='cas_ng_login'),
    url(r'^admin/logout/$', cas_views.logout, name='cas_ng_logout'),
    url(r'^accounts/callback$', cas_views.callback, name='cas_ng_proxy_callback'),

And, the third virtual environment is having django-helpdesk, and to use CAS for its authentication I have changed the url's to following:

    url(r'^login/$', cas_views.login, name='cas_ng_login'),
    url(r'^logout/$', cas_views.logout, name='cas_ng_logout'),
    url(r'^accounts/callback$', cas_views.callback, name='cas_ng_proxy_callback'),

As per this tutorial , the callback "url processes logout request that comes from the CAS server." That's why I have used it in this way, and have also tried 'admin/callback' or 'accounts/callback' or even commenting it out as well.

In the above config, single sign-on works perfectly fine. But, single log out doesn't work at all.

ghost avatar Feb 10 '18 00:02 ghost

I've never used the callback setting in urls.py.

manelclos avatar Feb 10 '18 09:02 manelclos

@manelclos: I have tried without callback setitngs also, and SLO still doesn't work.

Further, I saw that you had found an issue with SLO before and tested it to work properly in #27

Can you please share the settings (from settings.py) and URLs of django-mama-cas and django-cas-ng that works for you? Thanks.

ghost avatar Feb 12 '18 02:02 ghost

Hi @amanjots, I got some time today for testing this. Maybe you are missing this on the settings.py of the server (mama_cas):

MAMA_CAS_ENABLE_SINGLE_SIGN_OUT = True

I've fixed the SSO and SLO configurations so they are working in this example: https://github.com/manelclos/django-cas-test

See that when you log out from "cas_client" (app1) the cookie for the cas_server is deleted and also the one for "cas_client" (app1). "second_client" (app2) cookie is not deleted until you access "second_client" again.

Let me know if you get it working with the example repository.

manelclos avatar Feb 14 '18 21:02 manelclos

@manelclos Thanks a lot for your reply and providing the example. Have you tested django-mama-cas server with 'MAMA_CAS_SERVICES' because the way you have configured CAS server it is operating in "open mode".

So can you once check if you configure 'MAMA_CAS_SERVICES' in settings.py of cas server, does it work properly? If you can update the config after testing this, that will really help to resolve the issue. Thanks again. :)

ghost avatar Feb 14 '18 22:02 ghost

Yes, it was working also with MAMA_CAS_SERVICES, I removed it before commiting to make it even simpler.

manelclos avatar Feb 14 '18 22:02 manelclos

@manelclos Thanks again. Can you please add 'MAMA_CAS_SERVICES' configuration that you tested to be working to https://github.com/manelclos/django-cas-test ?

ghost avatar Feb 15 '18 04:02 ghost

Sure thing, see here: https://github.com/manelclos/django-cas-test/commit/f1b1dd9509986bb6bbe62f601952fafb97ca723f

On the server you can check:

$ python manage.py checkservice http://127.0.0.1
Invalid service: http://127.0.0.1

$ python manage.py checkservice http://127.0.0.1:8001
Valid service: http://127.0.0.1:8001
  Proxy allowed: True
  Logout allowed: True
  Logout URL: None
  Callbacks: 

manelclos avatar Feb 15 '18 07:02 manelclos

@amanjots is this issue fixed?

manelclos avatar Feb 28 '18 18:02 manelclos

@manelclos I will have to do the testing again soon. Actually, the project structure that I was working on is changed completely. So, I will have to setup my separate project to test this issue. Kindly allow me few days to ensure this issue is resolved. Thanks.

ghost avatar Mar 01 '18 03:03 ghost

Thanks for the description - from this thread I figured out how to make this mama-client thing going. For me also does not work the single log out in local development mode if I use http protocol. I'll check on staging, if it works with https.

Manel, ( @manelclos ) I have a multi-language multi-domain site. I have - as you suggested:

settings.py:

MAMA_CAS_ENABLE_SINGLE_SIGN_OUT = True
CAS_LOGOUT_COMPLETELY = True
CAS_VERSION = '3'

urls.py:

    path('accounts/', include('django.contrib.auth.urls')),
    url(r'^cas/', include('mama_cas.urls')),
    path('accounts/login', django_cas_ng.views.LoginView.as_view(), name='cas_ng_login'),
    path('accounts/logout', django_cas_ng.views.LogoutView.as_view(), name='cas_ng_logout'),
    url(r'^admin/logout/$', django_cas_ng.views.LogoutView.as_view()),
  • first I log in on Site1
  • then I go to Site2 and get automatically logged in
  • now I log out on Site2
  • expect to get logged out on Site1 but I stay logged in.

What am I missing?

Probably relevant part of my requirements.txt:

django-cas-ng==3.6.0
django-hosts==3.0
django-mama-cas==2.4.0
django==2.2.2

BarnabasSzabolcs avatar Oct 20 '19 20:10 BarnabasSzabolcs

Ok, now I've figured out. MAMA CAS calls back the relevant CAS clients and says goodbye. For that MAMA CAS has to be said where to say good bye (it is done using the MAMA_CAS_SERVICES config variable) and the client has to provide a place for calling back (in case of DJANGO_CAS_NG it is CallbackView - they recommend setting "/acconts/callback" as AP).

BarnabasSzabolcs avatar Oct 25 '19 16:10 BarnabasSzabolcs

@BarnabasSzabolcs do you mean 'LOGOUT_URL': 'http://127.0.1.1:80/accounts/callback' in the MAMA_CAS_SERVICES?

thanks,I have the same problem.

lluww avatar Dec 27 '19 08:12 lluww

@lluww probably yes. My solution was to put my server behind nginx, locally.

BarnabasSzabolcs avatar Dec 28 '19 20:12 BarnabasSzabolcs

截屏2019-12-30下午4 49 06

The fact that request.user is AnonymousUser in the LogoutView function means that the logout_user(request) function will not be executed, resulting in a single logout failure, but I can't find a solution.

zhao-dapeng avatar Dec 30 '19 08:12 zhao-dapeng

@BarnabasSzabolcs thanks,I will configure nginx and try again, only change 'LOGOUT_URL' doesn't work.

lluww avatar Dec 30 '19 09:12 lluww

@lluww Ah, one more thing: with nginx I use mkcert https://github.com/FiloSottile/mkcert to generate local ssh certificates.

ssl_certificate /full/path/to/mypage.test-fullchain.pem; ssl_certificate_key /full/path/to/mypage.test-key.pem;

and then mama-cas works fine for me. (otherwise I get some weird redirect on logout... something like http://127.0.0.1:8000/http://127.0.0.1:8000/)

BarnabasSzabolcs avatar Dec 30 '19 13:12 BarnabasSzabolcs

@BarnabasSzabolcs Oh, I know my problem. I guess I forget to add 'django_cas_ng.middleware.CASMiddleware' in client app's setting.MIDDLEWARE. After that I can single-logout.

I haven't install nginx this is my logout url: Request URL: http://127.0.0.1:8000/logout?service=http%3A%2F%2F127.0.1.2%3A8000%2F Request Method: GET Status Code: 302 Found Remote Address: 127.0.0.1:8000

#setting.py server MAMA_CAS_SERVICES = [ { 'SERVICE': 'http://127.0.1.1:8000', 'CALLBACKS': [ 'mama_cas.callbacks.user_model_attributes', ], 'LOGOUT_ALLOW': True, 'LOGOUT_URL': 'http://127.0.1.1:8000/accounts/callback', 'PROXY_ALLOW': True, # 'PROXY_PATTERN': '^https://proxy.example.com', }, { 'SERVICE': 'http://127.0.1.2:8000', 'CALLBACKS': [ 'mama_cas.callbacks.user_model_attributes', ], 'LOGOUT_ALLOW': True, 'LOGOUT_URL': 'http://127.0.1.2:8000/accounts/callback', 'PROXY_ALLOW': True, # 'PROXY_PATTERN': '^https://proxy.example.com', } ] MAMA_CAS_ENABLE_SINGLE_SIGN_OUT = True

#setting.py client ALLOWED_HOSTS = ['127.0.1.2']

CAS_SERVER_URL = 'http://127.0.0.1:8000'

CAS_VERSION = '3'

CAS_APPLY_ATTRIBUTES_TO_USER = True

CAS_LOGOUT_COMPLETELY = True

AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', 'django_cas_ng.backends.CASBackend', )

lluww avatar Dec 31 '19 03:12 lluww

Hello, I have a problem in making a logout system using mama cas, I can't get service at the login URL after logging out. How to get service in URL when logout using mama cas?

girikusuma avatar Sep 15 '21 06:09 girikusuma