-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sec ops caching #35
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Round of refactoring
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 intodev
---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. Ifexp
is in the past or there's noexp
field, we won't cache the token. Notice DAPS returns a JSON object with the actual JWT and an additionalexpires_in
JSON field. We never considerexpires_in
since it isn't signed data so even if we got anexpires_in
with a time in the future but noexp
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. Ifexp
is in the past or there's noexp
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.