Skip to content

Conversation

KrumTy
Copy link
Collaborator

@KrumTy KrumTy commented Feb 17, 2025

Description

  • Issue: revoking access to INFO via ACL causes areas of the app not to work
  • Solution: fallback to HELLO command where possible, otherwise refactor logic

Notes

  • this PR addresses issues related to db connectivity when access to INFO is disabled
  • type-wise, the only mandatory field from the info response was 'version', something that's also present in the hello response
  • connecting to db only requires info command's response to check the redis' version (for recommendation and client info collect)

Updates

  • this PR evolved a bit as per @ArtemHoruzhenko 's suggestion
  • the logic for retrieving the info data has been unified inside the base client (see getInfo in redis.client.ts)
  • it basically checks for info, if no permissions are available - checks for data from hello;
  • in case hello is not available (redis v < 6.2.0) or something fails, defaults to a basic static object
  • the original PR was aimed at solving just RI-6849 but it so happens that it resolves multiple issues

@KrumTy KrumTy requested a review from pawelangelow February 18, 2025 11:14
@KrumTy KrumTy changed the title RI-6849: fallback to hello command when connecting to db [RI-6849] [RI-6846]: fallback to hello command when connecting to db Feb 19, 2025
@KrumTy KrumTy changed the title [RI-6849] [RI-6846]: fallback to hello command when connecting to db [RI-6849] [RI-6846] [RI-6847]: fallback to hello command when connecting to db Feb 19, 2025
@KrumTy KrumTy requested a review from dantovska February 19, 2025 12:07
Copy link
Collaborator

@ArtemHoruzhenko ArtemHoruzhenko left a comment

Choose a reason for hiding this comment

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

I'm not sure that using DatabaseInfoProvider will be easy in all app modules. I assume we might have a lot of circular dependencies then. Let's move this logic to RedisClient so it will be available everywhere. wdyt?

@KrumTy KrumTy changed the title [RI-6849] [RI-6846] [RI-6847]: fallback to hello command when connecting to db [RI-6849] [RI-6842] [RI-6846] [RI-6847]: fallback to hello command when connecting to db Feb 20, 2025
['info', 'server'],
{ replyEncoding: 'utf8' },
) as string);
const info = await client.getInfo(true, 'server');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's avoid getting various info sections avross the app.

Copy link
Collaborator Author

@KrumTy KrumTy Feb 21, 2025

Choose a reason for hiding this comment

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

Why though? Preserving the behavior is one thing, but I figured querying just specific sections should be faster. E.g. if we have an interval, querying the data and only carrying about one section it would make sense to only query that section. I might be wrong, let me know.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this slightly impact performance. Just don't like idea of merging objects in getInfo funciton.
If we want to stay with this logic we should enhance getInfo command to reply only particular section as it works now (most probably without storing it)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

refactored; I've removed the stored info object

['info', 'server'],
{ replyEncoding: 'utf8' },
) as string);
const reply = await client.getInfo();
Copy link
Collaborator

Choose a reason for hiding this comment

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

like here

{ replyEncoding: 'utf8' },
) as string,
);
const info = await redisClient.getInfo(true, 'clients');
Copy link
Collaborator

Choose a reason for hiding this comment

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

clients

{ replyEncoding: 'utf8' },
) as string,
);
const info = await redisClient.getInfo(true, 'server');
Copy link
Collaborator

Choose a reason for hiding this comment

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

server

* @param infoSection - e.g. server, clients, memory, etc.
*/
public async getInfo(force = false): Promise<object> {
public async getInfo(force = true, infoSection?: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's remove infoSection

Comment on lines 174 to 177
this.info = {
...this.info,
...infoData,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's replace this with entirely new object we've got

replyEncoding: 'utf8',
}) as string,
);
const info = await client.getInfo(true, 'keyspace');
Copy link
Collaborator

Choose a reason for hiding this comment

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

keyspace here

@KrumTy KrumTy changed the title [RI-6849] [RI-6842] [RI-6846] [RI-6847]: fallback to hello command when connecting to db [RI-6849] [RI-6842] [RI-6845] [RI-6846] [RI-6847]: fallback to hello command when connecting to db Feb 21, 2025
@KrumTy KrumTy changed the title [RI-6849] [RI-6842] [RI-6845] [RI-6846] [RI-6847]: fallback to hello command when connecting to db [RI-6849] [RI-6842] [RI-6843] [RI-6845] [RI-6846] [RI-6847]: fallback to hello command when connecting to db Feb 25, 2025
…led via ACL (#4390)

* RI-6848: add info_command_is_disabled to analytics when INFO is disabled via ACL

* add isInfoCommandDisabled prop to RedisClient

* preserve function signature

* set default value for isInfoCommandDisabled

* refactor getInfo

* update: always call HELLO if INFO fails
@KrumTy KrumTy changed the title [RI-6849] [RI-6842] [RI-6843] [RI-6845] [RI-6846] [RI-6847]: fallback to hello command when connecting to db RI-6658: fallback to hello command when connecting to db Feb 25, 2025
@KrumTy KrumTy changed the title RI-6658: fallback to hello command when connecting to db RI-6658: fallback to HELLO command when INFO is disabled via ACL Feb 25, 2025
Copy link
Collaborator

@pawelangelow pawelangelow left a comment

Choose a reason for hiding this comment

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

Tested and it looks OK. 🚀

Side note: I know that we merged few branches to this one, so this makes the whole change list bigger and it's hard to follow all the changes (big PR well known problem). I don't have perfect solution, but I'd rather prefer to merge them to main, than to a single branch that is merged back to main. (a.k.a. dont merge 3 > 2 > 1, but 1 to main, 2 to main and 3 to main). This way it's easier for me to see what happened.

Of course, the above is debatable, just saw it here and wanted to bring it up.

@pd-redis
Copy link
Collaborator

Tested and it looks OK. 🚀

Side note: I know that we merged few branches to this one, so this makes the whole change list bigger and it's hard to follow all the changes (big PR well known problem). I don't have perfect solution, but I'd rather prefer to merge them to main, than to a single branch that is merged back to main. (a.k.a. dont merge 3 > 2 > 1, but 1 to main, 2 to main and 3 to main). This way it's easier for me to see what happened.

Of course, the above is debatable, just saw it here and wanted to bring it up.

As long as 1,2,3 are individually mergable, yes! But if they don't make sense to be tested separately ...

Copy link
Collaborator

@ArtemHoruzhenko ArtemHoruzhenko left a comment

Choose a reason for hiding this comment

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

lgtm

@KrumTy KrumTy merged commit dd6358b into main Feb 26, 2025
28 checks passed
@KrumTy KrumTy deleted the feature/RI-6658/no-perm-info-command branch February 26, 2025 09:24
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.

6 participants