Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 3bcc944

Browse files
committed
Improve the instructions for AAD.
1 parent ebbf3e5 commit 3bcc944

File tree

1 file changed

+77
-39
lines changed

1 file changed

+77
-39
lines changed

docs/kubernetes/aad.md

+77-39
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ This is walkthrough is to help you get start with Azure Active Directory(AAD) in
66

77
Please also refer to [Azure Active Directory plugin for client authentication](https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/client-go/plugin/pkg/client/auth/azure/README.md) in Kubernetes repo for more details abount OpenID Connect and AAD support in upstream.
88

9-
## Prerequision
9+
## Prerequisites
1010
1. An Azure Active Directory tenant, will refer as `AAD Tenant`. You can use the tenant for your Azure subscription;
1111
2. A `Web app / API` type AAD application, will refer as `Server Application`. This application represents the `apiserver`; For groups to work properly, you'll need to edit the `Server Application` Manifest and set `groupMembershipClaims` to either `All` or `SecurityGroup`.
1212
3. A `Native` type AAD application, will refer as `Client Application`. This application is for user login via `kubectl`. You'll need to add delegated permission to `Server Application`, please see [troubleshooting](#loginpageerror) section for detail.
1313

14+
You also need to delegate permission from the to the application as follows:
15+
16+
1. Go to Azure Portal, navigate to `Azure Active Directory` -> `App registrations`.
17+
2. Select the `Client Application`, Navigate to `Settings` -> `Required permissions`
18+
3. Choose `Add`, select the `Server Application`. You may need to enter the Server Application's name into the search field and search for it.
19+
In permissions tab, select `Delegated permissions` -> `Access {Server Application}`
20+
21+
1422
## Deployment
1523
Follow the [deployment steps](kubernetes.md#deployment). In step #4, add the following under 'properties' section:
1624
```
@@ -23,40 +31,69 @@ Follow the [deployment steps](kubernetes.md#deployment). In step #4, add the fol
2331

2432
- `serverAppID` : the `Server Application`'s ID
2533
- `clientAppID` : the `Client Application`'s ID
26-
- `tenantID` : (optional) the `AAD tenant`'s ID. If not specified, will use the tenant of the deployment subscription.
34+
- `tenantID` : the `AAD tenant`'s ID.
2735

2836
After template generation, the local generated kubeconfig file (`_output/<instance>/kubeconfig/kubeconfig.<location>.json`) will have the default user using AAD.
2937
Initially it isn't assoicated with any AAD user yet. To get started, try any kubectl command (like `kubectl get pods`), and you'll be prompted to the device login process. After login, you will be able to operate the cluster using your AAD identity.
3038

31-
### Note
32-
Please note that as of Kubernetes 1.7, the default is authorization mode is `AlwaysAllow`, which means any authenticated user have full access of the cluster.
33-
OpenID Connect is an authentication protocol responsible for identify users only, so initally all active accounts under the tenant will be able to login and have full admin privilege of the cluster.
39+
It should look something like:
40+
```sh
41+
To sign in, use a web browser to open the page https://aka.ms/devicelogin and enter the code FCVDE87XY to authenticate.
42+
```
3443

35-
In this case you may want to also turn on RBAC for your cluster.
36-
Please refer to [Enable Kubernetes Role-Based Access Control](features.md#optional-enable-kubernetes-role-based-access-control-rbac) for turing on RBAC using acs-engine.
44+
### Setting up authorization
45+
You can now authenticate to the Kubernetes cluster, but you need to set up authorization as well.
3746

38-
Following instructions are for turnning on RBAC manually together with AAD integration:
47+
#### Authentication
48+
With ACS-Engine, the cluster is locked down by default.
3949

40-
1. Since we use AAD object ID as OpenID Connect identity.
41-
You'll first need to figure out your account's object ID. Here is how to do it using Azure Portal:
42-
Navigate to `Azure Active Directory` -> `Users and groups` -> `All users`. And choose your account in right pannel. Switch to `Manage` -> `Profile`, and you can see the `Object ID` property.
43-
2. Figure out your user name. The user name would be in form of `IssuerUrl#ObjectID` format.
44-
You can navigate to `https://login.microsoftonline.com/{tenantid}/.well-known/openid-configuration`, and find the `IssuerUrl` under `issuer` property.
45-
3. Add your account as admin role
50+
This means that when you try to use your AAD account you will see something
51+
like:
52+
```sh
53+
Error from server (Forbidden): User "https://sts.windows.net/<tenant-id>#<user-id>" cannot list nodes at the cluster scope. (get nodes)
4654
```
47-
kubectl create clusterrolebinding aad-default-cluster-admin-binding --clusterrole=cluster-admin --user={UserName}
48-
```
49-
For example, if your `IssuerUrl` is `https://sts.windows.net/e2917176-1632-47a0-ad18-671d485757a3/`, and your User `ObjectID` is `22fa281b-bf62-4b14-972c-0dbca24a25a2`, the command would be:
55+
56+
See [enabling cluster-admin](#enabling-cluster-admin) below.
57+
58+
#### Enabling cluster admin
59+
60+
To enable authorization, you need to add a cluster admin role account, and add your user to that account.
61+
62+
The user name would be in form of `IssuerUrl#ObjectID` format.
63+
64+
It should be printed in the error message from the previous kubectl request.
65+
66+
Alternately, you can navigate to [this url](https://login.microsoftonline.com/{tenantid}/.well-known/openid-configuration), and find the `IssuerUrl` under `issuer` property.
67+
68+
Once you have the user name you can add it to the `cluster-admin` role (cluster super-user) as follows:
69+
70+
```sh
71+
CLUSTER=<cluster-name-here>
72+
REGION=<your-azure-region-name, e.g. 'centralus'>
73+
74+
ssh -i _output/${CLUSTER}/azureuser_rsa azureuser@${CLUSTER}.${REGION}.cloudapp.azure.com \
75+
kubectl create clusterrolebinding aad-default-cluster-admin-binding \
76+
--clusterrole=cluster-admin \
77+
--user 'https://sts.windows.net/<tenant-id>/#<user-id>'
5078
```
51-
kubectl create clusterrolebinding aad-default-cluster-admin-binding --clusterrole=cluster-admin --user=https://sts.windows.net/e2917176-1632-47a0-ad18-671d485757a3/#22fa281b-bf62-4b14-972c-0dbca24a25a2
79+
80+
That should output:
81+
```sh
82+
clusterrolebinding "aad-default-cluster-admin-binding" created
5283
```
53-
4. (Optional) Add groups into your admin role
84+
85+
At which point you should be able to use any Kubernetes commands to administer the cluster, including adding other AAD identities to particular RBAC roles.
86+
87+
#### Enabling AAD groups
88+
89+
You can also optionally add groups into your admin role
90+
5491
For example, if your `IssuerUrl` is `https://sts.windows.net/e2917176-1632-47a0-ad18-671d485757a3/`, and your Group `ObjectID` is `7d04bcd3-3c48-49ab-a064-c0b7d69896da`, the command would be:
92+
5593
```
5694
kubectl create clusterrolebinding aad-default-group-cluster-admin-binding --clusterrole=cluster-admin --group=7d04bcd3-3c48-49ab-a064-c0b7d69896da
5795
```
5896

59-
Or alternatively you can set the Group `ObjectID` with the `adminGroupID` flag as follows:
6097
```
6198
"aadProfile": {
6299
"serverAppID": "",
@@ -66,29 +103,30 @@ kubectl create clusterrolebinding aad-default-group-cluster-admin-binding --clus
66103
```
67104
The above config would automatically generate a clusterrolebinding with the cluster-admin clusterrole for the specified Group `ObjectID` on cluster deployment.
68105

69-
4. Turn on RBAC on master nodes.
70-
On master nodes, edit `/etc/kubernetes/manifests/kube-apiserver.yaml`, add `--authorization-mode=RBAC` under `command` property. Reboot nodes.
71-
5. Now that AAD account will be cluster admin, other accounts can still login but do not have permission for operating the cluster.
72-
To verify this, add another client user:
73-
```
74-
kubectl config set-credentials "user1" --auth-provider=azure \
106+
#### Adding another client user:
107+
To add test adding another client user run the following:
108+
109+
```
110+
kubectl config set-credentials "user1" --auth-provider=azure \
75111
--auth-provider-arg=environment=AzurePublicCloud \
76112
--auth-provider-arg=client-id={ClientAppID} \
77113
--auth-provider-arg=apiserver-id={ServerAppID} \
78114
--auth-provider-arg=tenant-id={TenantID}
79-
```
80-
81-
And use that user to login
82-
```
83-
kubectl get pods --user=user1
84-
```
85-
Now you'll be prompted to login again, you can try logining with another AAD user account.
86-
The login would succeed, but later you can see following message since server denies access:
87-
```
88-
Error from server (Forbidden): User "https://sts.windows.net/{tenantID}/#{objectID}" cannot list pods in the namespace "default". (get pods)
89-
```
90-
91-
You can manually update server configuration or add administrator users based on your requirement.
115+
```
116+
117+
And to test that user's login
118+
```
119+
kubectl get pods --user=user1
120+
```
121+
122+
Now you'll be prompted to login again, you can try logining with another AAD user account.
123+
The login would succeed, but later you can see following message since server denies access:
124+
```
125+
Error from server (Forbidden): User "https://sts.windows.net/{tenantID}/#{objectID}" cannot list pods in the namespace "default". (get pods)
126+
```
127+
128+
You can then update the cluster's role bindings and RBAC to suit your needs for that user. See the [default role bindings](https://kubernetes.io/docs/admin/authorization/rbac/#default-roles-and-role-bindings) for more details, and
129+
the [general guide to Kubernetes RBAC](https://kubernetes.io/docs/admin/authorization/rbac/).
92130

93131
## Troubleshooting
94132

0 commit comments

Comments
 (0)