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 empty auth results to reduce db load #4104

Merged
merged 3 commits into from Nov 15, 2018
Merged

Cache empty auth results to reduce db load #4104

merged 3 commits into from Nov 15, 2018

Conversation

mhenke1
Copy link
Contributor

@mhenke1 mhenke1 commented Nov 8, 2018

Cache negative auth responses to avoid going to the DB with every identical call

Description

Since negative auth responses (Identity.get) are not cached,
all requests with a non existing namespace or an invalid authkey will perform queries to the subject db.
A user can influence OW performance by issuing a high number of those calls.

ThIs PR changes that behavior in the way, that negative auth results are cached as None value.
Subsequent Identical calls will only use the cache (for the 5 minutes cache period).
The external interface and behavior of the Identity.get methods stays unchanged.

Related issue and scope

  • I opened an issue to propose and discuss this change

My changes affect the following components

  • API
  • Controller
  • Message Bus (e.g., Kafka)
  • Loadbalancer
  • Invoker
  • Intrinsic actions (e.g., sequences, conductors)
  • Data stores (e.g., CouchDB)
  • Tests
  • Deployment
  • CLI
  • General tooling
  • Documentation

Types of changes

  • Bug fix (generally a non-breaking change which closes an issue).
  • Enhancement or new feature (adds new functionality).
  • Breaking change (a bug fix or enhancement which changes existing behavior).

Checklist:

  • I signed an Apache CLA.
  • I reviewed the style guides and followed the recommendations (Travis CI will check :).
  • I added tests to cover my changes.
  • My changes require further changes to the documentation.
  • I updated the documentation where necessary.

@mhenke1
Copy link
Contributor Author

mhenke1 commented Nov 8, 2018

[PG3:2985 ok]

@codecov-io
Copy link

codecov-io commented Nov 8, 2018

Codecov Report

Merging #4104 into master will decrease coverage by 3.49%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #4104     +/-   ##
=========================================
- Coverage   84.57%   81.07%   -3.5%     
=========================================
  Files         148      148             
  Lines        7110     7118      +8     
  Branches      431      423      -8     
=========================================
- Hits         6013     5771    -242     
- Misses       1097     1347    +250
Impacted Files Coverage Δ
...re/database/MultipleReadersSingleWriterCache.scala 98% <100%> (+0.32%) ⬆️
...la/org/apache/openwhisk/core/entity/Identity.scala 92.85% <100%> (+0.26%) ⬆️
...core/database/cosmosdb/RxObservableImplicits.scala 0% <0%> (-100%) ⬇️
...core/database/cosmosdb/CosmosDBArtifactStore.scala 0% <0%> (-95.54%) ⬇️
...sk/core/database/cosmosdb/CosmosDBViewMapper.scala 0% <0%> (-92.6%) ⬇️
...whisk/core/database/cosmosdb/CosmosDBSupport.scala 0% <0%> (-83.34%) ⬇️
...abase/cosmosdb/CosmosDBArtifactStoreProvider.scala 0% <0%> (-62.5%) ⬇️
...penwhisk/core/database/cosmosdb/CosmosDBUtil.scala 92% <0%> (-4%) ⬇️
...che/openwhisk/core/database/CouchDbRestStore.scala 73.23% <0%> (-0.51%) ⬇️
... and 22 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 775b757...cccedc2. Read the comment docs.

Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one, that's indeed an attack vector against the database.

LGTM!

@rabbah
Copy link
Member

rabbah commented Nov 8, 2018

Agree. Is 5 minutes too high?

@chetanmeh
Copy link
Member

Caching such negative lookups may be abused to put lots of of entries in cache and put pressure on heap (causing eviction of valid entries) given our caches are not bounded by size. May be use a separate bounded cache for such entries.

@markusthoemmes
Copy link
Contributor

@chetanmeh the cache is "bounded" as in its entries are garbage collectable.

@chetanmeh
Copy link
Member

@markusthoemmes All caches are currently configured with softValues thereby the entries are evicted (apart from expiry) on the basis of jvm garbage collection. Now if an attacker is given a way to add entry to one of the cache in arbitrary manner then it can possibly be abused to add lots of entries in Identity cache. This would put pressure on heap and would possibly trigger evictions of valid data in all other caches also.

If we use a bounded cache in terms of entry count then only identity cache would be impacted but other caches would not get impacted.

@mhenke1
Copy link
Contributor Author

mhenke1 commented Nov 9, 2018

I have now limited the auth cache hard to 100000 entries. Worth to be configurable ?

@chetanmeh
Copy link
Member

I have now limited the auth cache hard to 100000 entries. Worth to be configurable ?

@mhenke1 Should be fine to leave it specified in code for now

@mhenke1
Copy link
Contributor Author

mhenke1 commented Nov 14, 2018

[PG 2:3878 ok]

@mhenke1
Copy link
Contributor Author

mhenke1 commented Nov 14, 2018

@chetanmeh I have changed the code as suggested

@chetanmeh
Copy link
Member

@rabbah @markusthoemmes can you review cache changes once

Copy link
Member

@rabbah rabbah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chetanmeh chetanmeh merged commit 536ce94 into apache:master Nov 15, 2018
@mhenke1 mhenke1 deleted the identity_cache_improvement branch November 15, 2018 10:32
BillZong pushed a commit to BillZong/openwhisk that referenced this pull request Nov 18, 2019
cache empty results to avoid performance hits by calling webactions repeatedly. Also configure a fixed size for identity cache to ensure it does not grow unbounded with too many negative entries.

* limit size of auth cache

* Simplify logic to create the cache

Co-Authored-By: mhenke1 <martin.henke@web.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants