pteich / caddy-tlsconsul

🔒 Consul K/V storage for Caddy Web Server / Certmagic TLS data
Apache License 2.0
96 stars 17 forks source link

Caddyfile configuration is ignored #13

Closed rgdev closed 3 years ago

rgdev commented 4 years ago

It seems that when defining the module's configuration in the Caddyfile it gets ignored. Tested on swarm using caddy 2.1-beta.1 with tlsconsul 1.2.0.

Here's my stack :

version: '3.7'

services:
  caddy_server:
    image: (latest beta 2.1 image built with tls consul 1.2.0)
    command: run --config /etc/caddy/Caddyfile --adapter caddyfile
    ports:
      - 80:80
      - 443:443
    networks:
      - consul
    configs:
      - source: caddyfile-consul-test
        target: /etc/caddy/Caddyfile

configs:
  caddyfile-consul-test:
    external: true

networks:
  consul:
    external: true

Caddyfile :

{
    email contact@domain.tld
    storage consul {
            address "consul-server:8500"
        token "consul-access-token"
        timeout 10
        prefix "caddytls"
        value_prefix "myprefix"
        aes_key "consultls-1234567890-caddytls-32"
        tls_enabled "false"
        tls_insecure "true"
    }
}
:80 {
    root * /usr/share/caddy
    file_server
}

Log :

{"level":"info","ts":1592393077.5028267,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
{"level":"info","ts":1592393077.5079827,"logger":"caddy.storage.consul","msg":"TLS storage is using Consul at "}
run: loading initial config: loading new config: loading storage module: loading module 'consul': provision caddy.storage.consul: unable to ping Consul: Get "http://127.0.0.1:8500/v1/agent/self": dial tcp 127.0.0.1:8500: connect: connection refused

It logs a blank address (TLS storage is using Consul at) and defaults to 127.0.0.1:8500 despite the Caddyfile's consul address pointing to consul-server:8500. It works fine using environment variables.

pteich commented 4 years ago

I'll have a look! Maybe I messed up something when refactoring.

orsanawwad commented 4 years ago

A temporary fix is to use CONSUL_HTTP_ADDR instead

pteich commented 4 years ago

That's true, all environment variables work like before. I'm on a fix but currently in vacation.

rgdev commented 3 years ago

Any update on this issue ?

pteich commented 3 years ago

Sorry for the delay. I changed the implementation and also it still needs some polishing it works now with a Caddyfile like this:


{
    storage consul {
           address      "localhost:8500"
           token        "consul-access-token"
           timeout      10
           prefix       "caddytls"
           value_prefix "myprefix"
           aes_key      "consultls-1234567890-caddytls-32"
           tls_enabled  "false"
           tls_insecure "true"
    }
}