Skip to content

Commit f23da78

Browse files
committed
update kubelogin steps
1 parent 5b193ee commit f23da78

File tree

1 file changed

+75
-10
lines changed

1 file changed

+75
-10
lines changed

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

Lines changed: 75 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,69 @@ 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+
488+
1. Run the following command to set the credentials for the user:
489+
490+
```console
491+
kubectl config set-credentials <testuser>@<mytenant.onmicrosoft.com> \
492+
--auth-provider=azure \
493+
--auth-provider-arg=environment=AzurePublicCloud \
494+
--auth-provider-arg=client-id=<clientApplicationId> \
495+
--auth-provider-arg=tenant-id=<tenantId> \
496+
--auth-provider-arg=apiserver-id=<serverApplicationId>
497+
```
498+
499+
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:
500+
501+
```console
502+
kubectl config set-context --current=true --user=<testuser>@<mytenant.onmicrosoft.com>
503+
```
504+
505+
1. Add the **config-mode** setting under `user` > `config`:
506+
507+
```console
508+
509+
user:
510+
auth-provider:
511+
config:
512+
apiserver-id: $SERVER_APP_ID
513+
client-id: $CLIENT_APP_ID
514+
environment: AzurePublicCloud
515+
tenant-id: $TENANT_ID
516+
config-mode: "1"
517+
name: azure
518+
```
519+
520+
[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, a `client-go` credential (exec) plugin that implements Azure authentication.
521+
522+
1. Install Azure Kubelogin:
523+
524+
- For Windows or Mac, follow the [Azure Kubelogin installation instructions](https://azure.github.io/kubelogin/install.html#installation).
525+
- For Linux or Ubuntu, download the [latest version of kubelogin](https://github.com/Azure/kubelogin/releases), then run the following commands:
526+
527+
```bash
528+
curl -LO https://github.com/Azure/kubelogin/releases/download/"$KUBELOGIN_VERSION"/kubelogin-linux-amd64.zip
529+
530+
unzip kubelogin-linux-amd64.zip
531+
532+
sudo mv bin/linux_amd64/kubelogin /usr/local/bin/
533+
534+
sudo chmod +x /usr/local/bin/kubelogin
535+
```
536+
537+
1. [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:
538+
539+
```bash
540+
export KUBECONFIG=/path/to/kubeconfig
541+
542+
kubelogin convert-kubeconfig
543+
```
544+
545+
### [Kubernetes < v1.26](#tab/Kubernetes-earlier)
546+
484547
1. Run the following command to set the credentials for the user:
485548

486549
```console
@@ -513,6 +576,8 @@ After the proxy process is running, you can open another tab in your console to
513576
name: azure
514577
```
515578

579+
---
580+
516581
## Send requests to the cluster
517582

518583
1. Run any `kubectl` command. For example:
@@ -575,7 +640,7 @@ Access the cluster again. For example, run the `kubectl get nodes` command to vi
575640
kubectl get nodes
576641
```
577642

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:
643+
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:
579644

580645
1. In the Azure portal, go to **Azure Active Directory**.
581646
1. Select **Enterprise applications**. Then under **Activity**, select **Sign-ins**.
@@ -629,7 +694,7 @@ After you've made the assignments, verify that just-in-time access is working by
629694
kubectl get nodes
630695
```
631696

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

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

643708
## Refresh the secret of the server application
644709

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

647712
```azurecli
648713
SERVER_APP_SECRET=$(az ad sp credential reset --name "${SERVER_APP_ID}" --credential-description "ArcSecret" --query password -o tsv)
649714
```
650715

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

653718
```azurecli
654719
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)