Skip to content

Commit fba7e53

Browse files
committed
fix redis connections to ipv6 enabled servers (joeferner#512)
1 parent 6822cd6 commit fba7e53

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* update jsonwebtoken from 8.5.1 to 9.0.0 (fix CVE-2022-23529, CVE-2022-23541, CVE-2022-23539, CVE-2022-23540)
66
* update json5 from 2.2.1 to 2.2.3 (fix CVE-2022-46175)
77
#### Enhancements
8+
* allow using IPv6 addresses for Redis connection definitions. (except REDIS_HOSTS env var, here no IPv6 allowed, use host names instead)
89
* update dependencies yargs@17.6.2
910
* update ioredis from 4.28.5 to 5.3.0
1011

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ If remote redis server needs TLS write all connections into a config file instea
203203
of using `REDIS_HOSTS` (see [docs/connections.md](docs/connections.md) at the end
204204
within the more complex examples).
205205

206+
This environment variable `REDIS_HOSTS` does not support IPv6 addresses. It supports IPv4 or hostnames only due to ':'
207+
used as separator within IPv6 addresses and this fields here.
208+
206209
### With docker-compose
207210

208211
```yml
@@ -275,6 +278,8 @@ known issues with Kubernetes:
275278

276279
* using REDIS_HOSTS works only with a password-less redis db. You must specify REDIS_HOST on a password
277280
protected redis db
281+
* using REDIS_HOSTS does not work with IPv6 addresses. For connections to IPv6 addresses either use `REDIS_HOST` and `REDIS_PORT`
282+
env var or a custom `config/local.json` configuration file mounted into the redis container.
278283

279284

280285
## Helm chart

docs/connections.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Parameter "host", "port" and all "sentinel*" should not be set.
4343
"host" and "port" are needed.
4444
Do not set "path" or one of the "sentinel*" parameter as they have precedence
4545
over "host" and "port"!
46+
"host" can be either an IPv4 address, IPv6 address or a hostname.
4647

4748
```json
4849
{
@@ -81,6 +82,9 @@ parsed as list of sentinels to connect:
8182
3. array of strings
8283
4. array of objects
8384

85+
Attention - connecting to a Redis server via IPv6 the form with a list of objects must be used (last example). All other variants do not work due to ":"
86+
being part of the IPv6 address too.
87+
8488
```json
8589
{
8690
"connections": [
@@ -115,7 +119,8 @@ parsed as list of sentinels to connect:
115119
"label": "redis-sentinel-4",
116120
"sentinels": [
117121
{ "host": "192.0.2.2", "port": 26379 },
118-
{ "host": "192.0.2.3", "port": 26379 }
122+
{ "host": "192.0.2.3", "port": 26379 },
123+
{ "host": "fd00:2::3", "port": 26379 }
119124
],
120125
"sentinelName": "mymaster",
121126
"password": "<optional-redis-server-pw>",
@@ -143,19 +148,19 @@ configure them directly inside your own custom json config file.
143148

144149
*The environment variables work for the docker image only, not for the stand-alone app!*
145150

146-
| Name | Type | Default | Cli | Environment-Var (Docker only) | Description |
147-
|---|---|---|---|---|---|
148-
| path | string | '' | --redis-socket | REDIS_SOCKET | path to the redis server socket, e.g. '/var/run/redis/redis.sock' |
149-
| host | string | localhost | --redis-host | REDIS_HOST | hostname or ip address of redis server (standalone mode)|
150-
| port | number | 6379 | --redis-port | REDIS_PORT | port number where redis server listens (standalone mode) |
151-
| username | string | '' | --redis-username | REDIS_USERNAME | optional username of the redis server itself (socket, standalone, sentinel or cluster mode - supported since Redis 6.0) |
152-
| password | string | '' | --redis-password | REDIS_PASSWORD | optional password of the redis server itself (socket, standalone, sentinel or cluster mode) |
153-
| sentinels | string or list | '' | --sentinels | SENTINELS | string: comma separated list of sentinels with "host:port" (sentinel mode) or list of "host:port" strings |
154-
| sentinelName | string | 'mymaster' | --sentinel-name | SENTINEL_NAME | name of redis database group to connect to via sentinel. The default name of 'mymaster' can be change via global redis configuration value 'redis.defaultSentinelGroup' (sentinel mode) |
155-
| sentinelUsername | string | | --sentinel-username | SENTINEL_USERNAME | optional username to connect to sentinels itself. This is not the username of the redis server (sentinel mode - supported since Redis 6.0) |
156-
| sentinelPassword | string | | --sentinel-password | SENTINEL_PASSWORD | password to connect to sentinels itself. This is not the password of the redis server (sentinel mode) |
157-
| db | number | 0 | --redis-db | REDIS_DB | Number of database, starting with 0, max allowed db number is configured server-side (default 15) |
158-
| connectionName | string | '' | | | use special connection name at this redis client to identify it with redis "CLIENT LIST" command. If not set default connection name from config param `redis.connectionName` is used |
151+
| Name | Type | Default | Cli | Environment-Var (Docker only) | Description |
152+
|---|---|---|---|---|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
153+
| path | string | '' | --redis-socket | REDIS_SOCKET | path to the redis server socket, e.g. '/var/run/redis/redis.sock' |
154+
| host | string | localhost | --redis-host | REDIS_HOST | hostname or ipv4/ipv6 address of redis server (standalone mode) |
155+
| port | number | 6379 | --redis-port | REDIS_PORT | port number where redis server listens (standalone mode) |
156+
| username | string | '' | --redis-username | REDIS_USERNAME | optional username of the redis server itself (socket, standalone, sentinel or cluster mode - supported since Redis 6.0) |
157+
| password | string | '' | --redis-password | REDIS_PASSWORD | optional password of the redis server itself (socket, standalone, sentinel or cluster mode) |
158+
| sentinels | string or list | '' | --sentinels | SENTINELS | string: comma separated list of sentinels with "host:port" (sentinel mode) or list of "host:port" strings |
159+
| sentinelName | string | 'mymaster' | --sentinel-name | SENTINEL_NAME | name of redis database group to connect to via sentinel. The default name of 'mymaster' can be change via global redis configuration value 'redis.defaultSentinelGroup' (sentinel mode) |
160+
| sentinelUsername | string | | --sentinel-username | SENTINEL_USERNAME | optional username to connect to sentinels itself. This is not the username of the redis server (sentinel mode - supported since Redis 6.0) |
161+
| sentinelPassword | string | | --sentinel-password | SENTINEL_PASSWORD | password to connect to sentinels itself. This is not the password of the redis server (sentinel mode) |
162+
| db | number | 0 | --redis-db | REDIS_DB | Number of database, starting with 0, max allowed db number is configured server-side (default 15) |
163+
| connectionName | string | '' | | | use special connection name at this redis client to identify it with redis "CLIENT LIST" command. If not set default connection name from config param `redis.connectionName` is used |
159164
| tls | boolean or object | false | --redis-tls | REDIS_TLS | set to true to enable TLS secured connections to the redis server, for more specific configurations (allowed algorithms, server certificate checks and so on) this parameter can be an object directly use at Node tls sockets (https://github.com/luin/ioredis#tls-options) |
160165
| label | string | '' | --redis-label | | display label to us to identify this connection within the Web-UI |
161166
| optional | boolean | false | --redis-optional | REDIS_OPTIONAL | set to true to not auto-reconnect on connection lost. Reconnect will be done if data are fetch from UI on user request |

lib/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ function createRedisClient(clientConfig, callback) {
319319
port: clientConfig.port,
320320
host: clientConfig.host,
321321
path: clientConfig.path,
322-
family: 4
322+
family: 0
323323
});
324324
if (clientConfig.path) {
325325
// unix-socket:

0 commit comments

Comments
 (0)