DEV Community

johnettagaweraks
johnettagaweraks

Posted on

Zanzibar consistency tokens: when an authorization read must wait

Zanzibar consistency tokens: when an authorization read must wait

Authorization answers are data. They depend on relation tuples and other policy state that can change while a request is in flight. Google's Zanzibar design uses consistency tokens, often called zookies, to connect a content update with a later permission check. The token is not a credential. It is a statement about how fresh the authorization read must be.

The classic failure is easy to describe. A user loses access to a document, but a permission service still reads an old ACL and allows the user to view new content. Retrying with an older token does not fix that. If the application asked for at least the freshness represented by the content write, the authorization service must wait until its snapshot can observe the related relation change. The requirement is about read ordering, not about the user's browser cache.

Applications need to decide where this guarantee is necessary. A dashboard that can lag briefly has different requirements from a document viewer that must not reveal a file after its sharing record changed. For sensitive transitions, obtain a consistency token after the policy write or through the content-change ACL check and pass it with the authorization request. For ordinary reads, an older or absent token may be acceptable if the product has explicitly accepted the stale window.

SpiceDB and other Zanzibar-style systems expose the same concept under different API names. The implementation detail varies, but the operational questions do not. Who stores the token? How long is it valid? Can a client send an arbitrary token to request an older snapshot? Does the service fail closed when the token cannot be satisfied? Does the client retry after a timeout, and could that retry cross a permission revocation?

Tokens should be treated as part of a request's consistency contract, not as evidence of an authorization decision. A token from a different tenant or object should not be accepted as a global freshness marker. The authorization service should validate scope, preserve monotonicity where its API promises it, and avoid letting a caller choose a point in the past simply to reduce latency.

One practical test is to create a resource, grant access, write content, revoke access, and immediately read again while introducing artificial replica delay. The expected behavior depends on the chosen consistency mode, but the result should match the documented contract. A second test should remove the token and confirm that the system chooses the intended default rather than silently varying it by load balancer.

Auth teams should also record why each permission call uses a particular mode. "Required for sharing changes" and "best effort for a personal dashboard" are clearer than a global switch. The authorization system can only provide the freshness the caller asks for.

References

Top comments (0)