Skip to content

Commit 66fb200

Browse files
Merge pull request #234877 from JnHs/jh-arck8-rbacsk
add kubelogin steps
2 parents 8b8aae1 + e428d6c commit 66fb200

File tree

1 file changed

+76
-10
lines changed

1 file changed

+76
-10
lines changed

articles/azure-arc/kubernetes/azure-rbac.md

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
title: "Azure RBAC for Azure Arc-enabled Kubernetes clusters"
3-
ms.date: 03/13/2023
3+
ms.date: 04/27/2023
44
ms.topic: how-to
55
ms.custom: devx-track-azurecli
66
description: "Use Azure RBAC for authorization checks on Azure Arc-enabled Kubernetes clusters."
77
---
88

99
# Use Azure RBAC for Azure Arc-enabled Kubernetes clusters
1010

11-
Kubernetes [ClusterRoleBinding and RoleBinding](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#rolebinding-and-clusterrolebinding) object types help to define authorization in Kubernetes natively. By using this feature, you can use Azure Active Directory (Azure AD) and role assignments in Azure to control authorization checks on the cluster. This means that you can use Azure role assignments to granularly control who can read, write, and delete Kubernetes objects like deployment, pod, and service.
11+
Kubernetes [ClusterRoleBinding and RoleBinding](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#rolebinding-and-clusterrolebinding) object types help to define authorization in Kubernetes natively. By using this feature, you can use Azure Active Directory (Azure AD) and role assignments in Azure to control authorization checks on the cluster. Azure role assignments let you granularly control which users can read, write, and delete Kubernetes objects such as deployment, pod, and service.
1212

1313
For a conceptual overview of this feature, see [Azure RBAC on Azure Arc-enabled Kubernetes](conceptual-azure-rbac.md).
1414

@@ -39,7 +39,7 @@ For a conceptual overview of this feature, see [Azure RBAC on Azure Arc-enabled
3939
4040
## Set up Azure AD applications
4141
42-
### [AzureCLI >= v2.37](#tab/AzureCLI)
42+
### [Azure CLI >= v2.3.7](#tab/AzureCLI)
4343
4444
#### Create a server application
4545
@@ -134,7 +134,7 @@ For a conceptual overview of this feature, see [Azure RBAC on Azure Arc-enabled
134134
az rest --method PATCH --headers "Content-Type=application/json" --uri https://graph.microsoft.com/v1.0/applications/${CLIENT_OBJECT_ID}/ --body '{"api":{"requestedAccessTokenVersion": 1}}'
135135
```
136136
137-
### [AzureCLI < v2.37](#tab/AzureCLI236)
137+
### [Azure CLI < v2.3.7](#tab/AzureCLI236)
138138
139139
#### Create a server application
140140
@@ -252,7 +252,7 @@ az connectedk8s enable-features -n <clusterName> -g <resourceGroupName> --featur
252252
>
253253
> Use `--skip-azure-rbac-list` with the preceding command for a comma-separated list of usernames, emails, and OpenID connections undergoing authorization checks by using Kubernetes native `ClusterRoleBinding` and `RoleBinding` objects instead of Azure RBAC.
254254
255-
### Generic cluster where no reconciler is running on the apiserver specification
255+
### Generic cluster where no reconciler is running on the `apiserver` specification
256256

257257
1. SSH into every master node of the cluster and take the following steps:
258258

@@ -404,7 +404,7 @@ Owners of the Azure Arc-enabled Kubernetes resource can use either built-in role
404404

405405
| Role | Description |
406406
|---|---|
407-
| [Azure Arc Kubernetes Viewer](../../role-based-access-control/built-in-roles.md#azure-arc-kubernetes-viewer) | Allows read-only access to see most objects in a namespace. This role doesn't allow viewing secrets. This is because `read` permission on secrets would enable access to `ServiceAccount` credentials in the namespace. These credentials would in turn allow API access through that `ServiceAccount` value (a form of privilege escalation). |
407+
| [Azure Arc Kubernetes Viewer](../../role-based-access-control/built-in-roles.md#azure-arc-kubernetes-viewer) | Allows read-only access to see most objects in a namespace. This role doesn't allow viewing secrets, because `read` permission on secrets would enable access to `ServiceAccount` credentials in the namespace. These credentials would in turn allow API access through that `ServiceAccount` value (a form of privilege escalation). |
408408
| [Azure Arc Kubernetes Writer](../../role-based-access-control/built-in-roles.md#azure-arc-kubernetes-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` value in the namespace, so it can be used to gain the API access levels of any `ServiceAccount` value in the namespace. |
409409
| [Azure Arc Kubernetes Admin](../../role-based-access-control/built-in-roles.md#azure-arc-kubernetes-admin) | Allows admin access. It's intended to be granted within a namespace through `RoleBinding`. If you use it in `RoleBinding`, it allows read/write access to most resources in a namespace, 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. |
410410
| [Azure Arc Kubernetes Cluster Admin](../../role-based-access-control/built-in-roles.md#azure-arc-kubernetes-cluster-admin) | Allows superuser access to execute any action on any resource. When you use it in `ClusterRoleBinding`, it gives full control over every resource in the cluster and in all namespaces. When you use it in `RoleBinding`, it gives full control over every resource in the role binding's namespace, including the namespace itself.|
@@ -481,6 +481,10 @@ After the proxy process is running, you can open another tab in your console to
481481

482482
### Use a shared kubeconfig file
483483

484+
Using a shared kubeconfig requires slightly different steps depending on your Kubernetes version.
485+
486+
### [Kubernetes version >= 1.26](#tab/kubernetes-latest)
487+
484488
1. Run the following command to set the credentials for the user:
485489

486490
```console
@@ -513,6 +517,68 @@ After the proxy process is running, you can open another tab in your console to
513517
name: azure
514518
```
515519

520+
> [!NOTE]
521+
>[Exec plugin](https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins) is a Kubernetes authentication strategy that allows `kubectl` to execute an external command to receive user credentials to send to `apiserver`. Starting with Kubernetes version 1.26, the default Azure authorization plugin is no longer included in `client-go` and `kubectl`. With later versions, in order to use the exec plugin to receive user credentials you must use [Azure Kubelogin](https://azure.github.io/kubelogin/index.html), a `client-go` credential (exec) plugin that implements Azure authentication.
522+
523+
4. Install Azure Kubelogin:
524+
525+
- For Windows or Mac, follow the [Azure Kubelogin installation instructions](https://azure.github.io/kubelogin/install.html#installation).
526+
- For Linux or Ubuntu, download the [latest version of kubelogin](https://github.com/Azure/kubelogin/releases), then run the following commands:
527+
528+
```bash
529+
curl -LO https://github.com/Azure/kubelogin/releases/download/"$KUBELOGIN_VERSION"/kubelogin-linux-amd64.zip
530+
531+
unzip kubelogin-linux-amd64.zip
532+
533+
sudo mv bin/linux_amd64/kubelogin /usr/local/bin/
534+
535+
sudo chmod +x /usr/local/bin/kubelogin
536+
```
537+
538+
5. [Convert](https://azure.github.io/kubelogin/cli/convert-kubeconfig.html) the kubelogin to the appropriate [login mode](https://azure.github.io/kubelogin/concepts/login-modes.html). For example, for [device code login](https://azure.github.io/kubelogin/concepts/login-modes/devicecode.html) with an Azure Active Directory user, the commands would be as follows:
539+
540+
```bash
541+
export KUBECONFIG=/path/to/kubeconfig
542+
543+
kubelogin convert-kubeconfig
544+
```
545+
546+
### [Kubernetes < v1.26](#tab/Kubernetes-earlier)
547+
548+
1. Run the following command to set the credentials for the user:
549+
550+
```console
551+
kubectl config set-credentials <testuser>@<mytenant.onmicrosoft.com> \
552+
--auth-provider=azure \
553+
--auth-provider-arg=environment=AzurePublicCloud \
554+
--auth-provider-arg=client-id=<clientApplicationId> \
555+
--auth-provider-arg=tenant-id=<tenantId> \
556+
--auth-provider-arg=apiserver-id=<serverApplicationId>
557+
```
558+
559+
1. Open the *kubeconfig* file that you created earlier. Under `contexts`, verify that the context associated with the cluster points to the user credentials that you created in the previous step. To set the current context to these user credentials, run the following command:
560+
561+
```console
562+
kubectl config set-context --current=true --user=<testuser>@<mytenant.onmicrosoft.com>
563+
```
564+
565+
1. Add the **config-mode** setting under `user` > `config`:
566+
567+
```console
568+
569+
user:
570+
auth-provider:
571+
config:
572+
apiserver-id: $SERVER_APP_ID
573+
client-id: $CLIENT_APP_ID
574+
environment: AzurePublicCloud
575+
tenant-id: $TENANT_ID
576+
config-mode: "1"
577+
name: azure
578+
```
579+
580+
---
581+
516582
## Send requests to the cluster
517583

518584
1. Run any `kubectl` command. For example:
@@ -575,7 +641,7 @@ Access the cluster again. For example, run the `kubectl get nodes` command to vi
575641
kubectl get nodes
576642
```
577643

578-
Follow the instructions to sign in again. An error message states that you're successfully logged in, but your admin requires the device that's requesting access to be managed by Azure AD to access the resource. Follow these steps:
644+
Follow the instructions to sign in again. An error message states that you're successfully logged in, but your admin requires the device that's requesting access to be managed by Azure AD in order to access the resource. Follow these steps:
579645

580646
1. In the Azure portal, go to **Azure Active Directory**.
581647
1. Select **Enterprise applications**. Then under **Activity**, select **Sign-ins**.
@@ -629,7 +695,7 @@ After you've made the assignments, verify that just-in-time access is working by
629695
kubectl get nodes
630696
```
631697

632-
Note the authentication requirement and follow the steps to authenticate. If authentication is successful, you should see output similar to the following:
698+
Note the authentication requirement and follow the steps to authenticate. If authentication is successful, you should see output similar to this:
633699

634700
```output
635701
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code AAAAAAAAA to authenticate.
@@ -642,13 +708,13 @@ node-3 Ready agent 6m33s v1.18.14
642708

643709
## Refresh the secret of the server application
644710

645-
If the secret for the server application's service principal has expired, you will need to rotate it.
711+
If the secret for the server application's service principal has expired, you'll need to rotate it.
646712

647713
```azurecli
648714
SERVER_APP_SECRET=$(az ad sp credential reset --name "${SERVER_APP_ID}" --credential-description "ArcSecret" --query password -o tsv)
649715
```
650716

651-
Update the secret on the cluster. Please add any optional parameters you configured when this command was originally run.
717+
Update the secret on the cluster. Include any optional parameters you configured when the command was originally run.
652718

653719
```azurecli
654720
az connectedk8s enable-features -n <clusterName> -g <resourceGroupName> --features azure-rbac --app-id "${SERVER_APP_ID}" --app-secret "${SERVER_APP_SECRET}"

0 commit comments

Comments
 (0)