Azure网站IP限制

时间:2014-07-22 09:50:08

标签: azure ip azure-web-sites cloudflare

我有一个Azure网站,我只用于开发和测试,因此我想限制除了我自己以外的所有人访问它。 根据这个blog article,这现在是正式支持的,所以我尝试将它添加到我的web.config文件中:

<system.webServer>
    <security>
        <ipSecurity allowUnlisted="false" denyAction="NotFound">
            <add allowed="true" ipAddress="1.2.3.4" />
        </ipSecurity>
    </security>
</system.webServer>

对于ipAddress属性,我必须使用我的互联网连接的IP地址吗?所以我去了http://www.whatismyip.com/并复制了地址,但现在我的网站只是阻止所有请求,允许规则没有效果。

我错过了什么吗?

更新:日志文件显示Web服务器看到的IP不是实际客户端的IP,而是介于两者之间的代理(Cloudflare)。所以我尝试通过添加enableProxyMode="true"来解决这个问题,遗憾的是这不能解决我的问题。有关如何获得IP限制以使用Cloudflare的任何想法吗?

3 个答案:

答案 0 :(得分:7)

以防万一有人尝试使用Cloudflare设置IP限制:解决方案不仅是将您的IP添加到白名单,还要添加所有Cloudflare IP(取自here)。

<system.webServer>
    <security>
        <ipSecurity enableProxyMode="true" allowUnlisted="false" denyAction="NotFound">
            <!-- YOUR IP -->
            <add allowed="true" ipAddress="1.2.3.4" />
            <!-- CLOUDFLARE -->
            <add allowed="true" ipAddress="199.27.128.0" subnetMask="255.255.248.0" />
            <add allowed="true" ipAddress="173.245.48.0" subnetMask="255.255.240.0" />
            <add allowed="true" ipAddress="103.21.244.0" subnetMask="255.255.252.0" />
            <add allowed="true" ipAddress="103.22.200.0" subnetMask="255.255.252.0" />
            <add allowed="true" ipAddress="103.31.4.0" subnetMask="255.255.252.0" />
            <add allowed="true" ipAddress="141.101.64.0" subnetMask="255.255.192.0" />
            <add allowed="true" ipAddress="108.162.192.0" subnetMask="255.255.192.0" />
            <add allowed="true" ipAddress="190.93.240.0" subnetMask="255.255.240.0" />
            <add allowed="true" ipAddress="188.114.96.0" subnetMask="255.255.240.0" />
            <add allowed="true" ipAddress="197.234.240.0" subnetMask="255.255.252.0" />
            <add allowed="true" ipAddress="198.41.128.0" subnetMask="255.255.128.0" />
            <add allowed="true" ipAddress="162.158.0.0" subnetMask="255.254.0.0" />
            <add allowed="true" ipAddress="104.16.0.0" subnetMask="255.240.0.0" />
        </ipSecurity>
    </security>
</system.webServer>

答案 1 :(得分:0)

不打算作为完整答案,只需以有用的复制/粘贴格式发布稍微更新的CloudFlare IP列表。请参阅已接受的使用答案。

    <add allowed="true" ipAddress="103.21.244.0" subnetMask="255.255.252.0" />
    <add allowed="true" ipAddress="103.22.200.0" subnetMask="255.255.252.0" />
    <add allowed="true" ipAddress="103.31.4.0" subnetMask="255.255.252.0" />
    <add allowed="true" ipAddress="104.16.0.0" subnetMask="255.240.0.0" />
    <add allowed="true" ipAddress="108.162.192.0" subnetMask="255.255.192.0" />
    <add allowed="true" ipAddress="131.0.72.0" subnetMask="255.255.252.0" />
    <add allowed="true" ipAddress="141.101.64.0" subnetMask="255.255.192.0" />
    <add allowed="true" ipAddress="162.158.0.0" subnetMask="255.254.0.0" />
    <add allowed="true" ipAddress="172.64.0.0" subnetMask="255.248.0.0" />
    <add allowed="true" ipAddress="173.245.48.0" subnetMask="255.255.240.0" />
    <add allowed="true" ipAddress="188.114.96.0" subnetMask="255.255.240.0" />
    <add allowed="true" ipAddress="190.93.240.0" subnetMask="255.255.240.0" />
    <add allowed="true" ipAddress="197.234.240.0" subnetMask="255.255.252.0" />
    <add allowed="true" ipAddress="198.41.128.0" subnetMask="255.255.128.0" />
    <add allowed="true" ipAddress="199.27.128.0" subnetMask="255.255.248.0" />

答案 2 :(得分:-2)

从Azure SDK 2.3开始,可以使用访问控制列表(ACL)为您的云服务应用IP限制。

只需将ACL添加到 ServiceConfiguration.Cloud.cscfg

<NetworkConfiguration>
    <AccessControls>
        <AccessControl name="test">
            <Rule action="permit" description="test" order="100" remoteSubnet="xxx.xxx.xxx.xxx/32" />
            <Rule action="deny" description="test" order="200" remoteSubnet="0.0.0.0/0" />
        </AccessControl>
    </AccessControls>
    <EndpointAcls>
        <EndpointAcl role="WebRoleName" endPoint="Endpoint1" accessControl="test" />
    </EndpointAcls>
</NetworkConfiguration>