From 11eb3230d238ee867289dbdbe987e1fd7a388993 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Wed, 25 Sep 2024 13:30:12 -0600 Subject: [PATCH 1/3] fix(redis): allow tls config to be used for redis --- docker-compose.yaml | 1 + src/config.ts | 3 +++ src/init/header-stores.ts | 1 + src/init/resolvers.ts | 3 +++ src/store/redis-kv-store.ts | 3 +++ src/system.ts | 1 + 6 files changed, 12 insertions(+) diff --git a/docker-compose.yaml b/docker-compose.yaml index 092610e8..0974cf4f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -64,6 +64,7 @@ services: - IO_PROCESS_ID=${IO_PROCESS_ID:-} - CHAIN_CACHE_TYPE=${CHAIN_CACHE_TYPE:-redis} - REDIS_CACHE_URL=${REDIS_CACHE_URL:-redis://redis:6379} + - REDIS_USE_TLS=${REDIS_USE_TLS:-false} - REDIS_CACHE_TTL_SECONDS=${REDIS_CACHE_TTL_SECONDS:-} - NODE_JS_MAX_OLD_SPACE_SIZE=${NODE_JS_MAX_OLD_SPACE_SIZE:-} - ENABLE_FS_HEADER_CACHE_CLEANUP=${ENABLE_FS_HEADER_CACHE_CLEANUP:-true} diff --git a/src/config.ts b/src/config.ts index 5cfef95c..10be111b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -209,6 +209,9 @@ export const REDIS_CACHE_URL = env.varOrDefault( 'redis://localhost:6379', ); +export const REDIS_USE_TLS = + env.varOrDefault('REDIS_USE_TLS', 'false') === 'true'; + // Default Redis TTL export const REDIS_CACHE_TTL_SECONDS = +env.varOrDefault( 'REDIS_CACHE_TTL_SECONDS', diff --git a/src/init/header-stores.ts b/src/init/header-stores.ts index 71b82d69..6cbfcedb 100644 --- a/src/init/header-stores.ts +++ b/src/init/header-stores.ts @@ -50,6 +50,7 @@ const createKvBufferStore = ({ return new RedisKvStore({ redisUrl: config.REDIS_CACHE_URL, ttlSeconds: redisTtlSeconds, + useTls: config.REDIS_USE_TLS, log, }); } diff --git a/src/init/resolvers.ts b/src/init/resolvers.ts index 9b85d9dc..778a5181 100644 --- a/src/init/resolvers.ts +++ b/src/init/resolvers.ts @@ -36,12 +36,14 @@ export const createArNSKvStore = ({ log, type, redisUrl, + useTls, ttlSeconds, maxKeys, }: { type: 'redis' | 'node' | string; log: Logger; redisUrl: string; + useTls: boolean; ttlSeconds: number; maxKeys: number; }): KVBufferStore => { @@ -56,6 +58,7 @@ export const createArNSKvStore = ({ log, redisUrl, ttlSeconds, + useTls, }); } return new NodeKvStore({ ttlSeconds, maxKeys }); diff --git a/src/store/redis-kv-store.ts b/src/store/redis-kv-store.ts index 714bfd0d..9b48c07c 100644 --- a/src/store/redis-kv-store.ts +++ b/src/store/redis-kv-store.ts @@ -28,16 +28,19 @@ export class RedisKvStore implements KVBufferStore { constructor({ log, redisUrl, + useTls, ttlSeconds, }: { log: winston.Logger; redisUrl: string; + useTls: boolean; ttlSeconds: number; }) { this.log = log.child({ class: this.constructor.name }); this.ttlSeconds = ttlSeconds; this.client = createClient({ url: redisUrl, + ...(useTls ? { tls: {} } : {}), // use base tls options if useTls is true }); this.client.on('error', (error: any) => { this.log.error(`Redis error`, { diff --git a/src/system.ts b/src/system.ts index 6ca047e7..b06db503 100644 --- a/src/system.ts +++ b/src/system.ts @@ -558,6 +558,7 @@ export const arnsResolverCache = new KvArnsStore({ redisUrl: config.REDIS_CACHE_URL, ttlSeconds: config.ARNS_CACHE_TTL_SECONDS, maxKeys: config.ARNS_CACHE_MAX_KEYS, + useTls: config.REDIS_USE_TLS, }), }); From 9352650400db95244ef52f5bc77759dfa75d5431 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Wed, 25 Sep 2024 13:33:58 -0600 Subject: [PATCH 2/3] chore(kv): standardize createKvBufferStore to allow optional redis configs and default them --- src/init/header-stores.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/init/header-stores.ts b/src/init/header-stores.ts index 6cbfcedb..52468a17 100644 --- a/src/init/header-stores.ts +++ b/src/init/header-stores.ts @@ -32,12 +32,16 @@ const createKvBufferStore = ({ pathKey, type, log, + redisUrl = config.REDIS_CACHE_URL, redisTtlSeconds = config.REDIS_CACHE_TTL_SECONDS, + useTls = config.REDIS_USE_TLS, }: { pathKey: string; type: string; log: winston.Logger; + redisUrl?: string; redisTtlSeconds?: number; + useTls?: boolean; }): KVBufferStore => { log.info(`Using ${type} for KVBufferStore for ${pathKey}`); switch (type) { @@ -48,9 +52,9 @@ const createKvBufferStore = ({ } case 'redis': { return new RedisKvStore({ - redisUrl: config.REDIS_CACHE_URL, + redisUrl, ttlSeconds: redisTtlSeconds, - useTls: config.REDIS_USE_TLS, + useTls, log, }); } From e9022917a635368d28e7601f8415e2f2cab32ad5 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Wed, 25 Sep 2024 13:53:15 -0600 Subject: [PATCH 3/3] fix(redis): use createClient tls config --- src/store/redis-kv-store.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/store/redis-kv-store.ts b/src/store/redis-kv-store.ts index 9b48c07c..2a13a338 100644 --- a/src/store/redis-kv-store.ts +++ b/src/store/redis-kv-store.ts @@ -40,7 +40,9 @@ export class RedisKvStore implements KVBufferStore { this.ttlSeconds = ttlSeconds; this.client = createClient({ url: redisUrl, - ...(useTls ? { tls: {} } : {}), // use base tls options if useTls is true + socket: { + tls: useTls, + }, }); this.client.on('error', (error: any) => { this.log.error(`Redis error`, {