You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/aks/kubelogin-authentication.md
+40-22Lines changed: 40 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,24 +8,24 @@ ms.date: 11/28/2023
8
8
9
9
# Use kubelogin to authenticate users in Azure Kubernetes Service
10
10
11
-
The kubelogin plugin in Azure is a client-go credential [plugin][client-go-cred-plugin] that implements Microsoft Entra authentication. In kubelogin, you can access features that aren't available in the kubectl command-line tool.
11
+
The kubelogin plugin in Azure is a client-go credential [plugin][client-go-cred-plugin] that implements Microsoft Entra authentication. The kubelogin plugin offers features that aren't available in the kubectl command-line tool.
12
12
13
-
Azure Kubernetes Service (AKS) clusters that are integrated with Microsoft Entra ID and running Kubernetes versions 1.24 or later automatically use the kubelogin format.
13
+
Azure Kubernetes Service (AKS) clusters that are integrated with Microsoft Entra ID and running Kubernetes version 1.24 or later automatically use the kubelogin format.
14
14
15
-
This article provides an overview and examples of how to use all [supported Microsoft Entra authentication methods][authentication-methods]for AKS.
15
+
This article provides an overview and examples of how to use kubelogin for all [supported Microsoft Entra authentication methods][authentication-methods]in AKS.
16
16
17
17
## Limitations
18
18
19
-
* You can include a maximum of 200 groups in a Microsoft Entra JSON Web Token (JWT) claim. For more than 200 groups, consider using [application roles][entra-id-application-roles].
20
-
* Groups that are created in Microsoft Entra ID are included only by using their **ObjectID** value, and not by their display name. The `sAMAccountName` command is available only for groups that are synchronized from on-premises Windows Server Active Directory.
21
-
* In AKS, the service principal authentication method works only with managed Microsoft Entra ID, and not with earlier-version Azure Active Directory.
22
-
* The device code authentication method doesn't work when a Microsoft Entra Conditional Access policy is configured on a Microsoft Entra tenant. Use web browser interactive authentication instead.
19
+
* You can include a maximum of 200 groups in a Microsoft Entra JSON Web Token (JWT) claim. If you have more than 200 groups, consider using [application roles][entra-id-application-roles].
20
+
* Groups that are created in Microsoft Entra ID are included only by their **ObjectID** value, and not by their display name. The `sAMAccountName` command is available only for groups that are synchronized from on-premises Windows Server Active Directory.
21
+
* In AKS, the service principal authentication method works only with managed Microsoft Entra ID, and not with the earlierversion Azure Active Directory.
22
+
* The device code authentication method doesn't work when a Microsoft Entra Conditional Access policy is set on a Microsoft Entra tenant. In that scenario, use web browser interactive authentication.
23
23
24
24
## How authentication works
25
25
26
-
For most interactions with kubelogin, you use the `convert-kubeconfig` subcommand. The subcommand uses the kubeconfig file that's specified in `--kubeconfig` or in the `KUBECONFIG` environment variable to convert to the final kubeconfig file to exec format based on the specified authentication method.
26
+
For most interactions with kubelogin, you use the `convert-kubeconfig` subcommand. The subcommand uses the kubeconfig file that's specified in `--kubeconfig` or in the `KUBECONFIG` environment variable to convert the final kubeconfig file to exec format based on the specified authentication method.
27
27
28
-
The authentication methods that kubelogin implements are Microsoft Entra OAuth 2.0 token grant flows. The following parameter flags are common to use in kubelogin subcommands. In general, these flags are already set up when you get the kubeconfig file from AKS.
28
+
The authentication methods that kubelogin implements are Microsoft Entra OAuth 2.0 token grant flows. The following parameter flags are common to use in kubelogin subcommands. In general, these flags are ready to use when you get the kubeconfig file from AKS.
29
29
30
30
*`--tenant-id`: The Microsoft Entra tenant ID.
31
31
*`--client-id`: The application ID of the public client application. This client app is used only in the device code, web browser interactive, and OAuth 2.0 Resource Owner Password Credentials (ROPC) (workflow identity) sign-in methods.
@@ -36,7 +36,7 @@ The authentication methods that kubelogin implements are Microsoft Entra OAuth 2
36
36
37
37
## Authentication methods
38
38
39
-
The next sections describe the supported authentication methods and how to use them:
39
+
The next sections describe supported authentication methods and how to use them:
40
40
41
41
* Device code
42
42
* Azure CLI
@@ -49,9 +49,9 @@ The next sections describe the supported authentication methods and how to use t
49
49
50
50
Device code is the default authentication method for the `convert-kubeconfig` subcommand. The `-l devicecode` parameter is optional. This authentication method prompts the device code for the user to sign in from a browser session.
51
51
52
-
Before the kubelogin and exec plugins were introduced, the Azure authentication method in kubectl supported only the device code flow. It used an earlier version of a library that produces the token with the `audience` claim that has the `spn:` prefix. (`spn` refers to *Service Principal Name (SPN)*.) It isn't compatible with [AKS managed Microsoft Entra ID][aks-managed-microsoft-entra-id], which uses an [on-behalf-of (OBO)][oauth-on-behalf-of] flow. When you run the `convert-kubeconfig` subcommand, kubelogin removes the `spn:` prefix from the audience claim.
52
+
Before the kubelogin and exec plugins were introduced, the Azure authentication method in kubectl supported only the device code flow. It used an earlier version of a library that produces a token that has the `audience` claim with an `spn:` prefix. It isn't compatible with [AKS managed Microsoft Entra ID][aks-managed-microsoft-entra-id], which uses an [on-behalf-of (OBO)][oauth-on-behalf-of] flow. When you run the `convert-kubeconfig` subcommand, kubelogin removes the `spn:` prefix from the audience claim.
53
53
54
-
If your requirements include using earlier-version functionality, add the `--legacy` argument. If you're using the kubeconfig file in an earlier-version Azure Active Directory cluster, kubelogin automatically adds the `--legacy` flag.
54
+
If your requirements include using functionality from earlier versions, add the `--legacy` argument. If you're using the kubeconfig file in an earlierversion Azure Active Directory cluster, kubelogin automatically adds the `--legacy` flag.
55
55
56
56
In this sign-in method, the access token and the refresh token are cached in the *${HOME}/.kube/cache/kubelogin* directory. To override this path, include the `--token-cache-dir` parameter.
57
57
@@ -75,15 +75,17 @@ kubelogin remove-tokens
75
75
```
76
76
77
77
> [!NOTE]
78
-
> The device code sign-in method doesn't work when a Conditional Access policy is configured on a Microsoft Entra tenant. In this scenario, use the [web browser interactive method][web-browser-interactive-method] instead.
78
+
> The device code sign-in method doesn't work when a Conditional Access policy is configured on a Microsoft Entra tenant. In this scenario, use the [web browser interactive method][web-browser-interactive-method].
79
79
80
80
### Azure CLI
81
81
82
-
The Azure CLI method of authentication uses the signed-in context that the Azure CLI establishes to get the access token. The token is issued in the same Microsoft Entra tenant as `az login`. kubelogin doesn't write the tokens to the token cache file because it's already managed by the Azure CLI.
82
+
The Azure CLI authentication method uses the signed-in context that the Azure CLI establishes to get the access token. The token is issued in the same Microsoft Entra tenant as `az login`. kubelogin doesn't write tokens to the token cache file because they are already managed by the Azure CLI.
83
83
84
84
> [!NOTE]
85
85
> This authentication method works only with AKS managed Microsoft Entra ID.
86
86
87
+
The following example shows how to use the Azure CLI method to authenticate:
88
+
87
89
```bash
88
90
az login
89
91
@@ -98,14 +100,16 @@ Run this kubectl command to get node information:
98
100
kubectl get nodes
99
101
```
100
102
101
-
When the Azure CLI config directory is outside the *${HOME}* directory, use the `--azure-config-dir` parameter with the `convert-kubeconfig` subcommand. It generates the kubeconfig with the environment variable configured. You can get the same configuration by setting the `AZURE_CONFIG_DIR` environment variable to this directory when you run a kubectl command.
103
+
If the Azure CLI config directory is outside the *${HOME}* directory, use the `--azure-config-dir` parameter with the `convert-kubeconfig` subcommand. The command generates the kubeconfig file with the environment variable configured. You can get the same configuration by setting the `AZURE_CONFIG_DIR` environment variable to this directory when you run a kubectl command.
102
104
103
105
### Web browser interactive
104
106
105
-
The web browser interactive method of authentication automatically opens a web browser to sign in the user. After the user is authenticated, the browser redirects back to a local web server by using the verified credentials. This authentication method complies with Conditional Access policy.
107
+
The web browser interactive method of authentication automatically opens a web browser to sign in the user. After the user is authenticated, the browser redirects to the local web server by using the verified credentials. This authentication method complies with Conditional Access policy.
106
108
107
109
When you authenticate by using this method, the access token is cached in the *${HOME}/.kube/cache/kubelogin* directory. You can override this path by using the `--token-cache-dir` parameter.
108
110
111
+
#### Bearer token
112
+
109
113
The following example shows how to use a bearer token with the web browser interactive flow:
110
114
111
115
```bash
@@ -120,7 +124,9 @@ Run this kubectl command to get node information:
120
124
kubectl get nodes
121
125
```
122
126
123
-
The following example shows how to use PoP tokens with the web browser interactive flow:
127
+
#### Proof-of-Possession token
128
+
129
+
The following example shows how to use a Proof-of-Possession (PoP) token with the web browser interactive flow:
124
130
125
131
```bash
126
132
export KUBECONFIG=/path/to/kubeconfig
@@ -136,21 +142,23 @@ kubectl get nodes
136
142
137
143
### Service principal
138
144
139
-
This authentication method uses a service principal to sign in. You can provide the credential by using an environment variable or by using it in a command-line argument. The supported credentials to use are a password or a Personal Information Exchange (PFX) client certificate.
145
+
This authentication method uses a service principal to sign in the user. You can provide the credential by setting an environment variable or by using the credential in a command-line argument. The supported credentials that you can use are a password or a Personal Information Exchange (PFX) client certificate.
140
146
141
147
Before you use this method, consider the following limitations:
142
148
143
149
* This method works only with managed Microsoft Entra ID.
144
150
* The service principal can be a member of a maximum of 200 [Microsoft Entra groups][microsoft-entra-group-membership].
145
151
146
-
The following examples show how to set up a client secret by using an environment variable:
152
+
#### Environment variables
153
+
154
+
The following example shows how to set up a client secret by using environment variables:
@@ -177,6 +185,8 @@ Run this kubectl command to get node information:
177
185
kubectl get nodes
178
186
```
179
187
188
+
#### Command-line argument
189
+
180
190
The following example shows how to set up a client secret in a command-line argument:
181
191
182
192
```bash
@@ -192,9 +202,11 @@ kubectl get nodes
192
202
```
193
203
194
204
> [!WARNING]
195
-
> This method leaves the secret in the kubeconfig file.
205
+
> The command-line argument method stores the secret in the kubeconfig file.
206
+
207
+
#### Client certificate
196
208
197
-
The following examples show how to set up a client secret by using a client certificate:
209
+
The following example shows how to set up a client secret by using a client certificate:
198
210
199
211
```bash
200
212
export KUBECONFIG=/path/to/kubeconfig
@@ -230,6 +242,8 @@ Run this kubectl command to get node information:
230
242
kubectl get nodes
231
243
```
232
244
245
+
#### PoP token and environment variables
246
+
233
247
The following example shows how to set up a PoP token that uses a client secret that it gets from environment variables:
234
248
235
249
```bash
@@ -251,6 +265,8 @@ kubectl get nodes
251
265
252
266
Use the [managed identity][managed-identity-overview] authentication method for applications that connect to resources that support Microsoft Entra authentication. Examples include accessing Azure resources like an Azure virtual machine, a virtual machine scale set, or Azure Cloud Shell.
253
267
268
+
#### Default managed identity
269
+
254
270
The following example shows how to use the default managed identity:
255
271
256
272
```bash
@@ -265,6 +281,8 @@ Run this kubectl command to get node information:
265
281
kubectl get nodes
266
282
```
267
283
284
+
#### Specific identity
285
+
268
286
The following example shows how to use a managed identity with a specific identity:
0 commit comments