Skip to content

Commit 51eae6d

Browse files
committed
updated rbac doc, added reference
1 parent ac7ac6e commit 51eae6d

File tree

3 files changed

+118
-78
lines changed

3 files changed

+118
-78
lines changed

chapters/configuring_authentication_and_authorization.md

Lines changed: 87 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,95 @@
1-
# Configuring Authentication and Authorization
2-
Let us assume a scenario, where a cluster admin was asked to add a newly joined developer, John, to the cluster. He needs to create a configuration file for John and restrict him from accessing resources from other environments.
1+
# Kubernetes Access Control: Authentication and Authorization
32

4-
## Create namespace for a user(Optional)
3+
In this lab you are going to,
54

6-
Create the **dev** namespace if it has not been created already.
5+
* Create users and groups and setup certs based authentication
6+
* Create service accounts for applications
7+
* Create Roles and ClusterRoles to define authorizations
8+
* Map Roles and ClusterRoles to subjects i.e. users, groups and service accounts using RoleBingings and ClusterRoleBindings.
79

8-
`dev-namespace.yml`
910

10-
```
11-
apiVersion: v1
12-
kind: Namespace
13-
metadata:
14-
name: dev
15-
labels:
16-
name: dev
17-
```
18-
```
19-
kubectl apply -f dev-namespace.yml
20-
```
11+
## How one can access the Kubernetes API?
12+
13+
The Kubernetes API can be accessed by three ways.
14+
15+
* Kubectl - A command line utility of Kubernetes
16+
* Client libraries - Go, Python, etc.,
17+
* REST requests
18+
19+
## Who can access the Kubernetes API?
20+
21+
Kubernetes API can be accessed by,
22+
23+
* Human Users
24+
* Service Accounts
25+
26+
Each of these topics will be discussed in detail in the later part of this chapter.
27+
28+
## Stages of a Request
29+
30+
When a request tries to contact the API , it goes through various stages as illustrated in the image given below.
31+
32+
![request-stages](images/access-control.svg)
33+
<sub>[source: official kubernetes site](https://kubernetes.io/docs/home/)</sub>
34+
35+
36+
### Stage 1: Authentication
37+
38+
* Authentication operation checks whether the *user/service account* has the permission to talk to the api server or not.
39+
* Authentication is done by the authentication modules which are configured with the api server.
40+
* Cluster uses with one or more authentication modules enabled.
41+
* If the request fails to authenticate itself, it will be served with **401 error**.
42+
43+
#### Authentication for Human Users
44+
45+
* Kubernetes uses **usernames** for access control.
46+
* But it neither has an api object nor stores information about users in its data store.
47+
* Users need to be managed externally by the cluster administrator.
48+
49+
#### Authentication for Service Accounts
50+
51+
* Unlike user accounts, service accounts are managed by Kubernetes.
52+
* *service accounts* are bound to specific namespaces.
53+
* Credentials for *service Accounts* are stored as *secrets*.
54+
* These secrets are mounted to pods when a deployment starts using the Service Account.
55+
56+
### Stage 2: Authorization
57+
58+
* After a request successfully authenticated, it goes through the authorization process.
59+
* In order for a request to be authorized, it must consist following attributes.
60+
* Username of the requester(User)
61+
* Requested action(Verb)
62+
* The object affected(Resource)
63+
* Authorization is done by the following modules. Each of these modules has a special purpose.
64+
* Attribute Based Access Control(ABAC)
65+
* Role Based Access Control(RBAC)
66+
* Node Authorizer
67+
* Webhook module
68+
* If a request is failed to get authorized, it will be served with **403 error**.
69+
* Among these modules, RBAC is the most used authorizer while,
70+
* ABAC is used for,
71+
* Policy based, fine grained access control
72+
* The caveat is api server has to be restarted whenever we define a ABAC policy
73+
* Node Authorizer is,
74+
* Enabled in all the worker nodes
75+
* Grants access to kubelet for some of the resources.
76+
* We have already talked about the user in detail. Now lets focus on **verbs** and **resources**
77+
* We will talk about RBAC in detail in the later part
78+
79+
### Stage 3: Admission Control
80+
* Admission control part is taken care of by the software modules that can modify/reject requests.
81+
* Admission control is mainly used for fine-tuning access control.
82+
* Admission control can directly act on the object being modified.
83+
84+
85+
## Role Based Access Control (RBAC)
86+
87+
| Group | User | Namespace | Resources |
88+
| :------------- | :------------- | :------------- | :------------- |
89+
| ops | maya | all | all |
90+
| dev | kim | instavote | pods, deployments, statefulsets, configmaps, secrets, services, jobs, crons |
91+
2192

22-
## Create the user credentials
2393
Generate the user's private key
2494
```
2595
openssl genrsa -out john.key 2048
@@ -78,25 +148,6 @@ roleRef:
78148
kubectl create -f dev-rolebinding.yaml
79149
```
80150

81-
## Kubernetes Access Control
82-
In this chapter, we will see about how to use authentication and authorisation of Kubernetes.
83-
## How one can access the Kubernetes API?
84-
The Kubernetes API can be accessed by three ways.
85-
* Kubeclt - A command line utility of Kubernetes
86-
* Client libraries - Go, Python, etc.,
87-
* REST requests
88-
89-
## Who can access the Kubernetes API?
90-
Kubernetes API can be accessed by,
91-
* Human users
92-
* Service Accounts
93-
Each of these topics will be discussed in detail in the later part of this chapter.
94-
95-
## Stages of a Request
96-
When a request tries to contact the API , it goes through various stages as illustrated in the image given below.
97-
98-
![request-stages](images/access-control.svg)
99-
<sub>[source: official kubernetes site](https://kubernetes.io/docs/home/)</sub>
100151

101152
### TLS in Kubernetes
102153
Kubernetes API typically runs on two ports.
@@ -107,44 +158,6 @@ Kubernetes API typically runs on two ports.
107158
* TLS Enabled.
108159
* Available for kubectl and others.
109160

110-
### Stage 1: Authentication
111-
* Authentication operation checks whether the *user/service account* has the permission to talk to the api server or not.
112-
* Authentication is done by the authentication modules which are configured with the api server.
113-
* Cluster uses with one or more authentication modules enabled.
114-
* If the request fails to authenticate itself, it will be served with **401 error**.
115-
116-
#### Authentication for Normal User
117-
* Kubernetes uses **usernames** for access control.
118-
* But it neither has an api object nor stores information about users in its data store.
119-
* Users need to be managed externally by the cluster administrator.
120-
121-
#### Authentication for Service Accounts
122-
* Unlike user accounts, service accounts are managed by Kubernetes.
123-
* *service accounts* are bound to specific namespaces.
124-
* Credentials for *service Accounts* are stored as *secrets*.
125-
* These secrets are mounted to pods when a deployment starts using the Service Account.
126-
127-
### Stage 2: Authorization
128-
* After a request successfully authenticated, it goes through the authorization process.
129-
* In order for a request to be authorized, it must consist following attributes.
130-
* Username of the requester(User)
131-
* Requested action(Verb)
132-
* The object affected(Resource)
133-
* Authorization is done by the following modules. Each of these modules has a special purpose.
134-
* Attribute Based Access Control(ABAC)
135-
* Role Based Access Control(RBAC)
136-
* Node Authorizer
137-
* Webhook module
138-
* If a request is failed to get authorized, it will be served with **403 error**.
139-
* Among these modules, RBAC is the most used authorizer while,
140-
* ABAC is used for,
141-
* Policy based, fine grained access control
142-
* The caveat is api server has to be restarted whenever we define a ABAC policy
143-
* Node Authorizer is,
144-
* Enabled in all the worker nodes
145-
* Grants access to kubelet for some of the resources.
146-
* We have already talked about the user in detail. Now lets focus on **verbs** and **resources**
147-
* We will talk about RBAC in detail in the later part
148161

149162
#### Verbs
150163
* Verbs are the **action** to be taken on resources.
@@ -161,10 +174,6 @@ Kubernetes API typically runs on two ports.
161174
* Resources are the object being manipulated by the verb.
162175
* Ex: pods, deployments, service, namespaces, nodes, etc.,
163176

164-
### Stage 3: Admission Control
165-
* Admission control part is taken care of by the software modules that can modify/reject requests.
166-
* Admission control is mainly used for fine-tuning access control.
167-
* Admission control can directly act on the object being modified.
168177

169178
## Role Based Access Control (RBAC)
170179
* RBAC is the most used form of access control to **grant or revoke** permissions to users.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# RBAC Reference
2+
3+
### kubernetes Instances Configuration
4+
## GCP
5+
6+
NUMBER OF NODE-SIZE |INSTANCE TYPE |CPU|MEMORY
7+
-------------------- | ------------- | ----- | -----------
8+
| 1-5 | n1-standard-1 | 1 |3.75 |
9+
|6-10 | n1-standard-2 | 2 |7.50 |
10+
|11-100 | n1-standard-4 | 4 |15 |
11+
|101-250 | n1-standard-8 | 8 |30 |
12+
|251-500 | n1-standard-16 | 16|60 |
13+
|more than 500 | n1-standard-32 | 32|120 |
14+
15+
## AWS
16+
| NUMBER OF NODE_SIZE |INSTANCE TYPE |CPU|MEMORY
17+
|--------------------|-----------------|----|---------
18+
| 1-5 | m3.medium | 1 | 3.75 |
19+
|6-10 | m3.large | 2 | 7.50 |
20+
|11-100 | m3.xlarge | 4 | 15 |
21+
|101-250 | m3.2xlarge | 8 | 30 |
22+
|251-500 | c4.4xlarge | 8 | 30 |
23+
|more than 500 | c4.8xlarge | 16| 60 |
24+
25+
## api groups and resources
26+
27+
| apiGroup | Resources |
28+
| :------------- | :------------- |
29+
| apps | daemonsets, deployments, deployments/rollback, deployments/scale, replicasets, replicasets/scale, statefulsets, statefulsets/scale |

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pages:
2626
- Ingress Controllers: "ingress.md"
2727
- Additional Topics:
2828
- Troubleshooting Tips: "12_troubleshooting.md"
29+
- References:
30+
- RBAC apiGroups to Resource Mapping: "rbac-resource-group-mapping.md"
2931
docs_dir: chapters
3032
theme: readthedocs
3133
plugins:

0 commit comments

Comments
 (0)