Skip to content

Commit 019e839

Browse files
authored
Merge pull request #229359 from schaffererin/rbac-k8s-authorization
Freshness pass and addressing GitIssues
2 parents 8beb874 + 96d5e5c commit 019e839

File tree

2 files changed

+72
-104
lines changed

2 files changed

+72
-104
lines changed

articles/aks/csi-migrate-in-tree-volumes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ For more about storage best practices, see [Best practices for storage and backu
508508
509509
<!-- LINKS - internal -->
510510
[install-azure-cli]: /cli/azure/install-azure-cli
511-
[aks-rbac-cluster-admin-role]: manage-azure-rbac.md#create-role-assignments-for-users-to-access-cluster
511+
[aks-rbac-cluster-admin-role]: manage-azure-rbac.md#create-role-assignments-for-users-to-access-the-cluster
512512
[azure-resource-locks]: ../azure-resource-manager/management/lock-resources.md
513513
[csi-driver-overview]: csi-storage-drivers.md
514514
[aks-storage-backups-best-practices]: operator-best-practices-storage.md

articles/aks/manage-azure-rbac.md

Lines changed: 71 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,45 @@
11
---
2-
title: Manage Azure RBAC in Kubernetes From Azure
2+
title: Use Azure RBAC for Kubernetes Authorization
33
titleSuffix: Azure Kubernetes Service
4-
description: Learn how to use Azure RBAC for Kubernetes Authorization with Azure Kubernetes Service (AKS).
4+
description: Learn how to use Azure role-based access control (Azure RBAC) for Kubernetes Authorization with Azure Kubernetes Service (AKS).
55
ms.topic: article
6-
ms.date: 02/09/2021
6+
ms.date: 03/02/2023
77
ms.author: jpalma
88
author: palma21
99

1010
#Customer intent: As a cluster operator or developer, I want to learn how to leverage Azure RBAC permissions to authorize actions within the AKS cluster.
1111
---
1212

13-
# Use Azure RBAC for Kubernetes Authorization
13+
# Use Azure role-based access control for Kubernetes Authorization
1414

15-
Today you can already leverage [integrated authentication between Azure Active Directory (Azure AD) and AKS](managed-aad.md). When enabled, this integration allows customers to use Azure AD users, groups, or service principals as subjects in Kubernetes RBAC, see more [here](azure-ad-rbac.md).
16-
This feature frees you from having to separately manage user identities and credentials for Kubernetes. However, you still have to set up and manage Azure RBAC and Kubernetes RBAC separately. For more details on authentication and authorization with RBAC on AKS, see [here](concepts-identity.md).
15+
When you leverage [integrated authentication between Azure Active Directory (Azure AD) and AKS](managed-aad.md), you can use Azure AD users, groups, or service principals as subjects in [Kubernetes role-based access control (Kubernetes RBAC)][kubernetes-rbac]. This feature frees you from having to separately manage user identities and credentials for Kubernetes. However, you still have to set up and manage Azure RBAC and Kubernetes RBAC separately.
1716

18-
This document covers a new approach that allows for the unified management and access control across Azure Resources, AKS, and Kubernetes resources.
17+
This article covers how to use Azure RBAC for Kubernetes Authorization, which allows for the unified management and access control across Azure resources, AKS, and Kubernetes resources. For more information, see [Azure RBAC for Kubernetes Authorization][azure-rbac-kubernetes-rbac].
1918

2019
## Before you begin
2120

22-
The ability to manage RBAC for Kubernetes resources from Azure gives you the choice to manage RBAC for the cluster resources either using Azure or native Kubernetes mechanisms. When enabled, Azure AD principals will be validated exclusively by Azure RBAC while regular Kubernetes users and service accounts are exclusively validated by Kubernetes RBAC. For more details on authentication and authorization with RBAC on AKS, see [here](concepts-identity.md#azure-rbac-for-kubernetes-authorization).
21+
* You need the Azure CLI version 2.24.0 or later installed and configured. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][install-azure-cli].
22+
* You need `kubectl`, with a minimum version of [1.18.3](https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.18.md#v1183).
23+
* You need managed Azure AD integration enabled on your cluster before you can add Azure RBAC for Kubernetes authorization. If you need to enable managed Azure AD integration, see [Use Azure AD in AKS](managed-aad.md).
24+
* If you have CRDs and are making custom role definitions, the only way to cover CRDs today is to use `Microsoft.ContainerService/managedClusters/*/read`. For the remaining objects, you can use the specific API groups, such as `Microsoft.ContainerService/apps/deployments/read`.
25+
* New role assignments can take up to five minutes to propagate and be updated by the authorization server.
26+
* This article requires that the Azure AD tenant configured for authentication is same as the tenant for the subscription that holds your AKS cluster.
2327

24-
### Prerequisites
28+
## Create a new AKS cluster with managed Azure AD integration and Azure RBAC for Kubernetes Authorization
2529

26-
- Ensure you have the Azure CLI version 2.24.0 or later
27-
- Ensure you have installed [kubectl v1.18.3+][az-aks-install-cli].
28-
29-
### Limitations
30-
31-
- Requires [Managed Azure AD integration](managed-aad.md).
32-
- Use [kubectl v1.18.3+][az-aks-install-cli].
33-
- If you have CRDs and are making custom role definitions, the only way to cover CRDs today is to provide `Microsoft.ContainerService/managedClusters/*/read`. AKS is working on providing more granular permissions for CRDs. For the remaining objects you can use the specific API Groups, for example: `Microsoft.ContainerService/apps/deployments/read`.
34-
- New role assignments can take up to 5min to propagate and be updated by the authorization server.
35-
- Requires the Azure AD tenant configured for authentication to be the same as the tenant for the subscription that holds the AKS cluster.
36-
37-
## Create a new cluster using Azure RBAC and managed Azure AD integration
38-
39-
Create an AKS cluster by using the following CLI commands.
40-
41-
Create an Azure resource group:
30+
Create an Azure resource group using the [`az group create`][az-group-create] command.
4231

4332
```azurecli-interactive
44-
# Create an Azure resource group
4533
az group create --name myResourceGroup --location westus2
4634
```
4735

48-
Create the AKS cluster with managed Azure AD integration and Azure RBAC for Kubernetes Authorization.
36+
Create an AKS cluster with managed Azure AD integration and Azure RBAC for Kubernetes Authorization using the [`az aks create`][az-aks-create] command.
4937

5038
```azurecli-interactive
51-
# Create an AKS-managed Azure AD cluster
52-
az aks create -g MyResourceGroup -n MyManagedCluster --enable-aad --enable-azure-rbac
39+
az aks create -g myResourceGroup -n myManagedCluster --enable-aad --enable-azure-rbac
5340
```
5441

55-
A successful creation of a cluster with Azure AD integration and Azure RBAC for Kubernetes Authorization has the following section in the response body:
42+
The output will look similar to the following example output:
5643

5744
```json
5845
"AADProfile": {
@@ -63,68 +50,62 @@ A successful creation of a cluster with Azure AD integration and Azure RBAC for
6350
"serverAppId": null,
6451
"serverAppSecret": null,
6552
"tenantId": "****-****-****-****-****"
66-
}
53+
}
6754
```
6855

69-
## Integrate Azure RBAC into an existing cluster
56+
## Enable Azure RBAC on an existing AKS cluster
7057

71-
> [!NOTE]
72-
> To use Azure RBAC for Kubernetes Authorization, Azure Active Directory integration must be enabled on your cluster. For more, see [Azure Active Directory integration][managed-aad].
73-
74-
To add Azure RBAC for Kubernetes Authorization into an existing AKS cluster, use the [az aks update][az-aks-update] command with the flag `enable-azure-rbac`.
58+
Add Azure RBAC for Kubernetes Authorization into an existing AKS cluster using the [`az aks update`][az-aks-update] command with the `enable-azure-rbac` flag.
7559

7660
```azurecli-interactive
7761
az aks update -g myResourceGroup -n myAKSCluster --enable-azure-rbac
7862
```
79-
To remove Azure RBAC for Kubernetes Authorization from an existing AKS cluster, use the [az aks update][az-aks-update] command with the flag `disable-azure-rbac`.
63+
64+
## Disable Azure RBAC for Kubernetes Authorization from an AKS cluster
65+
66+
Remove Azure RBAC for Kubernetes Authorization from an existing AKS cluster using the [`az aks update`][az-aks-update] command with the `disable-azure-rbac` flag.
8067

8168
```azurecli-interactive
8269
az aks update -g myResourceGroup -n myAKSCluster --disable-azure-rbac
8370
```
8471

85-
## Create role assignments for users to access cluster
86-
87-
AKS provides the following four built-in roles:
72+
## Create role assignments for users to access the cluster
8873

74+
AKS provides the following built-in roles:
8975

9076
| Role | Description |
9177
|-------------------------------------|--------------|
92-
| Azure Kubernetes Service RBAC Reader | Allows read-only access to see most objects in a namespace. It doesn't allow viewing roles or role bindings. This role doesn't allow viewing `Secrets`, since reading the contents of Secrets enables access to ServiceAccount credentials in the namespace, which would allow API access as any ServiceAccount in the namespace (a form of privilege escalation) |
93-
| Azure Kubernetes Service RBAC Writer | Allows read/write access to most objects in a namespace. This role doesn't allow viewing or modifying roles or role bindings. However, this role allows accessing `Secrets` and running Pods as any ServiceAccount in the namespace, so it can be used to gain the API access levels of any ServiceAccount in the namespace. |
78+
| Azure Kubernetes Service RBAC Reader | Allows read-only access to see most objects in a namespace. It doesn't allow viewing roles or role bindings. This role doesn't allow viewing `Secrets`, since reading the contents of Secrets enables access to ServiceAccount credentials in the namespace, which would allow API access as any ServiceAccount in the namespace (a form of privilege escalation). |
79+
| Azure Kubernetes Service RBAC Writer | Allows read/write access to most objects in a namespace. This role doesn't allow viewing or modifying roles or role bindings. However, this role allows accessing `Secrets` and running Pods as any ServiceAccount in the namespace, so it can be used to gain the API access levels of any ServiceAccount in the namespace. |
9480
| Azure Kubernetes Service RBAC Admin | Allows admin access, intended to be granted within a namespace. Allows read/write access to most resources in a namespace (or cluster scope), including the ability to create roles and role bindings within the namespace. This role doesn't allow write access to resource quota or to the namespace itself. |
9581
| Azure Kubernetes Service RBAC Cluster Admin | Allows super-user access to perform any action on any resource. It gives full control over every resource in the cluster and in all namespaces. |
9682

83+
Roles assignments scoped to the **entire AKS cluster** can be done either on the Access Control (IAM) blade of the cluster resource on Azure portal or by using the following Azure CLI commands:
9784

98-
Roles assignments scoped to the **entire AKS cluster** can be done either on the Access Control (IAM) blade of the cluster resource on Azure portal or by using Azure CLI commands as shown below:
85+
Get your AKS resource ID using the [`az aks show`][az-aks-show] command.
9986

10087
```azurecli
101-
# Get your AKS Resource ID
102-
AKS_ID=$(az aks show -g MyResourceGroup -n MyManagedCluster --query id -o tsv)
88+
AKS_ID=$(az aks show -g myResourceGroup -n myManagedCluster --query id -o tsv)
10389
```
10490

105-
```azurecli-interactive
106-
az role assignment create --role "Azure Kubernetes Service RBAC Admin" --assignee <AAD-ENTITY-ID> --scope $AKS_ID
107-
```
108-
109-
where `<AAD-ENTITY-ID>` could be a username (for example, [email protected]) or even the ClientID of a service principal.
110-
111-
You can also create role assignments scoped to a specific **namespace** within the cluster:
91+
Create a role assignment using the [`az role assignment create`][az-role-assignment-create] command. `<AAD-ENTITY-ID>` can be a username or the client ID of a service principal.
11292

11393
```azurecli-interactive
114-
az role assignment create --role "Azure Kubernetes Service RBAC Reader" --assignee <AAD-ENTITY-ID> --scope $AKS_ID/namespaces/<namespace-name>
94+
az role assignment create --role "Azure Kubernetes Service RBAC Admin" --assignee <AAD-ENTITY-ID> --scope $AKS_ID
11595
```
11696

117-
Today, role assignments scoped to namespaces need to be configured via Azure CLI.
118-
119-
120-
### Create custom roles definitions
121-
122-
Optionally you may choose to create your own role definition and then assign as above.
97+
> [!NOTE]
98+
> You can create the *Azure Kubernetes Service RBAC Reader* and *Azure Kubernetes Service RBAC Writer* role assignments scoped to a specific namespace within the cluster using the [`az role assignment create`][az-role-assignment-create] command and setting the scope to the desired namespace.
99+
>
100+
> ```azurecli-interactive
101+
> az role assignment create --role "Azure Kubernetes Service RBAC Reader" --assignee <AAD-ENTITY-ID> --scope $AKS_ID/namespaces/<namespace-name>
102+
> ```
123103
124-
Below is an example of a role definition that allows a user to only read deployments and nothing else. You can check the full list of possible actions [here](../role-based-access-control/resource-provider-operations.md#microsoftcontainerservice).
104+
## Create custom roles definitions
125105
106+
The following example custom role definition allows a user to only read deployments and nothing else. For the full list of possible actions, see [Microsoft.ContainerService operations](../role-based-access-control/resource-provider-operations.md#microsoftcontainerservice).
126107
127-
Copy the below json into a file called `deploy-view.json`.
108+
To create your own custom role definitions, copy the following file, replacing `<YOUR SUBSCRIPTION ID>` with your own subscription ID, and then save it as `deploy-view.json`.
128109
129110
```json
130111
{
@@ -142,47 +123,27 @@ Copy the below json into a file called `deploy-view.json`.
142123
}
143124
```
144125
145-
Replace `<YOUR SUBSCRIPTION ID>` by the ID from your subscription, which you can get by running:
146-
147-
```azurecli-interactive
148-
az account show --query id -o tsv
149-
```
150-
151-
Now we can create the role definition by running the below command from the folder where you saved `deploy-view.json`:
126+
Create the role definition using the [`az role definition create`][az-role-definition-create] command, setting the `--role-definition` to the `deploy-view.json` file you created in the previous step.
152127

153128
```azurecli-interactive
154129
az role definition create --role-definition @deploy-view.json
155130
```
156131

157-
Now that you have your role definition, you can assign it to a user or other identity by running:
132+
Assign the role definition to a user or other identity using the [`az role assignment create`][az-role-assignment-create] command.
158133

159134
```azurecli-interactive
160135
az role assignment create --role "AKS Deployment Reader" --assignee <AAD-ENTITY-ID> --scope $AKS_ID
161136
```
162137

163138
## Use Azure RBAC for Kubernetes Authorization with `kubectl`
164139

165-
> [!NOTE]
166-
> Ensure you have the latest kubectl by running the below command:
167-
>
168-
> ```azurecli-interactive
169-
> az aks install-cli
170-
> ```
171-
>
172-
> You might need to run it with `sudo` privileges.
173-
174-
Now that you have assigned your desired role and permissions. You can start calling the Kubernetes API, for example, from `kubectl`.
175-
176-
For this purpose, let's first get the cluster's kubeconfig using the below command:
140+
Make sure you have the [Azure Kubernetes Service Cluster User](../role-based-access-control/built-in-roles.md#azure-kubernetes-service-cluster-user-role) built-in role, and then get the kubeconfig of your AKS cluster using the [`az aks get-credentials`][az-aks-get-credentials] command.
177141

178142
```azurecli-interactive
179-
az aks get-credentials -g MyResourceGroup -n MyManagedCluster
143+
az aks get-credentials -g myResourceGroup -n myManagedCluster
180144
```
181145

182-
> [!IMPORTANT]
183-
> You'll need the [Azure Kubernetes Service Cluster User](../role-based-access-control/built-in-roles.md#azure-kubernetes-service-cluster-user-role) built-in role to perform the step above.
184-
185-
Now, you can use kubectl to, for example, list the nodes in the cluster. The first time you run it you'll need to sign in, and subsequent commands will use the respective access token.
146+
Now, you can use `kubectl` manage your cluster. For example, you can list the nodes in your cluster using `kubectl get nodes`. The first time you run it, you'll need to sign in, as shown in the following example:
186147

187148
```azurecli-interactive
188149
kubectl get nodes
@@ -194,19 +155,18 @@ aks-nodepool1-93451573-vmss000001 Ready agent 3h6m v1.15.11
194155
aks-nodepool1-93451573-vmss000002 Ready agent 3h6m v1.15.11
195156
```
196157

197-
198158
## Use Azure RBAC for Kubernetes Authorization with `kubelogin`
199159

200-
To unblock additional scenarios like non-interactive logins, older `kubectl` versions or leveraging SSO across multiple clusters without the need to sign in to new cluster, granted that your token is still valid, AKS created an exec plugin called [`kubelogin`](https://github.com/Azure/kubelogin).
160+
AKS created the [`kubelogin`](https://github.com/Azure/kubelogin) plugin to help unblock additional scenarios, such as non-interactive logins, older `kubectl` versions, or leveraging SSO across multiple clusters without the need to sign in to a new cluster.
201161

202-
You can use it by running:
162+
You can use the `kubelogin` plugin by running the following command:
203163

204164
```bash
205165
export KUBECONFIG=/path/to/kubeconfig
206166
kubelogin convert-kubeconfig
207-
```
167+
```
208168

209-
The first time, you'll have to sign in interactively like with regular kubectl, but afterwards you'll no longer need to, even for new Azure AD clusters (as long as your token is still valid).
169+
Similar to `kubectl`, you need to log in the first time you run it, as shown in the following example:
210170

211171
```bash
212172
kubectl get nodes
@@ -218,38 +178,37 @@ aks-nodepool1-93451573-vmss000001 Ready agent 3h6m v1.15.11
218178
aks-nodepool1-93451573-vmss000002 Ready agent 3h6m v1.15.11
219179
```
220180

221-
## Clean up
181+
## Clean up resources
222182

223-
### Clean Role assignment
183+
### Delete role assignment
224184

225185
```azurecli-interactive
186+
# List role assignments
226187
az role assignment list --scope $AKS_ID --query [].id -o tsv
227-
```
228188
229-
Copy the ID or IDs from all the assignments you did and then.
230-
231-
```azurecli-interactive
189+
# Delete role assignments
232190
az role assignment delete --ids <LIST OF ASSIGNMENT IDS>
233191
```
234192

235-
### Clean up role definition
193+
### Delete role definition
236194

237195
```azurecli-interactive
238196
az role definition delete -n "AKS Deployment Reader"
239197
```
240198

241-
### Delete cluster and resource group
199+
### Delete resource group and AKS cluster
242200

243201
```azurecli-interactive
244-
az group delete -n MyResourceGroup
202+
az group delete -n myResourceGroup
245203
```
246204

247205
## Next steps
248206

249-
- Read more about AKS Authentication, Authorization, Kubernetes RBAC, and Azure RBAC [here](concepts-identity.md).
250-
- Read more about Azure RBAC [here](../role-based-access-control/overview.md).
251-
- Read more about the all the actions you can use to granularly define custom Azure roles for Kubernetes authorization [here](../role-based-access-control/resource-provider-operations.md#microsoftcontainerservice).
207+
To learn more about AKS authentication, authorization, Kubernetes RBAC, and Azure RBAC, see:
252208

209+
* [Access and identity options for AKS](/concepts-identity.md)
210+
* [What is Azure RBAC?](../role-based-access-control/overview.md)
211+
* [Microsoft.ContainerService operations](../role-based-access-control/resource-provider-operations.md#microsoftcontainerservice)
253212

254213
<!-- LINKS - Internal -->
255214
[aks-support-policies]: support-policies.md
@@ -259,6 +218,15 @@ az group delete -n MyResourceGroup
259218
[az-feature-list]: /cli/azure/feature#az_feature_list
260219
[az-feature-register]: /cli/azure/feature#az_feature_register
261220
[az-aks-install-cli]: /cli/azure/aks#az_aks_install_cli
221+
[az-aks-create]: /cli/azure/aks#az_aks_create
222+
[az-aks-show]: /cli/azure/aks#az_aks_show
223+
[az-role-assignment-create]: /cli/azure/role/assignment#az_role_assignment_create
262224
[az-provider-register]: /cli/azure/provider#az_provider_register
225+
[az-group-create]: /cli/azure/group#az_group_create
263226
[az-aks-update]: /cli/azure/aks#az_aks_update
264227
[managed-aad]: ./managed-aad.md
228+
[install-azure-cli]: /cli/azure/install-azure-cli
229+
[az-role-definition-create]: /cli/azure/role/definition#az_role_definition_create
230+
[az-aks-get-credentials]: /cli/azure/aks#az_aks_get-credentials
231+
[kubernetes-rbac]: /concepts-identity#azure-rbac-for-kubernetes-authorization
232+
[azure-rbac-kubernetes-rbac]: /concepts-identity#azure-rbac-for-kubernetes-authorization

0 commit comments

Comments
 (0)