gamalan / caddy-tlsredis

Redis Storage using for Caddy TLS Data
Apache License 2.0
95 stars 31 forks source link

Attempts to connect to 127.0.0.1:6379 despite being configured otherwise #14

Closed lylo closed 4 years ago

lylo commented 4 years ago

I've built Caddy with the caddy-tlsredis module but I'm seeing connection problems. Caddy version:

v2.2.0 h1:sMUFqTbVIRlmA8NkFnNt9l7s0e+0gw+7GPIrhty905A=

I have configured Caddy as follows:

{
  storage redis {
    address       "myredisinstance.ondigitalocean.com:25061"
    password      "mypassword"
    db            1
    key_prefix    "caddytls"
    value_prefix  "caddy-storage-redis"
    timeout       5
    tls_enabled   "false"
    tls_insecure  "true"
    aes_key       "redistls-01234567890-caddytls-32"
  }
}

However I'm seeing this in the logs when starting Caddy:

Oct  4 11:30:47 caddy[1082]: {"level":"info","ts":1601811047.0859385,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":""}
Oct  4 11:30:47 caddy[1082]: {"level":"info","ts":1601811047.0913122,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["[::1]:2019","127.0.0.1:2019","localhost:2019"]}
Oct  4 11:30:47 caddy[1082]: {"level":"info","ts":1601811047.0918891,"logger":"caddy.storage.redis","msg":"TLS Storage are using Redis, on 127.0.0.1:6379"}
Oct  4 11:30:47 caddy[1082]: run: loading initial config: loading new config: loading storage module: loading module 'redis': provision caddy.storage.redis: dial tcp 127.0.0.1:6379: connect: connection refused
Oct  4 11:30:47 systemd[1]: caddy.service: Main process exited, code=exited, status=1/FAILURE
Oct  4 11:30:47 systemd[1]: caddy.service: Failed with result 'exit-code'.

It's quite likely I've made a mistake somewhere but it's unclear to me where! I am aware that 127.0.0.1:6379 is the Redis default but I don't understand why Caddy (or this module) is attempting to connect to it, given that I have specified the host and port as well as address. I have also tried setting just the address and also just the host and port. I've even tried adding CADDY_CLUSTERING_REDIS_PORT etc in the environment but I still get the same error.

Thanks in advance.

lylo commented 4 years ago

I'm not using a JSON Caddyfile. I've noticed that caddy adapt returns this:

  "storage": {
    "Client": null,
    "ClientLocker": null,
    "Logger": null,
    "address": "",
    "aes_key": "",
    "db": 0,
    "host": "",x
    "key_prefix": "",
    "module": "redis",
    "password": "",
    "port": "",
    "timeout": 0,
    "tls_enabled": false,
    "tls_insecure": false,
    "value_prefix": ""
  },

Presumably this is the root of the problem? Any advice on how to correct this would be welcome!

SkYNewZ commented 4 years ago

I have the same issue. Not working even from env or from static config

SkYNewZ commented 4 years ago
~/Sources/caddyv2/test using ☁️  default/iwc-apipy-ss-int-dtep 
➜ cat Caddyfile         
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: Caddyfile
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ {
   2   │   storage redis {
   3   │     address       "myredisinstance.ondigitalocean.com:25061"
   4   │     password      "mypassword"
   5   │     db            1
   6   │     key_prefix    "caddytls"
   7   │     value_prefix  "caddy-storage-redis"
   8   │     timeout       5
   9   │     tls_enabled   "false"
  10   │     tls_insecure  "true"
  11   │     aes_key       "redistls-01234567890-caddytls-32"
  12   │   }
  13   │ }
  14   │ 
  15   │ # lb.cloud.skynewz.local:80 {
  16   │ #   respond /health "OK" 200
  17   │ # }
  18   │ 
  19   │ localhost {
  20   │     respond "Hello, world!"
  21   │ }
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

~/Sources/caddyv2/test using ☁️  default/iwc-apipy-ss-int-dtep 
➜ ./caddy-redis run       
2020/10/15 00:30:57.033 INFO    using adjacent Caddyfile
2020/10/15 00:30:57.036 INFO    admin   admin endpoint started  {"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["127.0.0.1:2019", "localhost:2019", "[::1]:2019"]}
2020/10/15 00:30:57.036 INFO    caddy.storage.redis TLS Storage are using Redis, on :6379
run: loading initial config: loading new config: loading storage module: loading module 'redis': provision caddy.storage.redis: dial tcp :6379: connect: connection refused