【问题标题】:How to restrict access to section of website running on Azure如何限制对 Azure 上运行的网站部分的访问
【发布时间】:2019-11-30 09:37:11
【问题描述】:

我有一个在 Azure 上运行的 Episerver 网站,出于安全原因,我想使用 IP 地址白名单阻止对 cms 管理部分的任何请求的访问。

我过去曾在 Windows 服务器上运行的网站上这样做过,但我从未在 Azure 托管网站上这样做过。我已经尝试过在以前的网站上采用的方法,在 web.config 中为我要限制的位置添加了一个安全部分,例如:

<location path="cms/admin">
 <system.webServer>
  </ipSecurity>
   <add allowed="true" ipAddress="{my ip address}" subnetMask="255.255.255.255" />
...
  </security>
 </system.webServer>
</location>

这在本地工作,但是当我将 web.config 部署到 Azure 时它不起作用。它会阻止任何用户(包括白名单中的用户)访问该位置。

我还研究过使用 aplication->networking->Access-restrictions 在 portal.azure 中进行更改,但这看起来是为了控制对整个应用程序的访问,这不是我想要的。

有谁知道我这样做是否不正确,特别是针对 Azure 网站?我错过了访问限制中的设置吗?

谢谢

山姆

【问题讨论】:

  • 学习带条件的 URL Rewrite 模块规则,然后你就可以轻松实现了。

标签: asp.net azure iis episerver


【解决方案1】:

您可以使用iis url重写规则来阻止请求以限制特定路径的ip:

<rule name="RequestBlockingRule1" patternSyntax="Wildcard" stopProcessing="true">
                    <match url="cms/admin" />
                    <conditions>
                        <add input="{REMOTE_ADDR}" pattern="192.168.2.*" />
                    </conditions>
                    <action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to view this directory or page using the credentials that you supplied." />
                </rule>

如果你想允许一些 ip 比你可以添加另一个不匹配模式的条件。

更多细节可以参考以下文章:

Creating Rewrite Rules

Request Blocking - rule

【讨论】:

    【解决方案2】:

    正如其他人建议的那样,我们使用 url 重写模块解决了这个问题。我们还意识到,由于 cloudflare CDN,传入的 IP 地址不是真正的请求源 IP 地址。幸运的是,原始 IP 地址包含在来自 Cloudflare 的重新路由请求中,因此我们能够使用下面的 url 重写规则来完成这项工作。我已将此添加为问题的正确答案,因为 Jalpa 的答案在技术上不适用于我的特定上下文:

    <rewrite>
        <rules>
            <rule name="restrict admin access by IP address" stopProcessing="true">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_URI}" pattern="^/admin/login(.*)" />
                    <!-- localhost -->
                    <add input="{HTTP_True_Client_IP}" pattern="^127\.0\.0\.1$" negate="true"/>
                    <!-- my office -->
                    <add input="{HTTP_True_Client_IP}" pattern="^{your ip address here}$" negate="true"/>
                </conditions>
                <action type="CustomResponse" statusCode="404" statusReason="Not Found" statusDescription="The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." />
            </rule>
        </rules>
    </rewrite>
    

    【讨论】:

      【解决方案3】:

      这最近对我有用。

      <?xml version="1.0" encoding="UTF-8"?>
      <configuration>
          <system.webServer>
              <rewrite>
                  <rules>
                      <rule name="Block unauthorized access to admin" stopProcessing="true">
                          <match url=".*" />
                          <conditions>
                              <!-- Enter your staging site host name here as the pattern-->
                              <add input="{REQUEST_URI}" pattern="^/admin" />
                              <!-- Enter your white listed IP addresses -->
                              <add input="{REMOTE_ADDR}" pattern="127\.0\.0\.1" negate="true" />
                              <add input="{REMOTE_ADDR}" pattern="127\.0\.0\.2" negate="true" />
                              <!-- <add input="{REMOTE_ADDR}" pattern="123\.123\.123\.2" negate="true"/> -->
                          </conditions>
                          <action type="CustomResponse" statusCode="404" statusReason="Not Found" statusDescription="Site is not accessible" />
                      </rule>
                  </rules>
              </rewrite>
          </system.webServer>
      </configuration>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-04-08
        • 1970-01-01
        • 2023-03-09
        • 1970-01-01
        • 1970-01-01
        • 2010-11-15
        • 2017-11-05
        • 1970-01-01
        相关资源
        最近更新 更多