Skip to content

allow redis connections over TLS #1687

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

Open
wants to merge 5 commits into
base: development
Choose a base branch
from

Conversation

Deeptanshu-sankhwar
Copy link

@Deeptanshu-sankhwar Deeptanshu-sankhwar commented May 3, 2025

Add TLS connection to Redis

Closes #1685

Description:

  • Added tls certification variables to environment
  • Add test cases to mock a pem file to test config

Checklist:

  • I have formatted my code using goimport and golangci-lint.
  • All new code is covered by unit tests.
  • This PR does not decrease the overall code coverage.
  • I have reviewed the code comments and documentation for clarity.

@@ -6,4 +6,7 @@ REDIS_PORT=2002

LOG_LEVEL=DEBUG


REDIS_TLS_ENABLED=false
Copy link
Member

Choose a reason for hiding this comment

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

We don't need these configs here if not used.
Also please add these conifgs in the documentation so it will be easy to find out for other people also.


if options.Password == "" {
options.Password = redisConfig.Password
if caCert := c.Get("REDIS_TLS_CA_CERT"); caCert != "" {
Copy link
Member

Choose a reason for hiding this comment

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

@Deeptanshu-sankhwar The Redis TLS implementation had a critical issue in the getRedisConfig function that prevented proper certificate loading. The code was treating certificate file paths as if they contained the certificate content directly, rather than reading the files. I will recommend to update the certificate handling to properly read file content before passing to certificate functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

This matches a feedback I made yesterday and I forgot to send

#1687 (comment)

// REDIS_TLS_KEY: PEM-encoded client private key (string or file path)
//
// If TLS is enabled, the function sets up the TLS config for the Redis client.
func getRedisConfig(c config.Config, logger datasource.Logger) *Config {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not updating the signature to something like

Suggested change
func getRedisConfig(c config.Config, logger datasource.Logger) *Config {
func getRedisConfig(c config.Config) (*Config, error) {

I would prefer log to be in the caller, also I'm unsure why the code continues on error in the implementation in this PR.

I mean when code is facing this

                    logger.Errorf("failed to append CA cert to pool")
                     logger.Errorf("failed to load client cert/key pair: %v", err)

It should return an error, no?

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.

Allow adding connection over TLS for Redis
3 participants