10000 Allow authenticating with a username to redis by maddymeows · Pull Request #1488 · coturn/coturn · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow authenticating with a username to redis #1488

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

Merged
merged 2 commits into from
Nov 19, 2024

Conversation

maddymeows
Copy link
Contributor

I needed this

I just looked for occurrences of password and added username branches there. Let me know if there's anything wrong, I'm not proficient in C at all.

@eakraly
Copy link
Collaborator
eakraly commented Jun 2, 2024

Thank you @maddymeows !
It seems it would allow coturn to work with Redis6 that has new ACL feature

Could you please rebase the PR and also explain if you tested with new and old redis.
Does it require minimal version of hiredis to support it?

@maddymeows maddymeows force-pushed the redis-username branch 4 times, most recently from 70e9221 to 875358d Compare June 2, 2024 16:53
@maddymeows
Copy link
Contributor Author
maddymeows commented Jun 2, 2024

Sorry for tagging the regression fix alongside this PR, came up in testing after rebasing.

Could you please rebase the PR

Done

and also explain if you tested with new and old redis.

I've tested on debian 10 which has redis dated before ACLs were introduced, works fine as long as you don't configure a username.
I've also tested on latest debian and fedora and works just as well

Does it require minimal version of hiredis to support it?

As far as I know, no

@@ -163,9 +167,6 @@ static Ryconninfo *RyconninfoParse(const char *userdb, char **errmsg) {
if (!(co->host)) {
co->host = strdup("127.0.0.1");
}
if (!(co->password)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this change?

Copy link
Contributor Author
@maddymeows maddymeows Jun 3, 2024

Choose a reason for hiding this comment

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

Originally during testing I created an extra branch if (!(co->user)) { co->user = strdup(""); }.

However, I found out that it made coturn always authenticate with a username and password, which would break for redis servers that don't have the ACL feature.

That's because the branches using password (which I ended up copying for username branches) checked if the pointer to password was set, which it always was with the statement I just removed, rather than if password contained a useful value. So the password conditionals haven't been working for a while, coturn just discarded the error that redis threw out and continued on (which is fine, but not ideal).

Hence also changes to make those branches co->password && strlen(co->password) rather than just co->password, just in case. I could effectively change them to co->password && co->password[0] but strlen felt nicer.

Error handling of missing auth doesn't seem to be handled fully correctly from what I grasp, but happens moreso as a side effect, the side effect of using the side effect is it never warns about if the password is needed which is why there are no logs complaining about use of AUTH when wasn't needed.

@@ -268,7 +273,7 @@
}
}

ret = redisLibeventAttach(base, co->host, co->port, co->password, atoi(co->dbname));
ret = redisLibeventAttach(base, co->host, co->port, co->user, co->password, atoi(co->dbname));

Check warning

Code scanning / PREfast

'co->dbname' could be '0': this does not adhere to the specification for the function 'atoi'.

'co->dbname' could be '0': this does not adhere to the specification for the function 'atoi'.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

co->dbname is never null because a default is given in RyconninfoParse, I don't know how to silence this.

@eakraly
Copy link
Collaborator
eakraly commented Nov 18, 2024

Hi @maddymeows ! Could you please update the PR so I can merge it into upcoming version? Thanks

@maddymeows
Copy link
Contributor Author

@eakraly done!

@eakraly eakraly merged commit c4a954a into coturn:master Nov 19, 2024
@justinschoeman
Copy link

This commit breaks unauthenticated redis connections ("select " is not sent if password is not set).

@maddymeows
Copy link
Contributor Author

This commit breaks unauthenticated redis connections ("select " is not sent if password is not set).

#1668

ggarber pushed a commit that referenced this pull request May 21, 2025
Fixes a regression pointed out at
<#1488 (comment)>.

A regression was introduced in the last PR where the dbname parameter
was not respected if using redis without authentication. The logic for
sending the select command responsible for switching to the correct
database was wrongly guarded behind authentication being provided. This
PR flattens the control flow so the select command is always sent,
whether using authentication or not.
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.

3 participants
0