02.08.2021

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.
SHARE THIS BLOG:
Table of contents
1. What is Conditional Access?
2. Setup
• Prerequisites
3. Configurations
• Named Locations
• IP Addresses
• MFA Trusted IP’s
• Countries
4. Conditional Access Policy
• SharePoint Online should be accessible through US office locations 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 the US
5. Outcome

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.

Setup

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.

Prerequisites

  • 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.

Configurations

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:

ScenarioDiagram

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:

locationName

     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.

addip

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

createip

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.

Want to secure your applications with precise access controls? Reach out to us for professional support!

Countries

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.
namecountry

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

createcountry

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.

newpolicy

     3. Name the policy.

assignuserpolicy

     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.

selectapppolicy

     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).

includelocationpolicy

     6. Include location.

Select any location.

anylocation

     7. Exclude the named locations.

Selected Locations Name: USA

usapolicy

     8. Under Access Controls, Block Access.

Select ‘Block Access’ radio button.

blockacceesspolicy

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

Enable Policy: Report-Only or On

Click Create

createpolicy

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

exchangepolicy

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

powerbipolicy

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.

Outcome

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

spaccessgranted
  • Accessing SharePoint Online from India and Canada office:

SharePoint Online access is restricted.

sprestrictaccess
  • Accessing Exchange Online from Canada office:
outlookaccessgranted
  • Accessing Exchange Online from India and USA office:
Outlookrestrictaccess
  • Accessing PowerBI Service from India Office:
PowerBI
  • Accessing PowerBI Service from USA and Canada Office:
powerbirestrictedaccess

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.

Need expert help with Azure and conditional access configurations? Contact us to get started!

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

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

Managing Security Roles in Power Apps: Part 2

This blog explores three methods to manage security roles in PowerApps: using multiple SharePoint lists, SharePoint Groups, and item-level permissions. Each method offers unique advantages for role-based access control, ensuring sensitive data is accessible only to authorized users. Step-by-step guidance is provided for setting up these methods and integrating them within PowerApps to enhance data security and streamline app development.

Read More
Managing Security Roles in Power Apps: Part 1

This blog explores three methods to manage security roles in PowerApps: using multiple SharePoint lists, SharePoint Groups, and item-level permissions. Each method offers unique advantages for role-based access control, ensuring sensitive data is accessible only to authorized users. Step-by-step guidance is provided for setting up these methods and integrating them within PowerApps to enhance data security and streamline app development.

Read More
Top Strategies to Optimize Your Microsoft 365 Security Posture for Maximum Protection

Explore top strategies to optimize your Microsoft 365 security posture for maximum protection. This blog provides insights into the evolving threat landscape, the importance of enhancing security posture, and practical strategies to strengthen your M365 environment. Learn about common threats, the role of multi-factor authentication, data loss prevention, regular security audits, and the importance of user education. The blog also includes real-world examples of security breaches and case studies demonstrating the effectiveness of robust security measures.

Read More
1 2 3
chevron-right