connect icon indicating copy to clipboard operation
connect copied to clipboard

Support for Redis ACL Type Auth

Open tfendt-belong-gg opened this issue 2 years ago • 9 comments

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
}

tfendt-belong-gg avatar Nov 14 '23 19:11 tfendt-belong-gg

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 avatar Nov 14 '23 20:11 mihaitodor

@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 avatar Nov 14 '23 20:11 tfendt-belong-gg

@tfendt-belong-gg yes you should fork, write your contribution and apply it via Pull Request

peczenyj avatar Nov 14 '23 20:11 peczenyj

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).

peczenyj avatar Nov 14 '23 20:11 peczenyj

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?

tfendt-belong-gg avatar Nov 14 '23 20:11 tfendt-belong-gg

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

peczenyj avatar Nov 14 '23 21:11 peczenyj

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 avatar Nov 15 '23 21:11 tfendt-belong-gg

@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.

Jeffail avatar Nov 15 '23 21:11 Jeffail

@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.

tfendt-belong-gg avatar Nov 15 '23 21:11 tfendt-belong-gg