Lab Setup
Follow these steps to deploy the resources used in the lab:
-
Open the Azure portal at
https://portal.azure.comand sign in with User1. -
In the portal search bar, find and open Deploy a custom template.
-
Select Build your own template in the editor, and then select Load file.
-
Select lab-4c-setup.json from the F:\AllFiles\Lab-4C folder on the lab VM, and then select Save.
-
On the Basics page, confirm Location is set to
centralus. -
Select Review + create, and then select Create.
-
Wait until the deployment shows Succeeded before continuing.
===
Secure Azure App Services and API Management
A security assessment identified multiple web application platform gaps in your environment:
- No blocking WAF policy is enforced for inbound web traffic.
- App Service and Function App endpoints allow broad access.
- API calls are accepted without subscription key enforcement.
In this lab, you will validate WAF behavior in detection mode, switch to prevention mode, enforce Microsoft Entra authentication, apply network restrictions, and require subscription key protection in APIM.
In this lab, you will:
- Validate WAF detection mode logging.
- Switch WAF from detection to prevention and confirm request blocking.
- Enable Entra authentication (Easy Auth) for an App Service.
- Restrict network access to App Service and Function App.
- Configure subscription-required access in API Management.
- Validate key-required API behavior.
This exercise should take approximately 60 minutes to complete.
Note: This lab uses the fixed Application Gateway
sc500-lab4c-agwand generated services whose names begin withsc500-lab4c-apim-,sc500-lab4c-webapp-, andsc500-lab4c-func-. Throughout the lab,<apim-name>,<web-app-name>, and<function-app-name>refer to those resources. Thesc500-lab4c-rgresource group contains exactly one of each service type.
Review the Preconfigured State
-
In the Azure portal, open Resource groups and select sc500-lab4c-rg.
-
Confirm the following resources are present:
- sc500-lab4c-agw
-
From the resource list, select sc500-lab4c-waf.
-
On the Overview page, confirm that Policy mode is set to Detection.
Validate WAF Detection Mode
-
In the Azure portal, search for and select Application gateways, then select sc500-lab4c-agw.
-
On the Overview page, copy the Frontend public IP address.
-
Open Cloud Shell in the Azure portal.
-
Send a test request using the Application Gateway public endpoint and a SQL-injection-style payload:
curl -H "X-Scan-Test: 1" "http://<agw-public-ip>/?id=1+UNION+SELECT+NULL,username,password+FROM+users--"Note: Replace
with the Frontend public IP address of your Application Gateway before running the command. -
In the Azure portal search bar, search for and select Log Analytics workspaces.
-
Select sc500-lab4c-log, then from the left menu, select Logs.
-
Close the Queries dialog if it appears.
Note: If Agent mode is On, switch the Agent toggle to Off before continuing.
-
In the upper-right corner of the page, select the mode dropdown and switch from Simple mode to KQL mode. This opens the KQL query editor.
-
Run a query similar to the following to confirm WAF logged the request:
AzureDiagnostics | where ResourceType == "APPLICATIONGATEWAYS" | where requestUri_s contains "UNION" | sort by TimeGenerated desc -
Wait up to 10 minutes for diagnostic data to arrive. Re-run the query every 1-2 minutes until the request appears.
-
Confirm that the request was logged while the WAF policy was in Detection mode.
Switch WAF to Prevention Mode and Re-test
-
In the Azure portal, search for Web Application Firewalls, then select Web Application Firewall policies (WAF) from the search results.
-
Select sc500-lab4c-waf.
-
At the top of the Overview page, select Switch to prevention mode.
-
Confirm that Policy mode changes from Detection to Prevention.
-
Run the same
curltest again from Cloud Shell:curl -H "X-Scan-Test: 1" "http://<agw-public-ip>/?id=1+UNION+SELECT+NULL,username,password+FROM+users--"Note: Replace
with the Frontend public IP address of your Application Gateway before running the command. -
Confirm the request is blocked (typically HTTP 403).
-
Record the result in your notes:
Test Expected result Detection mode request Logged, not blocked Prevention mode request Blocked (HTTP 403)
Enable App Service Authentication
-
In the Azure portal, search for and select App Services, then select
. -
In the left navigation menu, expand Settings, select Authentication, and then select Add identity provider.
-
For Identity provider, select Microsoft.
-
Configure the provider:
Setting Value Tenant configuration Workforce configuration (current tenant) App registration type Create new app registration Client secret expiration 90 days (3 months) Supported account types Current tenant - Single tenant Restrict access Require authentication Unauthenticated requests HTTP 302 Found redirect Redirect to Microsoft -
Select Add. Confirm the Microsoft identity provider is listed and authentication is enabled.
-
If provider creation fails or the page reports a missing secret, use Cloud Shell to configure the same provider. Replace
<web-app-name>with the generated App Service name:WEB_APP_NAME='<web-app-name>' TENANT_ID=$(az account show --query tenantId -o tsv) APP_URL="https://$WEB_APP_NAME.azurewebsites.net" APP_ID=$(az ad app create \ --display-name "$WEB_APP_NAME-auth" \ --sign-in-audience AzureADMyOrg \ --web-redirect-uris "$APP_URL/.auth/login/aad/callback" \ --query appId -o tsv) CLIENT_SECRET=$(az ad app credential reset \ --id "$APP_ID" \ --append \ --display-name app-service-auth \ --query password -o tsv) test -n "$APP_ID" || { echo "The app registration could not be created."; exit 1; } test -n "$CLIENT_SECRET" || { echo "The client secret could not be created."; exit 1; } az webapp config appsettings set \ --resource-group sc500-lab4c-rg \ --name "$WEB_APP_NAME" \ --settings MICROSOFT_PROVIDER_AUTHENTICATION_SECRET="$CLIENT_SECRET" \ --output none SUBSCRIPTION_ID=$(az account show --query id -o tsv) AUTH_BODY=$(jq -n \ --arg clientId "$APP_ID" \ --arg issuer "https://sts.windows.net/$TENANT_ID/v2.0" \ '{properties:{platform:{enabled:true,runtimeVersion:"~1"},globalValidation:{requireAuthentication:true,unauthenticatedClientAction:"RedirectToLoginPage",redirectToProvider:"azureactivedirectory"},identityProviders:{azureActiveDirectory:{enabled:true,registration:{openIdIssuer:$issuer,clientId:$clientId,clientSecretSettingName:"MICROSOFT_PROVIDER_AUTHENTICATION_SECRET"}}},login:{tokenStore:{enabled:true}}}}') az rest --method put \ --uri "https://management.azure.com/subscriptions/$SUBSCRIPTION_ID/resourceGroups/sc500-lab4c-rg/providers/Microsoft.Web/sites/$WEB_APP_NAME/config/authsettingsV2?api-version=2022-03-01" \ --body "$AUTH_BODY" \ --output none az rest --method get \ --uri "https://management.azure.com/subscriptions/$SUBSCRIPTION_ID/resourceGroups/sc500-lab4c-rg/providers/Microsoft.Web/sites/$WEB_APP_NAME/config/authsettingsV2?api-version=2022-03-01" \ --query '{Enabled:properties.platform.enabled,UnauthenticatedAction:properties.globalValidation.unauthenticatedClientAction}' \ --output table unset CLIENT_SECRET AUTH_BODY -
Wait up to 2 minutes for authentication settings to propagate. Open the app URL in a private browser window and confirm it redirects to Microsoft sign-in.
Apply Network Restrictions to App Service and Function App
-
In
, expand Settings in the left navigation menu, and then select Networking. -
Under Inbound traffic configuration, select Enabled with no access restrictions next to Public network access.
-
On the Access Restrictions page, under Public network access, select Enabled from select virtual networks and IP addresses.
-
Under Main site, select Add.
-
On the Add rule pane, configure the following settings:
Setting Value Name Allow-AppGatewayAction Allow Priority 300Type Virtual Network Subscription Select the current subscription Virtual Network sc500-lab4c-vnet Subnet agw-subnet -
Select Add rule.
-
For Unmatched rule action, select Deny.
-
Select Save. On the Access update confirmation, select the confirmation checkbox, and then select Continue.
-
In the Azure portal, search for and select Function Apps, and then select
. -
In the left navigation menu, expand Settings, and then select Networking.
-
Under Inbound traffic configuration, select Enabled with no access restrictions next to Public network access.
-
On the Access Restrictions page, under Public network access, select Enabled from select virtual networks and IP addresses.
-
Under Main site, select Add, and configure the rule as follows:
Setting Value Name Allow-FunctionSubnetAction Allow Priority 300Type Virtual Network Subscription Select the current subscription Virtual Network sc500-lab4c-vnet Subnet func-allowed-subnet -
Select Add rule.
-
For Unmatched rule action, select Deny, and then select Save.
-
On the Access update confirmation page, select the confirmation checkbox, and then select Continue.
Enforce Subscription Key Protection in API Management
-
In the Azure portal, search for and select API Management services, and then select sc500-lab4c-apim-XXXX.
-
In the left navigation menu, expand APIs, select APIs, and then select Lab 4C API.
-
Select Settings, set Subscription required to Required, and then select Save.
-
In the left navigation menu, under APIs, select Subscriptions. Create a test subscription if needed, or open an existing subscription, and copy one of its subscription keys.
-
Return to APIs > Lab 4C API, select the Test tab, and then select Get Status.
-
Under Headers, select + Add header, and enter the following:
Setting Value Name Ocp-Apim-Subscription-KeyValue Paste the subscription key copied in the previous step -
Select Send and confirm that the request returns HTTP 200.
-
Test without a valid subscription key. In the Headers section, clear the value of the Ocp-Apim-Subscription-Key header or replace it with an invalid key, and then select Send. Confirm that API Management returns HTTP 401 Access Denied.
-
Record the results in your notes:
Request type Expected result With key HTTP 200 Without key HTTP 401
Summary
In this lab, you implemented layered controls for web and API workloads:
- WAF inspection and active blocking with prevention mode.
- Identity enforcement with Entra authentication for App Service.
- Network narrowing for App Service and Function App.
- API admission control through APIM subscription keys.
These controls reduce exploitability, limit unauthenticated access paths, and enforce policy at both network and application layers.