lucaslorentz / caddy-docker-proxy

Caddy as a reverse proxy for Docker
MIT License
2.61k stars 163 forks source link

Fix broken block parsing when label prefix contains dots #610

Open Vigilans opened 2 months ago

Vigilans commented 2 months ago

When CADDY_DOCKER_LABEL_PREFIX contains dots, parsing of blocks will break.

e.g. With CADDY_DOCKER_LABEL_PREFIX=mydomain.gitlab.caddy, cdp will yield error:

[ERROR]  Removing invalid block: Caddyfile:2: unrecognized global option: gitlab\n{\n\tgitlab {\n\t\tcaddy http://redis.gitlab.mydomain {\n\t\t\treverse_proxy 127.0.0.1:5540\n\t\t}\n\t}\n}\n\n

Then wrongly parsed block is:

{
        gitlab {
                caddy http://redis.gitlab.mydomain {
                        reverse_proxy 127.0.0.1:5540
                }
        }
}

It is because gitlab.caddy in mydomain.gitlab.caddy also gets parsed as path.

Using dots in prefix conforms to what docker has adopted in their labels, e.g.:

            "com.docker.compose.project": "...",
            "com.docker.compose.project.config_files": "...",
            "com.docker.compose.project.working_dir": "...",

So using dot-separated string in CADDY_DOCKER_LABEL_PREFIX should be a good way to keep naming style consistent with other labels and should be supported.

This PR fixes it by canonicalizing the label prefix to "caddy", so meta characters in user provided label prefix will not affect cdp's block parsing.