authzed / spicedb-kubeapi-proxy

Secure access to the Kubernetes API using SpiceDB
https://authzed.com/spicedb
Apache License 2.0
21 stars 1 forks source link

write durability: always commit a write to both kube and spicedb, or neither #16

Closed ecordell closed 1 year ago

ecordell commented 1 year ago

Closes https://github.com/authzed/spicedb-kubeapi-proxy/issues/3

This adds a durable saga that writes to spicedb and kube, with the goal of ensuring that a write happens in both, or neither, but not just one or the other.

There are two methods of writing implemented: a pessimistic lock that prevents other requests from attempting to create same object at the same time, and an optimistic lock that detects when there are conflicts and rolls back or forward as needed.

Pessimistic outline:

Optimistic outline:

There are pros and cons to each approach, for now both are supported and we can configure them per request type or per instance of the proxy.

The durability of this function means that inputs, outputs, and progress state are stored in a sqlite database. The goal is to be robust to service failures (SpiceDB and Kube API) and process failures (network dies, process crashes and restarts).

The tests make use of failpoints to inject faults at specific places, and then verify that either both writes effectively happened, or neither did.

This initial implementation just deals with namespace objects but should be fairly straightforward to make generic for other types. I'm assuming we'll spend time on that in #6.