2012-03-20 30 views
2

我想在ec2上設置一個反向代理,通過使用nginx的自定義域提供對我的appengine應用程序的安全訪問。它似乎工作正常,除非頁面需要用戶服務。它重定向到Google帳戶登錄名,然後轉到appspot域,而不是我的自定義域。我知道appengine在測試中有ssl,但我想要一個我現在可以使用的解決方案。是否有可能克服這個問題,還是我需要創建自己的用戶?如何通過AppEngine使用SSL的反向代理並使用用戶服務?

以下是我的配置:

server { 
    listen 443; 
    server_name <custom-domain>; 

    keepalive_timeout 70; 

    ssl on; 
    ssl_certificate  /etc/nginx/cert/server.crt; 
    ssl_certificate_key /etc/nginx/cert/server.key; 
    ssl_session_timeout 30m; 

    location/{ 
     proxy_redirect off; 
     proxy_pass  https://<appid>.appspot.com; 
     proxy_set_header Host <appid>.appspot.com; 

     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

     proxy_intercept_errors off; 
    } 
} 

我的域名有一個CNAME指向EC2。

===

我找到了解決方法。仍然希望更簡單的一個,並會很感激反饋。

1) Client hits https: //mydomain.com/blah which goes through EC2 proxy https://appid.appspot.com/blah 
2) The client is redirected to the google login page, with continue set as /aa?continue=/blah 
3) Client logs into Google Accounts and is then redirected to https: //appid.appspot.com/aa?continue=/blah 
4) Client hits https: //appid.appspot.com/aa which serves a redirect to https://mydomain.com/sc?c=ACSID&continue=/blah where ACSID is the Google account session cookie read by the handler for /aa. 
5) Client hits https: //mydomain.com/sc?c=ACSID&continue=/blah which sets the ACSID session cookie for the domain mydomain.com and redirects to https: //mydomain.com/blah based on a continue parameter in aa passed to sc 

以下是我的web.xml

/ is publicly accessible 
/aa is publicly accessible 
/sc is publicly accessible 
/* is restricted to logged in users 

以下是在處理程序的限制(有一些棘手的網址轉義):

/ --> if not logged in, redirect to login page continue=/aa 
/aa --> if not logged in, redirect to login page continue=/aa 
/sc --> if not logged in, redirect to login page continue=/aa 
/* --> if not logged in, redirect to login page continue=/aa?continue=* 

在此之後,用戶服務似乎即使通過SSL代理服務時也能正常工作。 ACSID cookie現在位於mydomain.com上,並通過代理髮送到appengine。

appspot域名仍然會顯示給技術精明的用戶,但這不是我最關心的問題。我的目標是通過https提供服務,並將我的自定義域保留在網址欄中,並通過用戶數據更安全地使用我的自定義域名在無SSL的情況下提供服務。由於整個交易都通過https,我認爲這不會暴露會話cookie,而不是使用不帶SSL的mydomain.com。無論如何,即使沒有這個計劃,任何其他的跨站點攻擊都可以運行

我仍不確定爲什麼mydomain.com/_ah/conflogin?state=blah失敗並需要此解決方法。

回答

0

您的解決方法解決了我的問題 - 謝謝!

下面是我想出的代碼,對於其他人陷入同樣的​​情況。這是與一些網站特定的東西拉出,所以可能需要一點調整,使其工作。 Cookie是SACSID,因爲我使用的是https;我認爲這將是http的ACSID。

class CompleteLoginHandler(BaseHandler): 
    def get(self): 
     redirect_to=self.request.get('next', '/') 
     if not redirect_to.startswith('/'): # don't allow redirects to another domain 
      redirect_to = '/' 
     session_id = self.request.get('SACSID', None) 
     if session_id: 
      self.response.set_cookie('SACSID', session_id) 
     return self.redirect(redirect_to) 

class PostLoginRedirectHandler(BaseHandler): 
    def get(self): 
     domain = self.request.headers.get('X-Forwarded-Host', None) 
     if domain is None: 
      # we are on the bare url; need to transfer the user -- and cookie 
      sacsid = self.request.cookies.get('SACSID') 
      next_url = config['domain'] + self.uri_for('complete_login', next=self.uri_for(route_name), SACSID=sacsid) 
      return self.redirect(next_url) 
     else: 
      return self.redirect('/') 

這裏,PostLoginRedirectHandler是處理步驟(4),和CompleteLoginHandler正在處理的tarun2000的描述(5)步驟

相關問題