caddy-docker-proxy icon indicating copy to clipboard operation
caddy-docker-proxy copied to clipboard

Escaping domain name in attribute

Open leonghui opened this issue 3 years ago • 5 comments

Hi there, I am trying to use the caddy-dynamicdns app but I am unable to define the values for domains properly. I tried the solution in #81 but it did not work in this case.

Example minimal Caddy config:

{
	"apps": {
		"dynamic_dns": {
			"domains": {
				"example.com": ["@"]
			},
			"dns_provider": {
				"name": "cloudflare",
				"api_token": "topsecret"
			}
		}
	}
}

docker-compose:

services:
  caddy:
    labels:
      caddy.dynamic_dns.provider: "duckdns <secret>"
      caddy.dynamic_dns.domains._0: "duckdns.org subdomain"
    # simple xcaddy builder with additional plugins
    image: ghcr.io/leonghui/caddy-docker-proxy-duckdns:latest
    environment:
      - CADDY_INGRESS_NETWORKS=caddy
    ports:
      - 80:80
      - 443:443
    networks:
      - caddy
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./caddy/:/data/caddy/
    restart: unless-stopped

expected output:

      "domains": {
        "duckdns.org": [
          "subdomain"
        ]

actual output:

      "domains": {
        "_0": [
          "duckdns.org",
          "subdomain"
        ]

leonghui avatar Nov 17 '21 16:11 leonghui

You're not supposed to put a dot between the field and the _0. See https://github.com/lucaslorentz/caddy-docker-proxy#ordering-and-isolation

francislavoie avatar Nov 17 '21 16:11 francislavoie

Thanks for the swift reply but unfortunately docker-proxy returned an error:

    labels:
      caddy.dynamic_dns.provider: "duckdns <secret>"
      caddy.dynamic_dns.domains_0: "duckdns.org subdomain"
"[ERROR]  Removing invalid block: parsing caddyfile tokens for 'dynamic_dns': Caddyfile:4 - Error during parsing: Wrong argument count or unexpected line ending after 'duckdns.org'
{
	dynamic_dns {
		domains duckdns.org subdomain
		provider duckdns <secret>
	}
}

"

Perhaps the domain name needs to be defined as a key/sub-directive instead of a value?

leonghui avatar Nov 17 '21 17:11 leonghui

Perhaps the domain name needs to be defined as a key/sub-directive instead of a value?

I think so, yes. So possibly like this:

    labels:
      caddy.dynamic_dns.provider: "duckdns <secret>"
      caddy.dynamic_dns.domains.duckdns\.org: "subdomain"

CDP's label parser might have issues dealing with options that have dots in them. Not sure what the workaround for that would be, if the above doesn't work.

You could provide the config you need as a Caddyfile to be merged in, see https://github.com/lucaslorentz/caddy-docker-proxy#caddy-cli or the CADDY_DOCKER_CADDYFILE_PATH env var.

francislavoie avatar Nov 17 '21 17:11 francislavoie

You are right, the parser is not handling the period correctly. In the meantime, I will try the suggested workarounds. Thanks again!

      "domains": {
        "duckdns": [
          "@"
        ],
        "org": [
          "subdomain"
        ],
        "{": [
          "@"
        ],
        "}": [
          "@"
        ]
      }

leonghui avatar Nov 17 '21 17:11 leonghui

@leonghui

I was able to fix this temporarily by storing the domain names in environment variables: https://caddyserver.com/docs/caddyfile-tutorial#environment-variables

Here's an example:

    command:
      - sh
      - -c
      - "echo '{\n}' > ./Caddyfile && caddy fmt ./Caddyfile && caddy docker-proxy -caddyfile-path ./Caddyfile -proxy-service-tasks false"
    environment:
      - DYNAMIC_DNS_DOMAIN=${DOMAIN?Variable not set}.
    networks:
      - caddy-minio
      - redis
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - caddy-data:/data
    restart: unless-stopped
    deploy:
      mode: replicated
      replicas: 1
      labels:
        - caddy.email=${EMAIL?Variable not set}
        - caddy.dynamic_dns.provider=route53
        - caddy.dynamic_dns.check_interval=1m 
        - "caddy.dynamic_dns.domains.0_{$$DYNAMIC_DNS_DOMAIN}=whattheheck"
        - caddy.dynamic_dns.0_ip_source=upnp
        - "caddy.dynamic_dns.1_ip_source=simple_http https://icanhazip.com"
        - "caddy.dynamic_dns.2_ip_source=simple_http https://api64.ipify.org"

regbo avatar Jan 27 '22 17:01 regbo