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

Sec ops caching #35

Merged
merged 20 commits into from
Apr 3, 2020
Merged

Sec ops caching #35

merged 20 commits into from
Apr 3, 2020

Conversation

c0c0n3
Copy link
Member

@c0c0n3 c0c0n3 commented Apr 2, 2020

This PR implements caching of security operations as outlined in #9.
Notice this PR also brings to master unrelated (but welcome!) code changes that got merged into dev---see PR #33.

Overview

A new component (orionadapter/cache package) provides the caching functionality to the adapter through a typed map-like interface that shields the rest of the code from the inner details and whether the backing cache is in memory or distributed. At the moment, we piggyback on an in-memory backing store, Ristretto, that comes with sophisticated caching policies, high-performance concurrent access and correctness guarantees under concurrent usage. We cache DAPS ID tokens, AuthZ decisions and adapter configuration each in its own backing store to cater for different usage patterns---e.g. we have different cache eviction policies to avoid a situation where too many AuthZ entries push a DAPS ID token out of the cache. The caches got tuned quite a bit and the default settings should cater for most scenarios but there's no substitute for observing real prod workloads and then tune the cache accordingly. We should provide config knobs to play with at some point. Below is a sum up of each cache's features.

DAPS ID cache

After getting a provider ID token from DAPS, we keep it until it expires so won't call again the DAPS server until then. Expiry is that specified by the exp field of the DAPS JWT. If exp is in the past or there's no exp field, we won't cache the token. Notice DAPS returns a JSON object with the actual JWT and an additional expires_in JSON field. We never consider expires_in since it isn't signed data so even if we got an expires_in with a time in the future but no exp in the future, then we still wouldn't cache the token.

AuthZ decision cache

We identify AuthZ calls by consumer JTW and all other relevant inputs (HTTP method/path, FiWare service, etc.) so that two calls are equivalent just in case they have the same inputs. After getting an AuthZ decision for a set of inputs, we cache the authorisation decision until the input consumer JWT expires. Expiry is that specified by the JWT exp field. If exp is in the past or there's no exp field, we won't cache the decision. If another HTTP request comes in which requires an equivalent AuthZ call, we'll use the cached decision unless it has expired, in which case we'll call AuthZ again. Cache growth is capped at 1GB to avoid the adapter becoming a memory hog and admission/eviction policies try to maximise hit ratio.

Adapter configuration cache

We cache adapter configuration too. This is only needed to support our stopgap solution (#25) to #24 and we can ditch it as soon as a better option becomes available. This cache is the simplest so far: it only stores one item at a time (the adapter config) until a fresher config becomes available at which point the old config gets replaced with the new. This happens every time the Mixer calls the adapter---the gRPC request contains the latest config.

@c0c0n3 c0c0n3 added this to In Review in Beta release Apr 2, 2020
@c0c0n3 c0c0n3 merged commit 62e46a3 into master Apr 3, 2020
@c0c0n3 c0c0n3 mentioned this pull request Apr 3, 2020
@c0c0n3 c0c0n3 moved this from In Review to Done in Beta release Apr 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

1 participant