Skip to content

Commit 8aec41a

Browse files
feat: redis tls support (#5884)
Co-authored-by: Laurin Quast <laurinquast@googlemail.com>
1 parent 277769d commit 8aec41a

21 files changed

Lines changed: 50 additions & 2 deletions

File tree

.changeset/early-otters-help.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'hive': minor
3+
---
4+
5+
Add `REDIS_TLS_ENABLED` environment variable for enabling and disabling Redis TLS for `emails`, `schema`, `tokens`, `webhooks` and `server` services.

docs/DEVELOPMENT.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ ENVIRONMENT=local
2222

2323
- Run `pnpm i` at the root to install all the dependencies and run the hooks
2424
- Run `pnpm local:setup` to run Docker compose dependencies, create databases and migrate database
25+
26+
Solving permission problems on this step:
27+
28+
```bash
29+
export UID=$(id -u)
30+
export GID=$(id -g)
31+
```
32+
33+
Add "user" field to docker-compose.dev.yml
34+
35+
```
36+
clickhouse:
37+
user: '${UID}:${GID}'
38+
db:
39+
user: '${UID}:${GID}'
40+
```
41+
2542
- Run `pnpm generate` to generate the typings from the graphql files (use `pnpm graphql:generate` if
2643
you only need to run GraphQL Codegen)
2744
- Run `pnpm build` to build all services
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const version = '0.8.0';
1+
export const version = '0.8.2';

packages/services/api/src/modules/shared/providers/redis.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { Logger } from './logger';
55

66
export type { RedisInstance as Redis };
77

8-
export type RedisConfig = Required<Pick<RedisOptions, 'host' | 'port' | 'password'>>;
8+
export type RedisConfig = Required<Pick<RedisOptions, 'host' | 'port' | 'password'>> & {
9+
tlsEnabled: boolean;
10+
};
911

1012
export const REDIS_INSTANCE = new InjectionToken<RedisInstance>('REDIS_INSTANCE');
1113

@@ -24,6 +26,7 @@ export function createRedisClient(label: string, config: RedisConfig, logger: Lo
2426
db: 0,
2527
maxRetriesPerRequest: null,
2628
enableReadyCheck: false,
29+
tls: config.tlsEnabled ? {} : undefined,
2730
});
2831

2932
redis.on('error', err => {

packages/services/emails/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Service for sending Hive Emails.
1212
| `REDIS_HOST` | **Yes** | The host of your redis instance. | `"127.0.0.1"` |
1313
| `REDIS_PORT` | **Yes** | The port of your redis instance. | `6379` |
1414
| `REDIS_PASSWORD` | **Yes** | The password of your redis instance. | `"apollorocks"` |
15+
| `REDIS_TLS_ENABLED` | **No** | Enable TLS for redis connection (rediss://). | `"0"` |
1516
| `EMAIL_FROM` | **Yes** | The email address used for sending emails | `kamil@graphql-hive.com` |
1617
| `EMAIL_PROVIDER` | **Yes** | The email provider that should be used for sending emails. | `smtp` or `postmark` or `mock` |
1718
| `EMAIL_PROVIDER_SMTP_PROTOCOL` | No (**Yes** if `EMAIL_PROVIDER` is set to `smtp`) | The protocol used for the smtp server | `smtp` or `smtps` |

packages/services/emails/src/environment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const RedisModel = zod.object({
4040
REDIS_HOST: zod.string(),
4141
REDIS_PORT: NumberFromString,
4242
REDIS_PASSWORD: emptyString(zod.string().optional()),
43+
REDIS_TLS_ENABLED: emptyString(zod.union([zod.literal('1'), zod.literal('0')]).optional()),
4344
});
4445

4546
const PostmarkEmailModel = zod.object({
@@ -193,6 +194,7 @@ export const env = {
193194
host: redis.REDIS_HOST,
194195
port: redis.REDIS_PORT,
195196
password: redis.REDIS_PASSWORD ?? '',
197+
tlsEnabled: redis.REDIS_TLS_ENABLED === '1',
196198
},
197199
email: {
198200
provider: emailProviderConfig,

packages/services/emails/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ async function main() {
6666
host: env.redis.host,
6767
port: env.redis.port,
6868
password: env.redis.password,
69+
tlsEnabled: env.redis.tlsEnabled,
6970
},
7071
queueName: 'emails',
7172
emailProvider,

packages/services/emails/src/scheduler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function createScheduler(config: {
1818
host: string;
1919
port: number;
2020
password: string;
21+
tlsEnabled: boolean;
2122
};
2223
queueName: string;
2324
emailProvider: EmailProvider;
@@ -126,6 +127,7 @@ export function createScheduler(config: {
126127
db: 0,
127128
maxRetriesPerRequest: null,
128129
enableReadyCheck: false,
130+
tls: config.redis.tlsEnabled ? {} : undefined,
129131
});
130132

131133
redisConnection.on('error', err => {

packages/services/schema/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ of subschemas.
1111
| `REDIS_HOST` | **Yes** | The host of your redis instance. | `"127.0.0.1"` |
1212
| `REDIS_PORT` | **Yes** | The port of your redis instance. | `6379` |
1313
| `REDIS_PASSWORD` | **Yes** | The password of your redis instance. | `"apollorocks"` |
14+
| `REDIS_TLS_ENABLED` | **No** | Enable TLS for redis connection (rediss://). | `"0"` |
1415
| `ENCRYPTION_SECRET` | **Yes** | Secret for encrypting stuff. | `8ebe95cg21c1fee355e9fa32c8c33141` |
1516
| `ENVIRONMENT` | No | The environment of your Hive app. (**Note:** This will be used for Sentry reporting.) | `staging` |
1617
| `BODY_LIMIT` | No | Maximum payload size in bytes. Defaults to 11 MB. | `11000000` |

packages/services/schema/src/environment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const RedisModel = zod.object({
5959
REDIS_HOST: zod.string(),
6060
REDIS_PORT: NumberFromString(),
6161
REDIS_PASSWORD: emptyString(zod.string().optional()),
62+
REDIS_TLS_ENABLED: emptyString(zod.union([zod.literal('1'), zod.literal('0')]).optional()),
6263
});
6364

6465
const PrometheusModel = zod.object({
@@ -151,6 +152,7 @@ export const env = {
151152
host: redis.REDIS_HOST,
152153
port: redis.REDIS_PORT,
153154
password: redis.REDIS_PASSWORD ?? '',
155+
tlsEnabled: redis.REDIS_TLS_ENABLED === '1',
154156
},
155157
sentry: sentry.SENTRY === '1' ? { dsn: sentry.SENTRY_DSN } : null,
156158
log: {

0 commit comments

Comments
 (0)