Skip to content
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

Add TLS/SSL and mTLS support for Redis #2055

Open
nmvinicius opened this issue Mar 5, 2025 · 0 comments
Open

Add TLS/SSL and mTLS support for Redis #2055

nmvinicius opened this issue Mar 5, 2025 · 0 comments

Comments

@nmvinicius
Copy link

Is your feature request related to a problem? Please describe.
No problem is reported at the moment. The idea is to offer TLS, SSL, and mTLS support for Redis, ensuring the possibility of using a user and password if necessary.

Describe the solution you'd like
Allow the configuration of TLS (and optional certificates) via environment variables, while preserving support for credentials. This covers scenarios with or without certificate use.

Describe alternatives you've considered

  1. Use unencrypted connections only.
  2. Manually set each parameter without environment variables.

packages/lib/src/redis.ts

import { env } from "@typebot.io/env";
import { Redis, RedisOptions } from "ioredis";
import * as fs from 'fs';

declare const global: { redis: Redis | undefined };
let redis: Redis | undefined;

const redisOptions: RedisOptions = {};

if (env.REDIS_SSL === "true") {
  redisOptions.tls = {};
  
  if (env.REDIS_REJECT_UNAUTHORIZED === "false") {
    redisOptions.tls.rejectUnauthorized = false;
  }

  if (env.REDIS_CA_PATH) {
    redisOptions.tls.ca = [fs.readFileSync(env.REDIS_CA_PATH)];
  }
  if (env.REDIS_CERT_PATH) {
    redisOptions.tls.cert = fs.readFileSync(env.REDIS_CERT_PATH);
  }
  if (env.REDIS_KEY_PATH) {
    redisOptions.tls.key = fs.readFileSync(env.REDIS_KEY_PATH);
  }
}

if (env.NODE_ENV === "production" && !process.versions.bun && env.REDIS_URL) {
  redis = new Redis(env.REDIS_URL, redisOptions);
} else if (env.REDIS_URL) {
  if (!global.redis) {
    global.redis = new Redis(env.REDIS_URL, redisOptions);
  }
  redis = global.redis;
}

export default redis;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog ☁️
Development

No branches or pull requests

2 participants