0

我正在嘗試讓OneLogin Saml身份驗證在我的實時服務器上工作,並且正在運行時遇到與我的AWS負載平衡器設置有關的問題。我認爲問題在於我有一個經典的負載均衡器,它使用AWS通配符HTTPS證書在端口80和443上偵聽。負載均衡器將這兩個端口轉發到我的服務器上的端口80,並添加HTTP_X_FORWARDED_PROTO標頭。Onelogin SAML與AWS負載平衡器

當我使用我的正常開發服務器(不是負載均衡器後面)SAML身份驗證正常工作。我正在得到一個適當的迴應。但是,當我推動生存時,SAML響應返回一個空的POST字典,而沒有RELAY STATE。

任何想法爲什麼POST將是空的?

我的設置是:

  • 的Python與SAML連接器開發服務器上
  • 工作正常社會權威性
  • 當我用我的直播服務器在防火牆後面,響應空

我懷疑它與我的SSL證書有關,或者我的負載均衡器將443轉發到端口80上的服務器並添加了標頭。我試圖通過分析轉發的報頭創建AUTH請求解決這個:

def _create_saml_auth(self, idp): 
    """Get an instance of OneLogin_Saml2_Auth""" 

    config = self.generate_saml_config(idp) 
    request_info = { 
     'https': 'on' if self.strategy.request_is_secure() else 'off', 
     'http_host': self.strategy.request_host(), 
     'script_name': self.strategy.request_path(), 
     'server_port': self.strategy.request_port(), 
     'get_data': self.strategy.request_get(), 
     'post_data': self.strategy.request_post(), 
    } 

    if 'HTTP_X_FORWARDED_PROTO' in self.strategy.request.META: 
     request_info['https'] = 'on' if self.strategy.request.META.get('HTTP_X_FORWARDED_PROTO') == 'https' else 'off' 
     request_info['server_port'] = self.strategy.request.META.get('HTTP_X_FORWARDED_PORT') 

但仍然無法返回從Onelogin SAML響應的empyy POST字典。儘管使用HTTPS正確生成初始url。

有沒有人有類似的問題。我卡住了,很想讓Onelogin工作。

非常感謝您的時間。

乾杯,

菲爾

回答

0

您可以檢查什麼的錯誤。我使用這樣的代碼:

auth = OneLogin_Saml2_Auth(saml_req, saml_settings) 
    auth.process_response() 

    if not auth.is_authenticated(): 
     error = auth.get_last_error_reason() # here's the error message 

我猜你是碰到了同樣的問題與ELB,我是,它就會像Authentication error: The response was received at http://... instead of https://...

該解決方案的東西要麼執行https-> https重定向,或者讓pysaml認爲它在https上收到響應。以下是我做到了(在這種情況下,一個Django應用程序,但應該很容易修改爲其他環境):

saml_req = { 
     'http_host': request.META['HTTP_HOST'], 
     'server_port': request.META['SERVER_PORT'], 
     'script_name': request.META['PATH_INFO'], 
     'get_data': request.GET.copy(), 
     'post_data': request.POST.copy() 
    } 

    if settings.SAML_FUDGE_HTTPS: # made a settings flag so it can be toggled 
     saml_req['https'] = True # this one forces https in the check url 
     saml_req['server_port'] = None # this one removes the port number (80) 

    auth = OneLogin_Saml2_Auth(saml_req, saml_settings) 
    auth.process_response() 

更新:爲@smartin提到的評論 - 你也許能夠嗅出HTTP_X_FORWARDED_FOR頭和避免產生變種的設置

+1

評論這個線程: https://github.com/onelogin/python-saml/issues/75#issuecomment-108647017 – smartin