Protect a Web App from Access in Azure - azure

I have a web app running a old ASMX service that I want to limit access to for only other apps and services within my azure environment.
Is there any easy and cheap way to do this?
App Service Environments seems like it does this, but they seem rather expensive for this small purpose. I would be cheaper with a VM that I can configure the firewall on.

If you know the IP-Ranges you can use web.config file in root of your app:
<security>
<ipSecurity allowUnlisted="false"> <!-- this line blocks everybody, except those listed below -->
<clear/> <!-- removes all upstream restrictions -->
<add ipAddress="127.0.0.1" allowed="true"/> <!-- allow requests from the local machine -->
<add ipAddress="81.116.19.53" allowed="true"/> <!-- allow the specific IP of 81.116.19.53 -->
</ipSecurity>
</security>

Related

Howto best setup MTLS in Azure

I would like to host IdentityServer4 in Azure with MTLS configured for a specific path. How can I accomplish that by hosting the IdentityServer4 asp.net core application in an "App Service" and setting up MTLS with some kind of load-balancer: API Management service, Application Gateway, NGINX etc. What I need is requiring client certificate on a specific path and be able to set up some kind of CTL (certificate-trust-list). In other words I would like to replace the following that you accomplish with a Windows-IIS-machine and web.config:
<configuration>
...
<location path="connect/mtls">
<system.webServer>
<security>
<access sslFlags="Ssl, SslNegotiateCert, SslRequireCert" />
</security>
</system.webServer>
</location>
...
</configuration>
Anyone?

How to have different Web.config files for different slots in Azure

How can I have different Web.config files for different Azure slots.
I have a staging and production slot with the same website I don't want the staging slot to be public (it's only for testing and such), so I've setup authentication for that slot through the web.config file.
The problem is that when I upload changes the production slot gets the same web.config file as the staging slot which is set for only allowing access by authenticating, and also the parameters are different so the production slot ends up getting inaccessible, I have to change the web.config file manually in the production slot to make it work.
I wanted to have some way to define a different web.config file for the production slot.
Update (adding more information to the question):
I'm using my local machine for testing (with a local server), that is the development environment.
The sites are in wordpress (wordpress uses php).
The staging slot is used only by a few people, not connected to my local Lan, when I selectively want them to test my site (different Operating Systems, different platforms, different mobile phones,..) before sending things to production. I can just stop the staging slot, when I'm not using it so production resources are not be affected.
I'm already using AppSettings for different connectionStrings, and parameters. I don't know how to use this to define different authentication settings..? I have the authentication settings in the web.config file (used by the staging slot).
My web.config file:
<configuration>
<system.web>
<authorization>
<allow users="foo#gmail.com, foo2#foo2.com, foo3#gmail.com"/>
<deny users="*"/>
</authorization>
</system.web>
<system.webServer>
<rewrite>
<rules>
<rule name="WordPress: http://contoso.azurewebsites.net" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule>
</rules>
</rewrite>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
You are using slots incorrectly. Staging slots are not meant to be long-lived applications for testing. These are for deployment and short-automated testing of the application while you are deploying.
Also if your prod and staging slots are almost identical, what is the point of securing staging if it does the same thing as production?
And to conclude - there is no way to do what you want to do. So you might as well set up separate testing WebApp and get it secured via web.config.
There are a few ways to accomplish what you are trying to do. Although I agree with Trailmax - this seems to be a misuse of the intended purpose of slots. Remember that slots share resources (CPU, memory, etc) with your production slot. If you're using a slot for your integration and testing environments and something goes sideways, you are impacting your production resources. That's really not a good idea.
But if you want to go this route anyways, you can:
Use slots along with different build configurations and associated web.config transforms. For example, if your production site is foo.azurewebsites.net, you can define a staging slot called "staging". You can publish directly to that slot at foo-staging.azurewebsites.net. Define a separate build configuration called Staging, and create a web.staging.config transform that updates the underlying web.config to the values you want to deploy to your staging slot. Make sure that when you publish, you choose the foo-staging target, and that you choose "staging" as your build configuration.
If the environments differ by AppSettings and ConnectionStrings, define slot-specific values in the Web App's Application Settings section. These override whatever is in web.config. This is my personal favorite approach.

Configure Azure App Service without public URL

I am trying to deploy an Azure App Service from Visual Studio 15.2. Specifically I am trying to deploy this following service: https://github.com/Microsoft/Azure-SQL-DB-auditing-OMS-integration to ingest audit logs from SQL Data Warehouse to OMS. However, due to security concerns, we would like to do so without creating a public endpoint, a url. We have tried configuring it in a VNet but it does not allow you to do so unless the VNet has a public gateway.
Configure Azure App Service without public URL
As far as I know, we couldn't configure Azure App Service without public URL. If you created a web app, it will auto provide public endpoint for user to access.
Here are two work around.
I found the github application just use the web app's webjobs.
One way:
If you don't need any web site, just use the backgourd process to run the webjobs, you could choose azure function which uses WebJobs SDK itself but doesn't require an App Service to be configured for it.
Second way:
Normally we run WebJobs in a Azure App Service web app, and that Azure App Service web app can be accessed/browsed via URL. If you want to prevent users from browsing to that Azure App Service web app, you can add a rewrite rule to site’s web.config to block web access.
The web.config is like this:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Block unauthorized traffic to staging sites" stopProcessing="true">
<match url=".*" />
<conditions>
<!-- Enter your staging site host name here as the pattern-->
<add input="{HTTP_HOST}" pattern=".*" />
<!-- Enter your white listed IP addresses -->
<add input="{REMOTE_ADDR}" pattern="123\.123\.123\.1" negate="true"/>
<!-- Add the white listed IP addresses with a new condition as seen below -->
<!-- <add input="{REMOTE_ADDR}" pattern="123\.123\.123\.2" negate="true"/> -->
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden"
statusDescription="Site is not accessible" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
More details about how to add the web.config to your web app, you could follow this steps:
1.Open kudu tool in web portal.
2.Open cmd console and locate the \site\wwwroot folder.
3.Create web.config and copy the settings in it.
4.When we accessed the web site, you could find this:

Azure Web App - Prevent routing to specific instances

We are hosting an ASP.NET Core application on an Azure App Service (Web Apps).
Our individual instances take some time to "preload" the required data needed to process requests. But when scaling out, requests will be routed to the instances still being prepared.
How does the App Service load balancer decide when an instance is ready and requests can be routed to it? Is there a way to prevent routing to some specific instance until we deem it ready?
Try using the applicationInitialization node in your web.config. This instructs IIS to to issue warm-up requests to URLs that you designate before the application receives its first request.
I have used this on slow swaps before. But from reading the docs on IIS here, it looks like it'll also work for new instances. I haven't tried this when scaling out though - let me know if this works for you.
Here's example code of using it within the web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<applicationInitialization>
<add initializationPage="/pagetowarmup1.php" />
<add initializationPage="/pagetowarmup2.php" />
<add initializationPage="/pagetowarmup3.php" />
</applicationInitialization>
</system.webServer>
</configuration>

DOS Protection in Azure Web APP

We are using Azure Web APP for for our FrontEnd site. Recently we have discovered DOS attack on our website. When I googled around I got to know solution for Azure Cloud Services. Is there any way, Azure Web APP can be protected with out of box support..
Azure Web Sites enabled the Dynamic IP Restrictions module for IIS8.You can protect your Azure Web App from DDOS Attacks by configuring Dynamic Ip Security under System.WebServer in your App's web.config file as follows.
<security>
<dynamicIpSecurity denyAction="NotFound">
<!--<denyByConcurrentRequests enabled="true" maxConcurrentRequests="20" />-->
<denyByRequestRate enabled="true" maxRequests="20" requestIntervalInMilliseconds="5000"/>
</dynamicIpSecurity>
</security>
Read Reference For More Information
https://azure.microsoft.com/fr-fr/blog/confirming-dynamic-ip-address-restrictions-in-windows-azure-web-sites/

Resources