Skip to content

Commit 4f89da2

Browse files
committed
add how to manage and configure azure rbac
1 parent 53fae55 commit 4f89da2

File tree

1 file changed

+234
-0
lines changed

1 file changed

+234
-0
lines changed
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
---
2+
title: Setup Azure RBAC
3+
description: How to set up and configure Azure RBAC for Nebari's access to Azure resources
4+
---
5+
6+
# Setup Azure RBAC
7+
8+
Azure Role-Based Access Control (RBAC) is a powerful feature that allows you to manage who has access to Azure resources, what they can do with those resources, and what areas they have access to. Integrating Azure RBAC with Nebari ensures secure and fine-grained access control over your Kubernetes clusters and associated Azure resources.
9+
10+
## What is Azure RBAC?
11+
12+
Azure RBAC provides fine-grained access management of Azure resources. It allows you to assign permissions to users, groups, and applications at a certain scope, such as a subscription, resource group, or individual resources. This ensures that users have only the permissions they need to perform their tasks, enhancing the security and manageability of your Azure environment.
13+
14+
### Key Concepts
15+
16+
- **Role**: A collection of permissions. Azure provides built-in roles like Owner, Contributor, and Reader, and you can also create custom roles.
17+
- **Role Assignment**: Associates a role with a user, group, or application at a specific scope.
18+
- **Scope**: The level at which the role assignment applies. It can be a subscription, resource group, or individual resource.
19+
20+
For more details, refer to the [Azure RBAC documentation](https://docs.microsoft.com/azure/role-based-access-control/overview).
21+
22+
### Prerequisites
23+
24+
Before you begin, ensure you have the following:
25+
26+
- **Azure CLI**: Version 2.0.61 or later. Install or update it from [Install Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli).
27+
- **Azure Subscription**: Access to an Azure subscription where you can create resources.
28+
- **AKS Cluster**: An existing Nebari Azure deployment.
29+
30+
In this guide we will be using the Azure CLI to perform most of the operations. Instructions on how to perform the same operations using the Azure Portal can be found in the [Azure RBAC documentation](https://docs.microsoft.com/azure/role-based-access-control/overview) alongside links for installing the Azure CLI.
31+
32+
### Step 1: Create an Admin Group
33+
34+
Create an Azure AD group to serve as the admin group for the AKS cluster. This group will have full administrative permissions on the cluster and related resources.
35+
36+
```bash
37+
az ad group create --display-name "nebari-admins" --mail-nickname "nebari-admins"
38+
```
39+
40+
Record the Object ID for this group:
41+
42+
```bash
43+
ADMIN_GROUP_ID=$(az ad group show --group "nebari-admins" --query objectId -o tsv)
44+
echo $ADMIN_GROUP_ID
45+
```
46+
47+
### Step 2: Configure Nebari to Use Azure RBAC
48+
49+
Update your `nebari-config.yaml` to integrate Azure RBAC settings. Ensure that the `azure_rbac` section is correctly configured to enable RBAC integration.
50+
51+
```yaml
52+
azure:
53+
# Existing configuration...
54+
azure_rbac:
55+
enabled: true
56+
managed_identity: true
57+
admin_group_object_ids:
58+
- "<REPLACE_WITH_$ADMIN_GROUP_ID>"
59+
```
60+
61+
::note
62+
Ensure that the `admin_group_object_ids` correspond to the Azure AD groups you've created for managing access.
63+
::
64+
65+
### Step 6: Deploy Nebari with Updated Configuration
66+
67+
After updating the `nebari-config.yaml`, deploy Nebari to apply the changes.
68+
69+
```bash
70+
nebari deploy
71+
```
72+
73+
By default, when rbac is `enabled`, Nebari will use the Azure AD group specified in
74+
`admin_group_object_ids` to grant full administrative permissions to the AKS cluster by
75+
automatically assigning the `Azure Kubernetes Service Cluster Admin Role` to the group.
76+
As seen bellow:
77+
78+
```yaml
79+
apiVersion: rbac.authorization.k8s.io/v1
80+
kind: ClusterRoleBinding
81+
metadata:
82+
labels:
83+
addonmanager.kubernetes.io/mode: Reconcile
84+
kubernetes.io/cluster-service: "true"
85+
name: aks-cluster-admin-binding-aad
86+
resourceVersion: "1241646"
87+
uid: 3b1b3b1b-3b1b-3b1b-3b1b-3b1b3b1b3b1b
88+
roleRef:
89+
apiGroup: rbac.authorization.k8s.io
90+
kind: ClusterRole
91+
name: cluster-admin
92+
subjects:
93+
- apiGroup: rbac.authorization.k8s.io
94+
kind: Group
95+
name: <ADMIN_GROUP_ID>
96+
```
97+
98+
::warning
99+
Ensure that your configuration changes do not inadvertently disrupt existing deployments. Review your `nebari-config.yaml` before deploying.
100+
::
101+
102+
## Testing Access
103+
104+
To demonstrate the capabilities of the RBAC and Azure AD integration, let’s simulate access scenarios with one additional group: (`appdev`) who should only have access to a `dev` namespace. This group is not required for the core setup but serve as an illustrative example.
105+
106+
### Prepare Test Groups and Role Assignments
107+
108+
0. **Retrieve AKS Cluster ID**
109+
110+
```bash
111+
AKS_ID=$(az aks show --resource-group <YourResourceGroup> --name <YourAKSCluster> --query id -o tsv)
112+
```
113+
114+
1. **Create the Developer Group**
115+
116+
```bash
117+
az ad group create --display-name "appdev" --mail-nickname "appdev"
118+
119+
APPDEV_GROUP_ID=$(az ad group show --group "appdev" --query objectId -o tsv)
120+
```
121+
122+
2. **Assign Reader Role (or other limited roles)**
123+
124+
Assign a more restrictive role to the developer and SRE groups at the resource group level. For this example, we’ll use `Reader`:
125+
126+
```bash
127+
az role assignment create \
128+
--assignee $APPDEV_ID \
129+
--role "Azure Kubernetes Service Cluster User Role" \
130+
--scope $AKS_ID
131+
```
132+
133+
3. **Map Azure AD Groups to Kubernetes RBAC**
134+
135+
Create or apply Role and RoleBinding resources for the `dev` namespace, assigning appropriate permissions.
136+
137+
For the `dev` namespace (for the `appdev` group):
138+
139+
```yaml
140+
# dev-role.yaml
141+
kind: Role
142+
apiVersion: rbac.authorization.k8s.io/v1
143+
metadata:
144+
namespace: dev
145+
name: dev-view-role
146+
rules:
147+
- apiGroups: [""]
148+
resources: ["pods"]
149+
verbs: ["get", "list"]
150+
151+
---
152+
# dev-rolebinding.yaml
153+
kind: RoleBinding
154+
apiVersion: rbac.authorization.k8s.io/v1
155+
metadata:
156+
namespace: dev
157+
name: dev-view-binding
158+
subjects:
159+
- kind: Group
160+
name: $APPDEV_GROUP_ID # Azure AD group ID for developers
161+
apiGroup: rbac.authorization.k8s.io
162+
roleRef:
163+
kind: Role
164+
name: dev-view-role
165+
apiGroup: rbac.authorization.k8s.io
166+
```
167+
168+
Apply the `dev` namespace roles:
169+
170+
```bash
171+
kubectl apply -f dev-role.yaml
172+
kubectl apply -f dev-rolebinding.yaml
173+
```
174+
175+
### Test Application Developer Access
176+
177+
1. **Log in as Developer**
178+
179+
```bash
180+
az login -u <AAD_DEV_UPN> -p '<AAD_DEV_PW>'
181+
```
182+
183+
::note
184+
This is just for testing and to serve as an exmaple, vvoid using passwords directly
185+
in command-line operations instead.
186+
::
187+
188+
2. **Retrieve Kubeconfig for Developer**
189+
190+
```bash
191+
az aks get-credentials --resource-group <YourResourceGroup> --name <YourAKSCluster> --overwrite-existing
192+
```
193+
194+
Update authentication details using `kubelogin`:
195+
196+
```bash
197+
kubelogin remove-tokens
198+
kubelogin convert-kubeconfig -l azurecli
199+
```
200+
201+
3. **Attempt to Access Dev Namespace**
202+
203+
```bash
204+
kubectl get pods --namespace dev
205+
```
206+
207+
**Expected Outcome:** The developer (in the `appdev` group) should be able to list and view pods within the `dev` namespace.
208+
209+
4. **Attempt to Access default Namespace**
210+
211+
```bash
212+
kubectl get pods --namespace default
213+
```
214+
215+
**Expected Outcome:** Access should be denied, indicating that the developer does not have permissions in the `default` namespace.
216+
217+
## Clean Up Resources
218+
219+
To avoid incurring unnecessary costs, clean up the resources created during this setup.
220+
221+
```bash
222+
# Retrieve admin credentials
223+
az aks get-credentials --resource-group <YourResourceGroup> --name <YourAKSCluster> --admin
224+
225+
# Delete Azure AD user if created for testing
226+
az ad user delete --upn-or-object-id $AKSDEV_ID
227+
228+
# Delete Azure AD test groups
229+
az ad group delete --group appdev
230+
```
231+
232+
::warning
233+
Deleting users and groups is irreversible. Ensure that these actions do not affect other parts of your organization.
234+
::

0 commit comments

Comments
 (0)