lucaslorentz / caddy-docker-proxy

Caddy as a reverse proxy for Docker
MIT License
2.95k stars 171 forks source link

layer4 configuration block #666

Open jameshclrk opened 1 week ago

jameshclrk commented 1 week ago

Following #342, the layer4 plugin can be configured using Caddyfile.

I'm trying to get one of the examples working, but I'm not sure how to set the keys in the correct way.

Example Caddyfile:

{
    layer4 {
        127.0.0.1:5000 {
            route {
                tls
                echo
            }
        }
    }
}

I have tried this compose file (ignore using whoami, just an example):

services:
  whoami:
    image: traefik/whoami
    networks:
      - caddy
    labels:
      caddy.layer4."127.0.0.0.1:5000".route.tls:
      caddy.layer4."127.0.0.0.1:5000".route.echo:

networks:
  caddy:
    external: true

But I get this Caddyfile which (correctly) causes an error:

{
    layer4 {
        `\"127` {
            0 {
                0 {
                    0 {
                        `1:5000\"` {
                            route {
                                echo
                                tls
                            }
                        }
                    }
                }
            }
        }
    }
}

I've tried escaping the .s with \ and that also doesn't work. This simple example could be done in a base Caddyfile, but I would like to be able to use layer4 for services defined via labels.

coandco commented 3 days ago

I'm also running into this. Watching to see if this issue gets answered.

coandco commented 3 days ago

Planning on try the solution here to see if it's a viable workaround.

coandco commented 3 days ago

Success! I'm attempting to do DNS-over-TLS with pihole, and this is what my labels look like after setting DOT_INGRESS_ADDR to 0.0.0.0:853 on my main caddy container:

      "caddy_1.layer4.0_{$DOT_INGRESS_ADDR}": ""
      "caddy_1.layer4.0_{$DOT_INGRESS_ADDR}.@pihole_host": "tls sni pihole.my.domain"
      "caddy_1.layer4.0_{$DOT_INGRESS_ADDR}.route": "@pihole_host"
      "caddy_1.layer4.0_{$DOT_INGRESS_ADDR}.route.0_tls": ""
      "caddy_1.layer4.0_{$DOT_INGRESS_ADDR}.route.1_proxy": "{{ upstreams 53 }}"

With this approach, I can successfully run doggo google.com A @tls://pihole.my.domain and get an answer.