Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit 11e7541

Browse files
author
knrt10
committed
Add document for admission webhook
Closes: #913 Signed-off-by: knrt10 <kautilya@kinvolk.io>
1 parent 5ba9d5c commit 11e7541

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

docs/concepts/admission-webhook.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Lokomotive admission webhooks
2+
3+
As part of the cluster control plane Lokomotive creates additional admission webhooks, which add extra features to the cluster. This document describes the webhooks we install and what they do.
4+
5+
## `Default` service account mutating webhook
6+
7+
When you create a pod, if you do not specify a service account, the pod is automatically assigned the `default` service account in the same namespace. If you get the raw JSON or YAML for a pod you have created (for example using `kubectl get pods/<podname> -o yaml`), you can see the `spec.serviceAccountName` field has been automatically set.
8+
9+
By default, created pods can authenticate to the Kubernetes API, which is a potential security threat. Not every pod needs the ability to utilize the API. If your application doesn't integrate with Kubernetes and doesn't utilize its API, the application shouldn't have access to API credentials.
10+
11+
To avoid having to manually disable automounting of the `default` service account, we have a webhook server that patches `default` service accounts whenever you either apply any [lokomotive component](./components.md) or create a new namespace. To see how it works, follow the steps below.
12+
13+
```bash
14+
# Create a namespace.
15+
kubectl create ns foo
16+
17+
# Get default service account for namespace foo.
18+
kubectl get sa default -o yaml -n foo
19+
```
20+
21+
By following the steps above you can see that the `automountServiceAccountToken` field is set to `false`.
22+
23+
For more information see the [kubernetes docs](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/).
24+
25+
### Current limitations
26+
27+
When creating a cluster, the `default` service account for the `default` namespace is not patched. Note that it is generally not recommended to use the `default` namespace for running workloads. However, if you want to patch the `default` namespace, too, you can delete the `default` service account after your cluster is created.
28+
29+
```bash
30+
kubectl delete sa default -n default
31+
```
32+
33+
### Enabling mounting of the `default` service account for pods
34+
35+
It is recommended to create a dedicated service account for your application, giving it the rights it needs. However, if you still want to enable mounting of the `default` service account, you can opt into automounting API credentials for a particular pod by setting `automountServiceAccountToken` to `true`. The pod spec takes precedence over the service account if both specify a value for the `automountServiceAccountToken` field. Look at the snippet below for more information on setting of `automountServiceAccountToken` field.
36+
37+
```yaml
38+
apiVersion: v1
39+
kind: Pod
40+
metadata:
41+
name: my-pod
42+
spec:
43+
serviceAccountName: build-robot
44+
automountServiceAccountToken: true
45+
...
46+
```

0 commit comments

Comments
 (0)