Support for Redis ACL Type Auth
We are using Redis with ACL for our access control. Currently the Benthos redis implementation doesn't support connecting to redis with a username and it results in an error when trying to connect.
I updated benthos locally with the necessary changes to support this. I have also tested this locally and confirmed it works with our setup. What route do I take to get this added?
Modified internal -> impl -> redis -> client.go
Added the following:
Example("redis://foousername:foopassword@redisplace:6379").
var user string
user = rurl.Username
Username: user,
Full Function Code with Mods:
func getClient(parsedConf *service.ParsedConfig) (redis.UniversalClient, error) {
urlStr, err := parsedConf.FieldString("url")
if err != nil {
return nil, err
}
kind, err := parsedConf.FieldString("kind")
if err != nil {
return nil, err
}
master, err := parsedConf.FieldString("master")
if err != nil {
return nil, err
}
tlsConf, tlsEnabled, err := parsedConf.FieldTLSToggled("tls")
if err != nil {
return nil, err
}
if !tlsEnabled {
tlsConf = nil
}
// We default to Redis DB 0 for backward compatibility
var redisDB int
var user string
var pass string
var addrs []string
// handle comma-separated urls
for _, v := range strings.Split(urlStr, ",") {
url, err := url.Parse(v)
if err != nil {
return nil, err
}
if url.Scheme == "tcp" {
url.Scheme = "redis"
}
rurl, err := redis.ParseURL(url.String())
if err != nil {
return nil, err
}
addrs = append(addrs, rurl.Addr)
redisDB = rurl.DB
user = rurl.Username
pass = rurl.Password
}
var client redis.UniversalClient
opts := &redis.UniversalOptions{
Addrs: addrs,
DB: redisDB,
Username: user,
Password: pass,
TLSConfig: tlsConf,
}
switch kind {
case "simple":
client = redis.NewClient(opts.Simple())
case "cluster":
client = redis.NewClusterClient(opts.Cluster())
case "failover":
opts.MasterName = master
client = redis.NewFailoverClient(opts.Failover())
default:
err = fmt.Errorf("invalid redis kind: %s", kind)
}
return client, err
}
Hey @tfendt-belong-gg 👋 looks like a reasonable addition to make. PRs are welcome! You'll also want to modify the clientFields() function to add that example and then run make docs and commit the changed .md files.
@mihaitodor Do I have to fork the repo first and create a PR from that? It doesn't appear I can create a branch on this project.
@tfendt-belong-gg yes you should fork, write your contribution and apply it via Pull Request
Optionally you can create a branch in your repo/fork, that is your organization of work.
for some trivial changes we can use the web interface of GitHub itself, that can perform some operations automatically. However some operations must be done such as run make docs
btw, after your first git push, the option to create a pull request will be visible in the web interface of your repo and I think each push will be followed witha link to create the pull request. So it is (almost) piece of cake.
but remember that you MUST sign your commits (add -s to the git commit command line).
PR created! https://github.com/benthosdev/benthos/pull/2240
I didn't sign the commit though. Should I go back and add an empty commit with the -s flag?
Don’t worry
after submit the PR there are some GitHub actions. One is the DCO that will check the signatures and will provide you a command line to fix is combining git rebase and force oush
How long until reviews happen and this can be merged in? I just need to know if I should come up with a temp solution for our project while we wait.
@tfendt-belong-gg it's a small and sensible change so I can merge it now, I'm expecting to do a release probably next week.
@tfendt-belong-gg it's a small and sensible change so I can merge it now, I'm expecting to do a release probably next week.
Wow! Thank you. I'll let my team know.