Skip to content

Conversation

@Oscaner
Copy link

@Oscaner Oscaner commented Jan 7, 2026

Description

Add comprehensive SSL/TLS support for Redis connections with configurable certificate verification modes. Introduces new environment variables for SSL configuration including REDIS_USE_SSL, REDIS_SSL_CERT_REQS (supporting CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED), and REDIS_SSL_CA_CERTS for custom CA certificates.

Changes:

  • Add Redis SSL configuration options to .env.example
  • Implement RedisTLSConfig() method to build tls.Config based on environment settings
  • Pass TLS config to both standard Redis and Sentinel mode initializers
  • Support custom CA certificate loading and verification modes
  • Set minimum TLS version to 1.2 for security
  • Minor whitespace cleanup in existing config comments

This enables secure Redis connections in production environments with flexible certificate verification options.

Fixes #450

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Performance improvement
  • Other

Essential Checklist

Testing

  • I have tested the changes locally and confirmed they work as expected
  • I have added unit tests where necessary and they pass successfully

Bug Fix (if applicable)

  • I have used GitHub syntax to close the related issue (e.g., Fixes #123 or Closes #123)

Additional Information

Please provide any additional context that would help reviewers understand the changes.

Add comprehensive SSL/TLS support for Redis connections with configurable certificate verification modes. Introduces new environment variables for SSL configuration including REDIS_USE_SSL, REDIS_SSL_CERT_REQS (supporting CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED), and REDIS_SSL_CA_CERTS for custom CA certificates.

Changes:
- Add Redis SSL configuration options to .env.example
- Implement RedisTLSConfig() method to build tls.Config based on environment settings
- Pass TLS config to both standard Redis and Sentinel mode initializers
- Support custom CA certificate loading and verification modes
- Set minimum TLS version to 1.2 for security
- Minor whitespace cleanup in existing config comments

This enables secure Redis connections in production environments with flexible certificate verification options.
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jan 7, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Oscaner, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the security of Redis connections by adding robust SSL/TLS configuration capabilities. It allows users to enable encrypted communication, specify certificate verification requirements, and provide custom Certificate Authority (CA) certificates, making the application more secure in production environments.

Highlights

  • Redis SSL/TLS Configuration: Introduced comprehensive SSL/TLS support for Redis connections, allowing secure communication with Redis instances.
  • Configurable Certificate Verification: Added new environment variables (REDIS_USE_SSL, REDIS_SSL_CERT_REQS, REDIS_SSL_CA_CERTS) to control SSL usage, certificate verification modes (CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED), and custom CA certificates.
  • TLS Configuration Integration: Implemented a RedisTLSConfig() method to build the tls.Config based on environment settings and integrated this configuration into both standard Redis and Sentinel mode initializers.
  • Security Enhancements: Set the minimum TLS version to 1.2 for all Redis SSL/TLS connections to ensure modern security standards.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Oscaner
Copy link
Author

Oscaner commented Jan 7, 2026

/gemini review

@dosubot dosubot bot added enhancement New feature or request go Pull requests that update go code plugin-daemon labels Jan 7, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces SSL/TLS support for Redis connections, a valuable security enhancement. The implementation is generally well-done, adding new environment variables and the necessary logic to configure TLS. However, I've identified a potential memory leak in the CERT_OPTIONAL handling due to a reference cycle. Additionally, there are a couple of places where the code can be simplified by removing redundant checks. My review includes suggestions to address these points.

…fy SSL setup

- Capture only RootCAs in VerifyConnection closure to avoid retaining
  entire tlsConf and potential reference cycles
- Remove redundant nil checks for tlsConf in Redis client initialization
  since tlsConf is guaranteed to be non-nil when useSsl is true
- Update comments to reflect actual behavior and constraints
@Oscaner
Copy link
Author

Oscaner commented Jan 7, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces comprehensive SSL/TLS support for Redis connections, which is a valuable security enhancement. The changes correctly integrate new environment variables for SSL configuration into the application's configuration and pass the generated tls.Config to both standard Redis and Sentinel mode initializers. The implementation handles custom CA certificate loading and sets a minimum TLS version, which are good security practices. However, there is a potential issue in the CERT_OPTIONAL verification logic that could compromise the intended security.

@Oscaner
Copy link
Author

Oscaner commented Jan 7, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces comprehensive SSL/TLS support for Redis connections, which is a great security enhancement. The changes are well-structured, adding new configuration options and integrating them into the Redis client initialization for both standard and Sentinel modes. The use of a minimum TLS version and support for custom CA certificates are excellent practices. My main feedback is on the implementation of the CERT_OPTIONAL verification mode, which appears to be overly complex and potentially insecure. I've provided a detailed comment with a suggestion for simplification.

@Oscaner
Copy link
Author

Oscaner commented Jan 7, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces comprehensive SSL/TLS support for Redis connections, which is a valuable security improvement. The implementation is solid, with configurable certificate verification and support for custom CAs. The code is clean and correctly handles configuration errors during application startup. I have one suggestion to further improve the code's maintainability.

Comment on lines 291 to 331
func (c *Config) RedisTLSConfig() (*tls.Config, error) {
if !c.RedisUseSsl {
return nil, nil
}

tlsConf := &tls.Config{
MinVersion: tls.VersionTLS12,
}

// Load custom CA certificates if provided
if strings.TrimSpace(c.RedisSSLCACerts) != "" {
pem, err := os.ReadFile(c.RedisSSLCACerts)
if err != nil {
return nil, fmt.Errorf("read REDIS_SSL_CA_CERTS: %w", err)
}
pool := x509.NewCertPool()
if !pool.AppendCertsFromPEM(pem) {
return nil, fmt.Errorf("failed to append CA certs from %s", c.RedisSSLCACerts)
}
tlsConf.RootCAs = pool
}

// Configure certificate verification based on REDIS_SSL_CERT_REQS
certReqs := strings.ToUpper(strings.TrimSpace(c.RedisSSLCertReqs))
switch certReqs {
case "CERT_NONE":
// Skip all certificate verification (insecure)
tlsConf.InsecureSkipVerify = true
case "CERT_OPTIONAL", "CERT_REQUIRED", "":
// Require valid certificate verification (default and most secure)
// CERT_OPTIONAL is treated as CERT_REQUIRED for client-side TLS,
// as servers almost always present certificates and the client's
// choice is whether to validate them or not
tlsConf.InsecureSkipVerify = false
default:
// Invalid value - return an error instead of silently defaulting
return nil, fmt.Errorf("invalid REDIS_SSL_CERT_REQS value: %s (valid options: CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED)", certReqs)
}

return tlsConf, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve maintainability and reduce the risk of typos, it's a good practice to use constants for string literals that represent configuration values. This makes the code more robust and easier to read.

I've also slightly improved the error message for invalid options by quoting the provided value and showing the original user input, which can aid in debugging.

func (c *Config) RedisTLSConfig() (*tls.Config, error) {
	if !c.RedisUseSsl {
		return nil, nil
	}

	const (
		certReqsNone     = "CERT_NONE"
		certReqsOptional = "CERT_OPTIONAL"
		certReqsRequired = "CERT_REQUIRED"
	)

	tlsConf := &tls.Config{
		MinVersion: tls.VersionTLS12,
	}

	// Load custom CA certificates if provided
	if strings.TrimSpace(c.RedisSSLCACerts) != "" {
		pem, err := os.ReadFile(c.RedisSSLCACerts)
		if err != nil {
			return nil, fmt.Errorf("read REDIS_SSL_CA_CERTS: %w", err)
		}
		pool := x509.NewCertPool()
		if !pool.AppendCertsFromPEM(pem) {
			return nil, fmt.Errorf("failed to append CA certs from %s", c.RedisSSLCACerts)
		}
		tlsConf.RootCAs = pool
	}

	// Configure certificate verification based on REDIS_SSL_CERT_REQS
	certReqs := strings.ToUpper(strings.TrimSpace(c.RedisSSLCertReqs))
	switch certReqs {
	case certReqsNone:
		// Skip all certificate verification (insecure)
		tlsConf.InsecureSkipVerify = true
	case certReqsOptional, certReqsRequired, "":
		// Require valid certificate verification (default and most secure)
		// CERT_OPTIONAL is treated as CERT_REQUIRED for client-side TLS,
		// as servers almost always present certificates and the client's
		// choice is whether to validate them or not
		tlsConf.InsecureSkipVerify = false
	default:
		// Invalid value - return an error instead of silently defaulting
		return nil, fmt.Errorf("invalid REDIS_SSL_CERT_REQS value: %q (valid options: %s, %s, %s)",
			c.RedisSSLCertReqs, certReqsNone, certReqsOptional, certReqsRequired)
	}

	return tlsConf, nil
}

@Oscaner
Copy link
Author

Oscaner commented Jan 8, 2026

Hi @Yeuoly, please review.

@Yeuoly
Copy link
Contributor

Yeuoly commented Jan 8, 2026

It looks good to me, but it will be better if we added some tests to it, just to check if the config parser will work.

Also, I prefer to have some comments on REDIS_SSL_CA_CERTS, to let others know that they may just use the path of the CA as this environment.

@Yeuoly Yeuoly requested a review from Stream29 January 8, 2026 05:30
@Oscaner
Copy link
Author

Oscaner commented Jan 8, 2026

It looks good to me, but it will be better if we added some tests to it, just to check if the config parser will work.

Also, I prefer to have some comments on REDIS_SSL_CA_CERTS, to let others know that they may just use the path of the CA as this environment.

Sure, done for tests and comments.

/gemini review

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jan 9, 2026
@Oscaner
Copy link
Author

Oscaner commented Jan 9, 2026

Hi @Stream29, thanks to review. I resolved with your suggestions, and rich the tests. Please review again.

…n tests

Update all InitRedisClient function calls across test files to include the new nil parameter for TLS configuration. This change maintains backward compatibility by explicitly passing nil for TLS settings in non-TLS test scenarios.
@Oscaner Oscaner requested a review from Stream29 January 9, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code plugin-daemon size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

redis ssl connect

3 participants