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

Commit 9e5d9ea

Browse files
committed
adding README.md file
1 parent 3b59d40 commit 9e5d9ea

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# k8s-tpm-device-plugin
2+
3+
This is a Kubernetes device plugin to make TPM devices accessible from Kubernetes pods without the need to run pods in privileged mode.
4+
The initial goal for this plugin was to enable the [rust keylime agent](https://github.com/keylime/rust-keylime/) to run on Kubernetes.
5+
6+
## Overview
7+
8+
In a nutshell the plugin consists actually of two plugins which allows you to pass through the `/dev/tpmrm0` or `/dev/tpm0` devices.
9+
Using the former device is preferred, and the latter one should usually only be used if the Linux kernel version of the cluster is <4.12.
10+
11+
Note that particularly when you are relying on the `/dev/tpm0` device that the host is not already holding full access to it.
12+
This could be the case if you are running [tpm2-abrmd](https://github.com/tpm2-software/tpm2-abrmd) which is not recommended any longer.
13+
14+
As mentioned below only one pod can hold the `/dev/tpm0` device at a time.
15+
Up to _N_ pods on a host can gain access to the `/dev/tpmrm0` device.
16+
This value is configurable and can be overwritten at installation time with for example an additional command-line flag while installing the helm chart: `--set pluginSettings.numTpmRmDevices=128`.
17+
By default up to 64 pods can gain access to the `/dev/tpmrm0` device on a host.
18+
Note that this number is totally arbitrary, and can unfortunately not be handled differently because of the way how devices are allocated by the Kubernetes device manager.
19+
20+
## Installation
21+
22+
The TPM device plugin must be deployed as a Kubernetes DaemonSet.
23+
It comes packaged as a helm chart.
24+
Run the following to deploy this helm chart in your Kubernetes cluster
25+
26+
```bash
27+
helm upgrade --install hhtpmplugin oci://ghcr.io/githedgehog/k8s-tpm-device-plugin/helm-charts/k8s-tpm-device-plugin
28+
```
29+
30+
If you want (or need) to make modifications to the installation, take a look at the [values.yaml](https://github.com/githedgehog/k8s-tpm-device-plugin/blob/main/build/helm/k8s-tpm-device-plugin/values.yaml) file.
31+
32+
## Usage
33+
34+
This is the preferred methodYou can request the `/dev/tpmrm0` device like the following in the resource limits section of a container spec:
35+
36+
```yaml
37+
resources:
38+
limits:
39+
githedgehog.com/tpmrm: 1
40+
```
41+
42+
In edge cases, and when you truly need it, you can similarly request the `/dev/tpm0` device like this (_NOTE: not implemented yet!_):
43+
44+
```yaml
45+
resources:
46+
limits:
47+
githedgehog.com/tpm: 1
48+
```
49+
50+
**NOTE:** The `/dev/tpm0` device can always be allocated only to one pod on a host at the same time.
51+
It is generally not advisable to use this device at all if your Linux kernel has support for the `/dev/tpmrm0` device.
52+
53+
## Example
54+
55+
Here is a full pod yaml example which provides full access to the TPM device without the need for any elevated privileges or capabilities:
56+
57+
```yaml
58+
---
59+
apiVersion: v1
60+
kind: Pod
61+
metadata:
62+
name: tpm-device-test
63+
spec:
64+
terminationGracePeriodSeconds: 1
65+
containers:
66+
- name: tpm-device-test
67+
image: fedora:latest
68+
command:
69+
- /bin/bash
70+
- -c
71+
- while true; do sleep 3600; done
72+
resources:
73+
limits:
74+
githedgehog.com/tpmrm: 1
75+
securityContext:
76+
allowPrivilegeEscalation: false
77+
capabilities:
78+
drop: ["ALL"]
79+
```
80+
81+
You can test this pod by running the following commands:
82+
83+
```bash
84+
kubectl exec -ti tpm-device-test -- /bin/bash
85+
86+
dnf install -y tpm2-tools
87+
tpm2_getcap --list
88+
tpm2_getrandom --hex 16
89+
```

0 commit comments

Comments
 (0)