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

Commit bd9bbe0

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

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

docs/concepts/admission-webhook.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Lokomotive admission webhooks
2+
3+
As part of the cluster control-plane Lokomotive creates additional admission webhooks, which provides extra features to the cluster. This document describes what webhooks we install and what they do.
4+
5+
## Default ServiceAccount Mutating Webhook
6+
7+
When you create a pod, if you do not specify a service account, it 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, `kubectl get pods/<podname> -o yaml`), you can see the `spec.serviceAccountName` field has been automatically set. For more information see [kubernetes docs](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/). By default, created pods can authenticate to Kubernetes API, which might be a potential security threat.
8+
9+
Not every pod needs the ability to utilize the API from within itself. If your application do not integrate with Kubernetes and not utilize it's API, it shouldn't have credentials for it.
10+
11+
To avoid manually disabling automounting of 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 below steps from your command line.
12+
13+
```bash
14+
# Create a namespace.
15+
$ kubectl create ns foo
16+
17+
# Get default service for namespace foo.
18+
$ kubectl get sa default -o yaml -n foo
19+
```
20+
21+
After following the above steps you can see that `automountServiceAccountToken` field is set to false.
22+
23+
### Current limitations
24+
25+
Currently, on applying cluster `default` service account for `default` namespace is not patched. Please note, that as general convention, `default` namespace should not be used to run your workloads. However, if you want it patched too, you can delete the default service account after your cluster is created.
26+
27+
`$ kubectl delete sa default -n default`
28+
29+
### How to enable mounting default service account for pods
30+
31+
It is recommended to create a dedicated service account for your application, so that you have full control over grants it has bind. However, if you still want to enable `X` for default service account, you can opt in of automounting API credentials for a particular pod by setting `automountServiceAccountToken: true`. The pod spec takes precedence over the service account if both specify a value for `automountServiceAccountToken` field.
32+
33+
```yaml
34+
apiVersion: v1
35+
kind: Pod
36+
metadata:
37+
name: my-pod
38+
spec:
39+
serviceAccountName: build-robot
40+
automountServiceAccountToken: true
41+
...
42+
```

0 commit comments

Comments
 (0)