1 of 24

A Heart Rate Validating Admission Webhook

In Kubernetes

2 of 24

I’m Tom Gallacher

Aka. @tomgco

3 of 24

Anatomy of Admission Webhooks

4 of 24

5 of 24

6 of 24

7 of 24

CardioOps

8 of 24

But how do I make it?

9 of 24

Validating Webhook Configuration

  • Can be written in any language
  • Must be TLS Terminated
  • Only can be performed on CREATE, UPDATE, CONNECT or * Operations.
  • Is broken on pod/exec and pod/port-forward as of v1.11.2
  • For me in Node.js
  • Running locally, but could use another cluster / Lambdas
  • Yay!
  • This means that we cannot validate requests such as read’s and watches.
  • But this is a bug (some patches have been merged to master)

10 of 24

Lets wire it together

11 of 24

.

12 of 24

  • Rules specify what to validate
  • faiurePolicy is either Ignore (fail open) or Fail (fail closed)

Finally we apply this to the cluster with:

kubectl apply -f -

apiVersion: admissionregistration.k8s.io/v1beta1

kind: ValidatingWebhookConfiguration

metadata:

name: deny-heartrate

webhooks:

- name: deny-heartrate.yld.io

rules:

- apiGroups:

- ""

apiVersions:

- "v1"

operations:

- "CREATE"

resources:

- "pods"

failurePolicy: Fail

clientConfig:

url: "https://192.168.99.1:8080"

caBundle: "%%CERTIFICATE%%"

13 of 24

a sprinkle of JavaScript (or any language you want)

  • Implement the bluetooth GATT spec for heart rates: org.bluetooth.characteristic.heart_rate_measurement
  • Hardcode to my specific device MAC (for now) “d7046c50aa65
  • Create a HTTPS server listening on 8080
  • Respond with:

{ “response”: { “allowed”: false, “status”:

{ “status”: “Failure”, “message”: “”,

“reason”: “”, code: 402

}}}

14 of 24

Step 1 - create some new pods and watch them fail!

15 of 24

16 of 24

Step 2 - Start the Server (set @200 BPM, hopefully I am not that nervous)

17 of 24

18 of 24

Step 3 - Start the Server (set @60 bpm, and my pod should create)

19 of 24

20 of 24

Step 4 - gate your kubernetes resources based on your own heart rate* :D

21 of 24

*Not production ready

22 of 24

Conclusions

Many uses, why not give them a go?

23 of 24

Questions?

24 of 24

Tom Gallacher

@tomgco

@yldio