基本
云平臺資源的接入管理(access management)對于任何使用云的組織都是一個至關(guān)重要的功能。Azure的基于角色的接入控制(RBAC)幫用戶管理了,1) 誰可以接入Azure資源,2)可以用這些資源做什么,3)可以接入哪些資源。
Azure的RBAC是建立在Azure資源管理器之上得到授權(quán)系統(tǒng)(authorisation system),為Azure 資源提供了精細(xì)化的接入管理。
RBAC的具體案例如下:
- 允許一個用戶管理訂閱(subsription)的虛擬機(VM),以及另一個用戶管理虛擬網(wǎng)絡(luò)(VN)
- 允許一個DBA組管理訂閱中的SQL數(shù)據(jù)庫
- 允許一個用戶管理一個資源組(resourece group)中的所有資源,比如VM,網(wǎng)頁和子網(wǎng)
- 允許一個應(yīng)用接入一個資源組的所有資源
RBAC如何工作
使用RBAC做資源接入控制的方式是分配Azure角色,也就是如何執(zhí)行和賦予權(quán)限(permission)。角色分批包括三個元素,1) security principal,2) role defition角色定義,和3) scope。
-
security principal:代表了用戶、組、service principal或者managed identity中的任意一個對象,該對象申請接入Azure資源。可將一個角色分配給任何一個security principals。其中的managed identity是用Azure自動管理的有Entra ID的個體。
rbac-security-principal.png -
角色定義:是權(quán)限的合集(a collection of permission),一般被稱作一個角色(role)。角色定義列出了可以執(zhí)行的動作,比如讀、寫、刪除。角色可以是high level的,如所有者(owner),或比較具體的,VM的使用者
rbac-role-definition.png
Azure引入多個內(nèi)建的角色。比如VM貢獻(xiàn)者,允許用戶創(chuàng)建和使用VM。如果內(nèi)建角色無法滿足用戶需求,可定制化角色。
Azure可在對象內(nèi)部賦給數(shù)據(jù)的接入權(quán)限,比如一個用戶有一個存儲賬戶的讀權(quán)限,該用戶可讀該存儲張的blobs或消息。
- Scope:Scope是接入應(yīng)用的一系列資源(a set of resourcess that the access applies to)。分配角色時,可進(jìn)一步限制角色的動作,該限制由scope提供。比如賦予某人website貢獻(xiàn)者的角色,但僅限于在一個resource group中有效。
Azure中可指定的scope分為四級:1. management group, 2. subscription, 3. resource group, 4. resource。Scope以母子關(guān)系組織,可在任何一級分配角色。
(2024.06.24 Mon @KLN)
-
角色分配(role assignment):角色分配是將角色定義與用戶、組、service principal或managed identity在特定scope上為了賦予接入權(quán)限(grant access)而綁定的過程。創(chuàng)建角色分配,則授予了接入權(quán)限;移除角色分配則收回權(quán)限(revoke access)。
下圖展示了角色分配的案例。營銷組(marketing groupp)被分配了藥品銷售(pharma-sales)資源組中的Contributor角色,也就說營銷組中的用戶可在藥品銷售資源組中創(chuàng)建和管理任何Azure資源。營銷組成員用戶不能接入/使用藥品銷售資源組以外的資源,除非被分配了對應(yīng)的角色。
rbac-role-assignment-overview.png
分配角色的方式包括,Azure portal, Azure CLI,Azure PowerShell,Azure SDKs,或REST APIs。
組群Group:對組群來說,角色分配有穿透性(transitive),也就是一個用戶是某組群A
的成員,而組群A是另一個組群B的成員,組群B有角色分配,則該用戶也擁有組群B的角色分配。-
多角色分配:如果用戶被分配了重疊的角色(overlapping role assignments)會出現(xiàn)什么結(jié)果?Azure RBAC是加性模型(additive model),有效的權(quán)限是角色分配之和。在下面案例中,一個用戶在subscription scope被分配了Contributor角色,在resource group scope中被分配了Reader角色。兩者之后也就是在subscription的Contributor角色,也就是Reader角色沒有影響。
rbac-multiple-roles.png
Role Definition
(2024.06.25 Tues)
角色定義,或簡稱角色(role)是一系列許可/權(quán)限的合集。角色定義列出了可以執(zhí)行的動作,如讀、寫、刪除,也列出了不可以對底層數(shù)據(jù)進(jìn)行的動作。
在用Azure PowerShell顯示時,角色定義包含下列字段:
- Name
- Id
- IsCustom
- Description
- Actions []
- NotActions []
- DataActions []
- NotDataActions []
- AssignableScopes []
- Condition
- ConditionVersion
用REST APIs或AZURE CLI顯示,角色定義包含下列字段:
- roleName
- name
- id
- roleType
- type
- description
- actions []
- notActions []
- dataActions []
- notDataActions []
- assignableScopes []
- condition
- conditionVersion
- createdOn
- updatedOn
- createdBy
- updatedBy
案例,在Azure PowerShell下的一個contributor role,以json形式表示如下
{
"Name": "Contributor",
"Id": "b24988ac-6180-42a0-ab88-20f7382dd24c",
"IsCustom": false,
"Description": "Grants full access to manage all resources, but does not allow you to assign roles in Azure RBAC, manage assignments in Azure Blueprints, or share image galleries.",
"Actions": [
"*"
],
"NotActions": [
"Microsoft.Authorization/*/Delete",
"Microsoft.Authorization/*/Write",
"Microsoft.Authorization/elevateAccess/Action",
"Microsoft.Blueprint/blueprintAssignments/write",
"Microsoft.Blueprint/blueprintAssignments/delete",
"Microsoft.Compute/galleries/share/action",
"Microsoft.Purview/consents/write",
"Microsoft.Purview/consents/delete"
],
"DataActions": [],
"NotDataActions": [],
"AssignableScopes": [
"/"
],
"Condition": null,
"ConditionVersion": null
}
字段說明
Property | Description |
---|---|
Name /roleName
|
角色的顯示名 |
Id /name
|
該角色的唯一ID,內(nèi)建角色在云平臺內(nèi)只有一個ID |
id |
角色的fully qualified unique ID,即便該角色被改名,角色I(xiàn)D也不會變,建議在代碼中使用該id |
IsCustom /roleType
|
角色是否為自定義角色,值為true /CustomeRole 則為自定義,值為false /BuiltInRole 則為內(nèi)建角色 |
type |
對象類型,設(shè)置為Microsoft.Authorization/roleDefinitions
|
Description /description
|
角色描述 |
Actions /actions
|
指定該角色可以執(zhí)行的動作,列表形式 |
NotActions /notActions
|
指定了該角色不能執(zhí)行的動作,列表形式 |
DataActions /dataActions
|
指定了該角色可以對對象中的數(shù)據(jù)執(zhí)行的操作,列表形式 |
NotDataActions /notDataActions
|
指定了該角色不可以對對象中的數(shù)據(jù)執(zhí)行的操作,列表形式 |
AssignableScopes /assignableScopes
|
指定了角色可以分配的scope(scopes that the role is available for assignment),列表形式 |
Condition /condition
|
對于內(nèi)建角色,基于角色定義的動作的條件聲明 |
ConditionVersion /conditionVersion
|
條件版本號,默認(rèn)2.0,且為唯一支持版本 |
注意上面案例中的Actions
字段,該字段的格式如下
{Company}.{ProviderName}/{resourceType}/{action}
其中的{action}
部分指明了可以對該resourceType
執(zhí)行的動作,可能包含如下動作
Action substring | Description |
---|---|
* |
wildcard符號含所有動作 |
read |
讀(GET) |
write |
寫(PUT/PATCH) |
action |
諸如重啟VM(POST) |
delete |
刪除(DELETE) |
另一個案例,在Azure CLI中表示的角色,以json形式表達(dá)
[
{
"assignableScopes": [
"/"
],
"createdBy": null,
"createdOn": "2015-02-02T21:55:09.880642+00:00",
"description": "Grants full access to manage all resources, but does not allow you to assign roles in Azure RBAC, manage assignments in Azure Blueprints, or share image galleries.",
"id": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c",
"name": "b24988ac-6180-42a0-ab88-20f7382dd24c",
"permissions": [
{
"actions": [
"*"
],
"condition": null,
"conditionVersion": null,
"dataActions": [],
"notActions": [
"Microsoft.Authorization/*/Delete",
"Microsoft.Authorization/*/Write",
"Microsoft.Authorization/elevateAccess/Action",
"Microsoft.Blueprint/blueprintAssignments/write",
"Microsoft.Blueprint/blueprintAssignments/delete",
"Microsoft.Compute/galleries/share/action",
"Microsoft.Purview/consents/write",
"Microsoft.Purview/consents/delete"
],
"notDataActions": []
}
],
"roleName": "Contributor",
"roleType": "BuiltInRole",
"type": "Microsoft.Authorization/roleDefinitions",
"updatedBy": null,
"updatedOn": "2023-07-10T15:10:53.947865+00:00"
}
]
Scope
(2024.06.26 Wed)
scope是一系列可以使用的資源。通過限制scope,可以限制security principal使用的資源。
Management group是比subscription更高一級的scope,但management group支持更多復(fù)雜分級。下圖給出了一個management group和subscriptions的一個分級網(wǎng)絡(luò)。
一個scope的案例如下,在Azure PowerShell中表示,scope id表示成屬性的json。
RoleAssignmentId : /subscriptions/<subscriptionId>/resourceGroups/test-rg/providers/Microsoft.Storage/storageAccounts/azurestorage12345/blobServices/default/containers/blob-container-01/pro
viders/Microsoft.Authorization/roleAssignments/<roleAssignmentId>
Scope : /subscriptions/<subscriptionId>/resourceGroups/test-rg/providers/Microsoft.Storage/storageAccounts/azurestorage12345/blobServices/default/containers/blob-container-01
DisplayName : User
SignInName : user@contoso.com
RoleDefinitionName : Storage Blob Data Reader
RoleDefinitionId : 2a2b9908-6ea1-4ae2-8e65-a410df84e7d1
ObjectId : <principalId>
ObjectType : User
CanDelegate : False
Description :
ConditionVersion :
Condition :
scope的格式
如果使用命令行分配角色,需要明確scope。在命令行中,scope表示為長字符串,用于識別角色分配的精確scope。在Azure portal中scope id
往往用resource id
來表示。
scope包含了一系列的字段,用斜線/
做分割。可將該字符串想象成如下分解,其中用大括號{}
標(biāo)識的是可以自定義的內(nèi)容。
/subscriptions
/{subscriptionId}
/resourcegroups
/{resourceGroupName}
/providers
/{providerName}
/{resourceType}
/{resourceSubType1}
/{resourceSubType2}
/{resourceName}
-
{subscriptionId}
:subscription ID/GUID -
{resourceGroupName}
:包含的resource group的名字 -
{providerName}
:資源供應(yīng)者名字,對應(yīng)的后面{resourceType}
和{resourceSubType*}
提供進(jìn)一步的resource provider信息 -
{resourceName}
:特定resource的最后一部分字符串
Management groups比其他scope有著最廣泛的scope。Management group的scope有下列形式:
/providers
/Microsoft.Management
/managementGroups
/{managmentGroupName}
Steps to assign an Azure role
(2024.06.24 Mon)
- 確定誰需要access:user? group? service principal? or manged identity?這四者合稱security principal。
- 選定合適的角色:可從Azure built-in roles中找,優(yōu)先管理者角色(privileged administrator roles)包括Contributor,Owner,RBAC administrator和user access administrator。若超出built-in roles的范疇,可自定義角色。
- 確定scope
- 檢查角色和scope
- 分配角色:一旦確定了security principal,角色和scope,即可分配角色。方式包括,portal, PowerShell,CLI,SDKs和REST APIs。
每個subscription中有4000個角色分配,每個management group中有500個角色分配。具體數(shù)字可查RBAC limits。
How Azure RBAC determines if a user has access to a resource
placeholder
Reference
- Azure official website