A Beginner's Guide To Role-Based Access Control on Azure.
Tags: beginners, azure, ops, security
Published: 2020-05-02 14:45:19

When creating access to systems, applications and environments it's important to keep security top of mind.  Even working at a rapid pace it's important to consider what credentials and access we give to a resource.  Examples of this kind of administration of roles could be access to a Windows Server or providing pull access to a Docker image from an Azure Kubernetes Cluster.  These types of actions require some form of authentication and authorization in order to provide access.

This guide provides you some information on getting started on understanding Azure RBAC with many of the articles you can find on [Microsoft Docs](https://docs.microsoft.com/?WT.mc_id=rbac-devto-jagord) and [Microsoft Learn.](https://docs.microsoft.com/learn/modules/secure-azure-resources-with-rbac/?WT.mc_id=rbac-devto-jagord)

## Defining the difference 

Authorization and Authentication are the cornerstones of security for computing.  Before we dig into examples, let's just define the words from Webster's dictionary.

[Authentication](https://www.merriam-webster.com/dictionary/authentication): *an act, process, or method of showing something (such as an identity, a piece of art, or a financial transaction) to be real, true, or genuine : the act or process of authenticating something*

[Authorization](https://www.merriam-webster.com/thesaurus/authorization): *The granting of power to perform various acts or duties*

To think about this in a practical sense, consider the hierarcy of a [Wordpress](https://wordpress.org/) CMS set of [user roles](https://wordpress.org/support/article/roles-and-capabilities/). 

From Wordpress Docs, [Summary of Roles](https://wordpress.org/support/article/roles-and-capabilities/#summary-of-roles)

- [Super Admin](https://wordpress.org/support/article/roles-and-capabilities/#super-admin) – somebody with access to the site network administration features and all other features. See the [Create a Network](https://wordpress.org/support/article/create-a-network/) article.
- [Administrator](https://wordpress.org/support/article/roles-and-capabilities/#administrator)  – somebody who has access to all the administration features within a single site.
- [Editor](https://wordpress.org/support/article/roles-and-capabilities/#editor) – somebody who can publish and manage posts including the posts of other users.
- [Author](https://wordpress.org/support/article/roles-and-capabilities/#author) – somebody who can publish and manage their own posts.
- [Contributor](https://wordpress.org/support/article/roles-and-capabilities/#contributor) – somebody who can write and manage their own posts but cannot publish them.
- [Subscriber](https://wordpress.org/support/article/roles-and-capabilities/#subscriber)  – somebody who can only manage their profile.

![How-To-Create-Custom-User-Roles-In-WordPress-1](https://tva1.sinaimg.cn/large/007S8ZIlgy1geeh52kfrmj30hw0600tg.jpg)

When a user **authenticates** into Wordpress, the SQL database where user roles are stored then determines what rights the user will have when logged in.  

The Administrator user may be responsible for maintenance of plug-ins for the website.  The admin would like to avoid users who are not part of the website maintenance plan to be able to install, delete or modify any of the plug-ins.  By ensuring all of these users have a role that does not permit these rights, our website remains more reliable due to unplanned maintenance.  The contributor role appears to be what's right:

```
Contributor #Contributor
delete_posts
edit_posts
read
read Reusable Blocks
```

In this case, the contributor role for someone who may be just posting new content update may make sense due to the specific set of roles the user is **authorized** to do.

## RBAC for Azure

Role-Based Authentication (RBAC) is an authorization system built on [Azure Resource Manager](https://docs.microsoft.com/azure/azure-resource-manager/management/overview?WT.mc_id=rbac-devto-jagord) that provides fine-grained access management of Azure resources.

Access management via RBAC on Azure allows you to better control the scope of what your users and applications can access along with what they authorized to do.

## What can I do with RBAC?

[Here are some examples of what you can do with RBAC:](https://docs.microsoft.com/azure/role-based-access-control/overview?WT.mc_id=rbac-devto-jagord#what-can-i-do-with-rbac)

- Allow one user to manage virtual machines in a subscription and another user to manage virtual networks
- Allow a DBA group to manage SQL databases in a subscription
- Allow a user to manage all resources in a resource group, such as virtual machines, websites, and subnets
- Allow an application to access all resources in a resource group



## Fundamentals 

The way you control access to resources using RBAC is to create role assignments. This is a key concept to understand – it's how permissions are enforced. A role assignment consists of three elements: security principal, role definition, and scope. 

![rbac-security-principal](https://tva1.sinaimg.cn/large/007S8ZIlgy1geeh51y8awj308j03mjrg.jpg)

- User - An individual who has a profile in Azure Active Directory. You can also assign roles to users in other tenants. For information about users in other organizations, see [Azure Active Directory B2B](https://docs.microsoft.com/en-us/azure/active-directory/b2b/what-is-b2b).
- Group - A set of users created in Azure Active Directory. When you assign a role to a group, all users within that group have that role.
- Service principal - A security identity used by applications or services to access specific Azure resources. You can think of it as a *user identity* (username and password or certificate) for an application.
- Managed identity - An identity in Azure Active Directory that is automatically managed by Azure. You typically use [managed identities](https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview) when developing cloud applications to manage the credentials for authenticating to Azure services.

![check-access-select](https://tva1.sinaimg.cn/large/007S8ZIlgy1geeh51b1ymj30b10bj0t8.jpg)

## Azure RBAC roles

Azure includes several [built-in roles](https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles) that you can use. The following lists four fundamental built-in roles. The first three apply to all resource types.

- [Owner](https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#owner) - Has full access to all resources including the right to delegate access to others.
- [Contributor](https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#contributor) - Can create and manage all types of Azure resources but can't grant access to others.
- [Reader](https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#reader) - Can view existing Azure resources.
- [User Access Administrator](https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#user-access-administrator) - Lets you manage user access to Azure resources.

![check-access-assignments](https://tva1.sinaimg.cn/large/007S8ZIlgy1geeh4zzn60j30uc0bv3zx.jpg)

Different Azure resources also have built in roles to ensure secure access.

By using RBAC we can ensure our DBA can log just into the development and UAT of our [Azure SQL Database managed instances](https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance?WT.mc_id=rbac-devto-jagord). We can assign them them with a the built in SQL Managed Instance Contributor role. This role permits users to manage SQL servers and databases, but not access to them, and not their security-related policies.  

## How RBAC determines if a user has access to a resource

The following are the high-level steps that RBAC uses to determine if you have access to a resource on the management plane. This is helpful to understand if you are trying to troubleshoot an access issue.

1. A user (or service principal) acquires a token for Azure Resource Manager.

   The token includes the user's group memberships (including transitive group memberships).

2. The user makes a REST API call to Azure Resource Manager with the token attached.

3. Azure Resource Manager retrieves all the role assignments and deny assignments that apply to the resource upon which the action is being taken.

4. Azure Resource Manager narrows the role assignments that apply to this user or their group and determines what roles the user has for this resource.

5. Azure Resource Manager determines if the action in the API call is included in the roles the user has for this resource.

6. If the user doesn't have a role with the action at the requested scope, access is not granted. Otherwise, Azure Resource Manager checks if a deny assignment applies.

7. If a deny assignment applies, access is blocked. Otherwise access is granted.

## Next Steps

You may want to learn more and get started you've got so many resources.

Check out these links:

 * [What is role-based access control (RBAC) for Azure resources?](https://docs.microsoft.com/azure/role-based-access-control/overview?WT.mc_id=rbac-devto-jagord)
 * [Create custom roles for Azure resources with role-based access control (RBAC)
](https://docs.microsoft.com/learn/modules/create-custom-azure-roles-with-rbac/?WT.mc_id=rbac-devto-jagord)
 * [Get $200 in Azure Credit](https://azure.microsoft.com/free/?WT.mc_id=rbac-devto-jagord)


{% youtube FKBoWWKRnvI %}