-
Notifications
You must be signed in to change notification settings - Fork 153
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
Keycloak backend plugin leads to DOS of Keycloak server #2471
Comments
I have prepared a fix for the issue. |
Hi @JohannesWill, this plugin has been migrated to https://github.com/backstage/community-plugins/tree/main/workspaces/keycloak and won't be maintained in this repository, so feel free to open a PR with your fix there! |
Additionally, could you raise this bug in the https://github.com/backstage/community-plugins repo and close this one? |
@JohannesWill I opened up a PR and set you as author but I wanted to double check with you on a couple of things right quick as I haven't been able to reproduce the problem, yet. First, I see that you mentioned using Second, I tested your changes with just 2500 users first, as that was easier for me to create at the time, and didn't notice any issues with the Keycloak server. I was also able to read them in relatively quickly. Could you give me a breakdown of how the groups look in your particular setup? Something along the lines of how many users on average are a part of a group. Finally, is there anyway you could provide info on how often you are making the sync requests with the app config value |
Another update, as I continue to attempt to reproduce. At the moment, I do not see any apparent issues with my Keycloak server during ingestion. My most recent test involved 2550 users and 850 groups where every user was assigned to every group. In the logs I can see:
Could you also provide what version of Keycloak you are using. |
We are using Keycloak v20.0.3 |
Were you able to test with a new version of the Keycloak plugin? I am not seeing any issues whenever I use |
I tested with "@backstage-community/plugin-catalog-backend-module-keycloak": "3.2.2" and I observe the same as with |
So strange, can you explain some of the setup for your users and groups? Are there any subgroups, how many users to a group, and so on. Are there any logs? Either the above that I shown in a comment or any errors? Sorry for all of the questions. For a little bit of background, we are having a hard time reproducing at the moment and the changes that are suggested are leading to timeout errors when we test them on our end. So, we are trying to figure out a fix that works for you and doesn't lead to any other problems. |
I think @JohannesWill reworked the code to use sequential requests instead of parallel operations by utilizing Promise.all(). Also, I'm considering how to reproduce the issue. Maybe the Keycloak server has limited CPU or memory in the deployment, which prevents it from handling a large number of HTTP requests. This could be the key to reproducing the issue... |
My patch was only a quick fix. import pLimit from 'p-limit';
//...
const limit = pLimit(config.maxConcurrency ?? Number.POSITIVE_INFINITY);
// The next line acts like range in python
const entityPromises = Array.from({ length: pageCount }, (_, i) =>
limit(() =>
entities
.find({
realm: config.realm,
max: entityQuerySize,
first: i * entityQuerySize,
})
.catch(err => {
logger.warn('Failed to retrieve Keycloak entities.', err);
return [];
}),
),
); and const limit = pLimit(config.maxConcurrency ?? Number.POSITIVE_INFINITY);
const kGroups = await Promise.all(
rawKGroups.map(g =>
limit(async () => {
g.members = await getAllGroupMembers(
client.groups as Groups,
g.id!,
config,
options,
);
if (isVersion23orHigher) {
if (g.subGroupCount! > 0) {
g.subGroups = await client.groups.listSubGroups({
parentId: g.id!,
first: 0,
max: g.subGroupCount,
briefRepresentation: false,
realm: config.realm,
});
}
if (g.parentId) {
const groupParent = await client.groups.findOne({
id: g.parentId,
realm: config.realm,
});
g.parent = groupParent?.name;
}
}
return g;
}),
),
);
` |
Describe the bug
I have setup the Keycloak backend plugin by following the steps given on below this link - https://janus-idp.io/plugins/keycloak/ .
Syncing the users and Groups will overload our Keycloak instance by doing many parrallel requests
Expected Behavior
What are the steps to reproduce this bug?
Versions of software used and environment
@janus-idp/backstage-plugin-keycloak-backend": "^2.0.8",
Backstage - 1.30.4 ([email protected])
Temporary Workaround:
During investigation of that problem I used patch-package to patch
@janus-idp/[email protected]
for the project I'm working on.With that pacht, where I serialized the calls to Keycloak, the problem is not reproduceable anymore.
Here is the diff that solved my problem:
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: