131 Continental Drive
Suite 305
Newark, DE 19713
United States
SCO 515, Third Floor
Sector 70, Mohali
Punjab, 160055
Follow Us on Social -

Configuring Conditional Access Policy to Restrict Access From Specific IP or Location

This blog is about how to restrict access to any application from different office locations in the world by using conditional access policies in Microsoft Azure. We are using specific IP address ranges to identify and name our office locations.

What is Conditional Access?

Conditional access is a set of policy configurations which controls what devices and users can have access to different applications. Specifically talking about Microsoft environment, conditional access policies work with Office 365 and other Software-as-a-Service (SaaS) applications configured in Azure Active Directory.

In simplest term, conditional access policies are if-then statements i.e., if a condition is met, then the necessary action can be taken for that condition. Example: A user wants to access any Office 365 application and is required to perform multi-factor authentication (MFA) to access it.


In this blog, I will demonstrate how to restrict access to different applications from different IP addresses based upon the location of the offices.

Consider that there are three physical offices of an organization, one in USA, one in Canada and one in India. Each office has two different Internet Service Providers where each ISP provides 5 static public IPs to the office location. This means that a single office is provided with a total of 10 public IPs. Based on this setup we will implement the following scenarios:

  • SharePoint Online should be accessible through US office location and restricted for Canada and India.
  • Exchange Online should be accessible through Canada office location and restricted for US and India.
  • PowerBI should be accessible through India office location and restricted for Canada and US.
  • Users should not be prompted for Multi Factor Authentication if they are coming from known office locations.

Note: This is just an arbitrary scenario for our demo purposes for writing this blog to showcase the capabilities. You can learn the implementation aspect and tweak your scenarios according to your requirements.


  • An active Azure subscription with Global Administrator role.
  • At least an Azure AD premium P1 license, if additional enhanced and security features are required you can compare the licenses here.
  • Three non-administrator test users whose password you know.


Named Locations

Before setting up our conditional access policy, we need to define named locations. This can be done by logging into Azure portal under Azure Active Directory > Security > Conditional Access > Named Locations.

We will configure three named locations by adding public IP addresses of the respective offices:


Note: - We are taking arbitrary IPs in this case by picking a range from defined public IP addresses range for all the three countries. If you are implementing for your scenario, make sure to change the IP addresses according to your requirements.

IP Addresses

For restricting access from a specific IP address range, click on ‘IP ranges location’ to add an IP address range from where you want to block or restrict access to your application.

To define a named location by IPv4/IPv6 address, one needs to provide:

  • Name for the location
  • One or more IP (IPv4 or IPv6) ranges (in CIDR notation)


Login to Azure Portal, then navigate to Azure Active Directory > Security > Conditional Access > Named Locations.

     1. Click on ‘IP ranges location’ to add IPs and enter the name of the Location as shown below:


     2. Click on ‘+’ button to add IP address in CIDR format and click Add, to add more than one IP click on plus button again.


     4. Finally click on create and you will have your IP ranges and your location defined.


We have configured and shown the named location only for Canada. Adding IP range would be the same procedure for USA as well as India as shown above.

MFA Trusted IP’s

To grant access from the given set of public IP addresses without requiring multi factor authentication, we will add range of IPs for trusted MFA’s specifically.

To configure MFA trusted IPs, login to Azure Portal > Azure Active Directory > Security > Conditional Access > Named Locations > Configure MFA Trusted IPs.

  1. Once you click on ‘Configure MFA trusted IPs’, you will be prompted to a new page where the required configurations can be done. Enter IPs in the text field area.
  1. Click Save.


As a result, the users trying to access application from the IPs defined in the trusted range will skip MFA and will be granted access by only entering their username and password.


We can restrict access with respect to country as well. But in our situation, it is not required as we have already setup the named location for IP addresses. All other IP’s or countries will be restricted access automatically. Therefore, there is no need to setup the named location for country.

Defining named location for country varies from case to case, still I will be showing how you can configure it if required. For restricting/allowing access from a country, we will first go to named locations and then click on ‘countries location’ to add countries.

To define a named location by country, login to azure portal > Azure Active Directory > Security > Conditional Access > Named Locations > Configure MFA Trusted IPs. an individual needs to enter:

  1. Name of the location/country.

     2. Select the country/countries you wish to block/allow access and click Create.


Conditional Access Policy:

Now that we have setup the named locations for IP address, we will be configuring the conditional access policy. To create a new conditional access policy, login and go to Azure Portal > Azure Active Directory > Security > Conditional Access > Policies.

To configure a conditional access policy, we need to define:

  • A name for the Policy
  • Which users this policy needs to be assigned to
  • Select an application on which action will be performed.
  • Conditions which will apply
  • Access Controls
    • Grant or Block Access
    • Session to configure sign-in frequency and using app enforced restrictions.

Note: Make sure that you do not assign the policy to all users and administrators at once. Always assign the policy to some users with no assigned roles first, enable policy in Report-only mode to test and make sure the policy works as expected. Otherwise, you have the potential to lock yourself out.

To know more about all other components, you can check out the Microsoft’s official conditional access documentation.

SharePoint Online should be accessible through US office location and restricted for Canada and India.

     1. Log in to azure, go to Azure Active Directory > Security > Conditional Access > Policies. Click ‘New Policy’ to create a new conditional access policy.


     3. Name the policy.


     4. Select the user(s) to whom this policy should be applied.

Users and Groups > Select users and groups > search a name of user/group. Click Select.


     5. Select the condition for location.

         i. Click on Condition.

        ii. Click Location

        iii. Select yes to configure (i.e., include/exclude locations from this policy).


     6. Include location.

Select any location.


     7. Exclude the named locations.

Selected Locations Name: USA


     8. Under Access Controls, Block Access.

Select ‘Block Access’ radio button.


     7. All configurations are done, now we need to enable and create the policy.

Enable Policy: Report-Only or On

Click Create


Simply put, this whole configuration means that if specified users are trying to access SharePoint Online from any other location than USA, they will not be granted access.

Exchange Online should be accessible through Canada office location and restricted for US and India.


Similarly, in this case, we did the same configurations as previous one with the difference that here the application is Exchange Online, we are excluding ‘Canada’ and including both ‘India and USA’. This policy will allow users in Canada office to access Exchange Online whereas users of India and USA will be restricted from accessing it.

PowerBI should be accessible through India office location and restricted for Canada and US.


Equivalently, the same configuration with the difference being that application this time is PowerBI service, we are excluding ‘India’ whereas including ‘USA & Canada’ under locations. As a result, this policy will allow users in India office to have access to PowerBI service and the employees of USA and Canada would not.


Let us try to access SharePoint Online from USA, Canada, and India. As per the policy created by us, one should be granted access while trying to access the application from USA office network. Whereas the access should be restricted for users trying to access it from Canada and India offices.

  • Accessing SharePoint Online from USA office network:

           SharePoint Online is accessible

  • Accessing SharePoint Online from India and Canada office:

SharePoint Online access is restricted.

  • Accessing Exchange Online from Canada office:
  • Accessing Exchange Online from India and USA office:
  • Accessing PowerBI Service from India Office:
  • Accessing PowerBI Service from USA and Canada Office:

Users trying to access Exchange Online (from Canada office), and PowerBI service (from India office) consequently, will be allowed to sign into the applications. Contrarily, if they trying to sign into Exchange Online (from USA or India office), and PowerBI service (from USA or Canada office), they will be shown a common error message.

Therefore, the policy is successfully implemented, and we secured access to the applications from defined locations only. Access from all other locations and IPs not defined is blocked.

What if someone tries to access applications from any other non-windows device? The error message would remain the same except the changes in the user interface.

Written By
Raghav Jain
Raghav Jain
Cloud Security Engineer
peer reviewed By
JAsjit Chopra
chief executive officer
Graphics designed By
Sanika Sanaye
sanika sanaye
Creative Design Director
Recommended Content

Email Insights

Get the latest updates from Penthara right in your mail box.
Sign Up

LinkedIn Newsletter

Monthly updates, news & events from Microsoft to help  your business grow.
Subscribe To Newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *

4 comments on “Configuring Conditional Access Policy to restrict access from specific IP or Location”

  1. Country based policies are ok, but those can be easily defeated by using VPN service. Is there a way to block all connections coming via VPN like Nordvpn etc? I have not found any solution.

    1. Unfortunately - unless you can find out which IP addresses a particular VPN service uses on the public side - one cannot put this kind of filter in place.

    1. Unfortunately this can only be achieved via Windows 365 for Enterprise edition where traffic can be run through your Azure Vnet in you rtenant

More From This Category

Stay Ahead of Threats with Microsoft Copilot for Security - What You Need to Know

Cybersecurity threats are constantly evolving, keeping IT professionals on their toes. But what if you had a powerful AI assistant by your side, proactively hunting threats and simplifying security operations? Enter Microsoft Copilot for Security, a game-changer in the cybersecurity landscape.

Read More
9 Essential Insights from the Microsoft Digital Defense Report 2023

The article outlines 9 key insights from the 2023 Microsoft Digital Defense Report, including topics such as basic security practices, ransomware trends, password attacks, BEC incidents, nation-state targeting, IoT/OT vulnerabilities, AI-powered cyberattacks, and supply chain risks.

Read More
Top 5 Configurations to Improve Identity Secure Score

In this blog, we will discuss the overview of Identity Secure Score in Azure AD and the top 5 configurations that will improve your Secure Score. These recommendations come from working in the Azure AD security space for multiple years across different industry verticals.

Read More