2013-03-02 51 views
3

我是新來的Azure和我正在使用新的網站模式,而不是雲服務項目。我想建立這樣一個連續的傳遞過程:http://www.windowsazure.com/en-us/develop/net/common-tasks/publishing-with-tfs/分期Azure的網站

不過,我不希望我的網站是公開每一個持續部署後尋址。相反,我希望我的持續部署只能由我的團隊進行測試。如何才能最好地實現?

思想至今:

  • 包住整個網站中的窗體身份驗證 - 但我不喜歡的事實,這意味着我會比我要部署部署不同版本的我的網站到生產進行測試。
  • IP地址限制 - 但我不知道這是否可以與Azure的網站來完成,這是一個很好的解決方案?

回答

2

Azure網站身份驗證/授權功能旨在支持此確切場景。基本上,您創建一個站點插槽,只需點擊幾下鼠標即可添加AAD身份驗證,然後即使在執行交換操作之後,您的登臺插槽始終需要有效的登錄。

博客文章:http://azure.microsoft.com/blog/2014/11/13/azure-websites-authentication-authorization/

演示視頻:http://azure.microsoft.com/en-us/documentation/videos/azure-websites-easy-authentication-and-authorization-with-chris-gillum/

1

我不得不爲客戶端做類似的事情,但是找不到限制Azure門戶本身訪問站點的方法。我使用IP地址限制選項,但通過應用程序本身的代碼完成。我的應用程序已經使用表單身份驗證,所以我可以在登錄操作中執行IP地址檢查。

在你的情況我建議一個custom action filter。在過濾器中執行檢查,如果IP地址不被允許,則返回http 401(未授權)狀態碼。

創建一個名爲AllowedIpAddresses的應用程序設置或一些這樣的,您可以在其中添加允許的IP地址的逗號分隔的列表。執行檢查時,如果AllowedIpAddresses爲空或不存在,則可以將您的站點設置爲允許所有流量。這樣,您可以在生產中忽略此設置,並且默認情況下會允許所有流量。您可以爲Azure門戶中的每個站點設置自定義應用程序設置。

這裏有一個自定義過濾器可能是什麼樣子。我沒有測試過這個!

public class AccessRestrictionFilterAttribute : ActionFilterAttribute 
{ 
    // simple wrapper around ConfigurationManager.AppSettings for testability 
    private readonly IAppSettingsHandler appSettingsHandler; 

    public AccessRestrictionFilterAttribute(IAppSettingsHandler appSettingsHandler) 
    { 
     this.appSettingsHandler = appSettingsHandler; 
    } 

    public override void OnActionExecuting(ActionExecutingContext filterContext) 
    { 
     var isAllowed = false; 
     var userIpAddress = filterContext.HttpContext.Request.UserHostAddress; 
     if (appSettingsHandler.AllowedIpAddresses.Split(new[] { ',' }).Any(x => x == userIpAddress)) 
     { 
      isAllowed = true; 
     } 

     if (!isAllowed) 
     { 
      filterContext.Result = new HttpUnauthorizedResult(); 
     } 

     base.OnActionExecuting(filterContext); 
    } 
} 
2

您可以使用URL重寫模塊添加IP限制,默認情況下,Azure網站似乎啓用了該功能。

你的web.config:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
     <rewrite> 
      <rules> 
       <rule name="SayNoToZombies" stopProcessing="true"> 
        <match url=".*" /> 
        <conditions> 
         <add input="{REMOTE_ADDR}" pattern="::1" negate="true" /> 
        </conditions> 
        <action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="Sorry, you're not allowed" /> 
       </rule> 
      </rules> 
     </rewrite> 
    </system.webServer> 
</configuration> 

您可以用合適的正則表達式來匹配您允許的IP,例如,pattern="87.236.134.47"取代pattern="::1"(IPv6中本地主機),或者如果不止一個:

pattern="(62\.231\.142\.233)|(87\.236\.134\.47)|(::1)|(127\.0\.0\.1)" 
+0

感謝湯姆。我喜歡這種基於配置的解決方案,它允許我使用web.config轉換在測試過程中輕鬆應用此限制,但在構建生產時將其刪除。 – John 2013-04-09 17:33:51