Azure website IP restriction

痴心易碎 提交于 2019-11-29 14:32:08

Just in case someone is trying to setup IP restrictions with Cloudflare: the solution is to not only add your IP to the whitelist, but also all the Cloudflare IPs (taken from 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>

Not intended as a full answer, just posting a slightly updated list of CloudFlare IPs in useful copy/paste format. See the accepted answer for usage.

    <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" />

Since Azure SDK 2.3 it's possible to use Access Control List (ACL) to apply IP restrictions for your cloud services.

Just add the ACL to your 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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!