-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
OIDC: Limit number of dynamic tenants #42804
base: main
Are you sure you want to change the base?
Conversation
🎊 PR Preview 646c96b has been successfully built and deployed to https://quarkus-pr-main-42804-preview.surge.sh/version/main/guides/
|
905ff84
to
919d339
Compare
Marking this PR as draft, I'm reworking the changes. The current state is rather a preparation. |
} | ||
} | ||
|
||
public TenantConfigContext getExistingTenantConfigContext(String tenantId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider Dynamic
instead of Existing
Hi @snazy Thanks, I've had a quick look, and it looks good |
…enants This is a prerequisite for quarkusio#42804 w/o any functional change. It moves the code to get/add tenants into the `TenantConfigBean`, so the limitation for the amount of dynamic tenants can be done there.
…enants This is a prerequisite for quarkusio#42804 w/o any functional change. It moves the code to get/add tenants into the `TenantConfigBean`, so the limitation for the amount of dynamic tenants can be done there.
…enants This is a prerequisite for quarkusio#42804 w/o any functional change. It moves the code to get/add tenants into the `TenantConfigBean`, so the limitation for the amount of dynamic tenants can be done there.
919d339
to
a41ea94
Compare
a41ea94
to
d0257dc
Compare
05f0d34
to
cdfb3d1
Compare
return new TenantConfigBean(staticTenantsConfig, defaultTenantContext, new LongSupplier() { | ||
@Override | ||
public long getAsLong() { | ||
return System.nanoTime(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could change to currentTimeMillis()
- however not sure whether all OSes (looking at you, Windows...) work fine then.
Lets `TenantConfigBean` be the sole "owner" of the static/dynamic tenants maps, adds/changes accessor methods for tenants. Also introduces a functional interface to create tenants. No functional change, only moving code around. Also some minor code cleanups (reducing the amount of warnings in IntelliJ).
…ved public functions, simplify some more code
Introduce a new configuration option `quarkus.oidc.dynamic-tenant-limit` as an opt-in to limit the number of active dynamic OIDC tenants. The default is no dynamic tenant limit. This change adds the field `volatile long TenantConfigContext.lastUsed`, and removes the field `TenantConfigContext.ready` to keep the heap footprint the same. The `lastUsed` field is initially set to "now" and updated when the dynamic tenant is being accessed. When a new dynamic tenant is about to be added to the dynamic tenants map, eviction runs, if there are more dynamic tenants than configured via `dynami-tenant-limit`. The eviction algo is built to iterate over the dynamic tenants only once - it may need to iterate more often, if one of the eviction candidates has been accessed in the mean time. There is no linked-list structure to form an LRU list/queue, as that likely causes more runtime overhead (pointer updates, synchronization) than the cost of iterating over the list once in a while. The assumption is that the map of dynamic tenants has not a lot of "churn".
cdfb3d1
to
91f6dee
Compare
Thanks @snazy, I'll have a closer look once the PRs it depends on are merged. For ex, look at the back channel logout cache and corresponding configuration properties in the Logout config group. Now that you have encapsulated the dynamic map nicely, I believe we should just have DynamicTenantsMap extending the abstract cache impl, instead of the dynamic tenants map, which should also terminate the optional Vertx timer on the shutdown |
Introduce a new configuration option
quarkus.oidc.dynamic-tenant-limit
as an opt-in to limit the number of active dynamic OIDC tenants. The default is no dynamic tenant limit.This change adds the field
volatile long TenantConfigContext.lastUsed
, and removes the fieldTenantConfigContext.ready
to keep the heap footprint the same. ThelastUsed
field is initially set to "now" and updated when the dynamic tenant is being accessed.When a new dynamic tenant is about to be added to the dynamic tenants map, eviction runs, if there are more dynamic tenants than configured via
dynami-tenant-limit
. The eviction algo is built to iterate over the dynamic tenants only once - it may need to iterate more often, if one of the eviction candidates has been accessed in the mean time. There is no linked-list structure to form an LRU list/queue, as that likely causes more runtime overhead (pointer updates, synchronization) than the cost of iterating over the list once in a while. The assumption is that the map of dynamic tenants has not a lot of "churn".Fixes #42803