Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache ZedTokens for resources using NATS #209

Merged
merged 4 commits into from
Jan 16, 2024

Commits on Jan 14, 2024

  1. Cache ZedTokens for resources using NATS

    Using full consistency when doing permissions checks is slow. In
    general, this is addressed by using ZedTokens to indicate minimum
    bounds on freshness when looking up cached data. Something has to keep
    track of those tokens, either on the client side or server-side.
    
    This commit introduces worker caching of ZedTokens for resources on
    updates to relationships and updates the query engine to use those
    tokens when performing permissions checks. When a worker updates a
    relationship, it persists the ZedToken for all resources directly
    affected by that update to a NATS KV bucket. NATS KV writes are
    immediately consistent, so the new ZedToken for that resource is
    available to all consumers, including permissions-api API
    frontends. When the query engine performs a permissions check, it
    checks to see if a ZedToken is available for the resource.
    
    If a ZedToken was found, that ZedToken is used along with the
    at_least_as_fresh SpiceDB API consistency strategy. If not, or if
    there was an error accessing NATS, the query engine falls back to the
    minimize_latency API consistency strategy. If the NATS KV bucket is
    configured with a TTL at least as high as the quantization interval
    for SpiceDB, this ensures that by the time the ZedToken is evicted
    from the cache, all SpiceDB frontends will be updated with data at
    least as fresh as the last relationship update for a resource. Clients
    that wish to force an update for a resource (e.g., making role changes
    immediately available to tenant users) can thus issue a relationship
    update to permissions-api and get the latest data for that resource.
    
    This commit assumes that the KV bucket used already exists;
    permissions-api will not attempt to create it. This is because the
    intention is that the KV bucket has a TTL set to something close to
    the SpiceDB quantization interval, which permissions-api is not
    necessarily aware of.
    
    Signed-off-by: John Schaeffer <[email protected]>
    jnschaeffer committed Jan 14, 2024
    Configuration menu
    Copy the full SHA
    fa1cfc3 View commit details
    Browse the repository at this point in the history

Commits on Jan 16, 2024

  1. Update Helm chart to support ZedToken cache

    This commit adds the necessary configs to the Helm chart to support
    populating a ZedToken cache for permissions-api.
    
    Signed-off-by: John Schaeffer <[email protected]>
    jnschaeffer committed Jan 16, 2024
    Configuration menu
    Copy the full SHA
    ea77d2e View commit details
    Browse the repository at this point in the history
  2. Add NATS creds to server deployment

    This commit adds NATS creds to the server deployment in the Helm
    chart.
    
    Signed-off-by: John Schaeffer <[email protected]>
    jnschaeffer committed Jan 16, 2024
    Configuration menu
    Copy the full SHA
    534a7bf View commit details
    Browse the repository at this point in the history
  3. Add tests for determining consistency

    This commit adds tests for determineConsistency.
    
    Signed-off-by: John Schaeffer <[email protected]>
    jnschaeffer committed Jan 16, 2024
    Configuration menu
    Copy the full SHA
    30e1adc View commit details
    Browse the repository at this point in the history