ID Selector is not working after upgrade to 2.4.0

1. Caddy version (caddy version):

2.4.0

2. How I run Caddy:

a. System environment:

Reproduced on both Windows 10 and Amazon Linux 2.

b. Command:

For windows

caddy_win.exe run --resume

For Linux

sudo systemctl start caddy

c. Service/unit/compose file:


d. My complete Caddyfile or JSON config:

Just going to show the windows configuration from here on out.

{
    "admin": {
        "listen": ":2020"
    },
    "apps": {
        "http": {
            "servers": {
                "server443": {
                    "@id": "routes - global",
                    "listen": [
                        ":443"
                    ],
                    "routes": [
                        {
                            "handle": [
                                {
                                    "@id": "routes - dev.uafricastore.local",
                                    "handler": "subroute",
                                    "routes": []
                                },
                                {
                                    "handler": "reverse_proxy",
                                    "headers": {
                                        "request": {
                                            "set": {
                                                "From": [
                                                    "localhost"
                                                ],
                                                "Host": [
                                                    "{http.request.host}"
                                                ],
                                                "X-Forwarded-Proto": [
                                                    "https"
                                                ]
                                            }
                                        }
                                    },
                                    "upstreams": [
                                        {
                                            "dial": "localhost:10047"
                                        }
                                    ]
                                }
                            ],
                            "match": [
                                {
                                    "host": [
                                        "*.dev.uafricastore.local"
                                    ]
                                }
                            ]
                        },
                        {
                            "@id": "dev.uafricastore.local",
                            "handle": [
                                {
                                    "handler": "reverse_proxy",
                                    "headers": {
                                        "request": {
                                            "set": {
                                                "From": [
                                                    "localhost"
                                                ],
                                                "Host": [
                                                    "{http.request.host}"
                                                ],
                                                "X-Forwarded-Proto": [
                                                    "https"
                                                ]
                                            }
                                        }
                                    },
                                    "upstreams": [
                                        {
                                            "dial": "localhost:10047"
                                        }
                                    ]
                                }
                            ],
                            "match": [
                                {
                                    "host": [
                                        "dev.uafricastore.local"
                                    ]
                                }
                            ]
                        },
                        {
                            "handle": [
                                {
                                    "@id": "routes - uafricastore.local",
                                    "handler": "subroute",
                                    "routes": [
                                        {
                                            "@id": "42 - custom-redirect",
                                            "handle": [
                                                {
                                                    "handler": "static_response",
                                                    "headers": {
                                                        "Location": [
                                                            "https://testcustagain1.local"
                                                        ]
                                                    },
                                                    "status_code": 301
                                                }
                                            ],
                                            "match": [
                                                {
                                                    "host": [
                                                        "testcustagain1.uafricastore.local"
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "@id": "53 - custom-redirect",
                                            "handle": [
                                                {
                                                    "handler": "static_response",
                                                    "headers": {
                                                        "Location": [
                                                            "https://testchange2.local"
                                                        ]
                                                    },
                                                    "status_code": 301
                                                }
                                            ],
                                            "match": [
                                                {
                                                    "host": [
                                                        "testchange2.uafricastore.local"
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "handler": "reverse_proxy",
                                    "headers": {
                                        "request": {
                                            "set": {
                                                "From": [
                                                    "localhost"
                                                ],
                                                "Host": [
                                                    "{http.request.host}"
                                                ],
                                                "X-Forwarded-Proto": [
                                                    "https"
                                                ]
                                            }
                                        }
                                    },
                                    "upstreams": [
                                        {
                                            "dial": "localhost:10041"
                                        }
                                    ]
                                }
                            ],
                            "match": [
                                {
                                    "host": [
                                        "*.uafricastore.local"
                                    ]
                                }
                            ]
                        },
                        {
                            "@id": "uafricastore.local",
                            "handle": [
                                {
                                    "handler": "reverse_proxy",
                                    "headers": {
                                        "request": {
                                            "set": {
                                                "From": [
                                                    "localhost"
                                                ],
                                                "Host": [
                                                    "{http.request.host}"
                                                ],
                                                "X-Forwarded-Proto": [
                                                    "https"
                                                ]
                                            }
                                        }
                                    },
                                    "upstreams": [
                                        {
                                            "dial": "localhost:10041"
                                        }
                                    ]
                                }
                            ],
                            "match": [
                                {
                                    "host": [
                                        "uafricastore.local"
                                    ]
                                }
                            ]
                        },
                        {
                            "@id": "19 - custom",
                            "handle": [
                                {
                                    "handler": "reverse_proxy",
                                    "headers": {
                                        "request": {
                                            "set": {
                                                "Host": [
                                                    "{http.request.host}"
                                                ],
                                                "X-Forwarded-Proto": [
                                                    "https"
                                                ]
                                            }
                                        }
                                    },
                                    "upstreams": [
                                        {
                                            "dial": "127.0.0.1:10041"
                                        }
                                    ]
                                }
                            ],
                            "match": [
                                {
                                    "host": [
                                        "custom4store.local",
                                        "www.custom4store.local"
                                    ]
                                }
                            ]
                        },
                        {
                            "@id": "27 - redirect",
                            "handle": [
                                {
                                    "handler": "static_response",
                                    "headers": {
                                        "Location": [
                                            "https://test9.uafricastore.local"
                                        ]
                                    },
                                    "status_code": 301
                                }
                            ],
                            "match": [
                                {
                                    "host": [
                                        "www.test9.local"
                                    ]
                                }
                            ]
                        },
                        {
                            "@id": "42 - custom",
                            "handle": [
                                {
                                    "handler": "reverse_proxy",
                                    "headers": {
                                        "request": {
                                            "set": {
                                                "Host": [
                                                    "{http.request.host}"
                                                ],
                                                "X-Forwarded-Proto": [
                                                    "https"
                                                ]
                                            }
                                        }
                                    },
                                    "upstreams": [
                                        {
                                            "dial": "127.0.0.1:10041"
                                        }
                                    ]
                                }
                            ],
                            "match": [
                                {
                                    "host": [
                                        "testcustagain1.local"
                                    ]
                                }
                            ]
                        },
                        {
                            "@id": "53 - custom",
                            "handle": [
                                {
                                    "handler": "reverse_proxy",
                                    "headers": {
                                        "request": {
                                            "set": {
                                                "Host": [
                                                    "{http.request.host}"
                                                ],
                                                "X-Forwarded-Proto": [
                                                    "https"
                                                ]
                                            }
                                        }
                                    },
                                    "upstreams": [
                                        {
                                            "dial": "127.0.0.1:10041"
                                        }
                                    ]
                                }
                            ],
                            "match": [
                                {
                                    "host": [
                                        "testchange2.local"
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }
        }
    },
    "logging": {
        "logs": {
            "": {
                "level": "debug"
            }
        }
    }
}

3. The problem I’m having:

I can not use the @id selector to select the correct “section”. It returns a 200 status code but with no content.

This used to work on the previous version: v2.3.0 but stopped after upgrading v.2.4.0

I have tried on both Windows 10 and Ubuntu (running on AWS, AMI: ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20201026)

4. Error messages and/or full log output:

curl --location --request GET 'http://localhost:2020/id/routes - global/routes/' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json'
GET /id/routes%20-%20global/routes/ HTTP/1.1
Content-Type: application/json
Accept: application/json
User-Agent: PostmanRuntime/7.28.0
Cache-Control: no-cache
Postman-Token: d1d9532c-cf3b-45d9-8632-fd2ff13238d2
Host: localhost:2020
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
 
HTTP/1.1 200 OK
Date: Wed, 19 May 2021 12:55:06 GMT
Content-Length: 0

5. What I already tried:

  • Escaping the spaces
  • Removing the - between the words
  • Replacing - with an underscore
  • Adding and removing the Accept and Content-Type headers
  • Different operating systems
  • Selecting using “direct ancestors” aka http://127.0.0.1:2020/config/apps/http/servers/server443/routes works

6. Links to relevant resources:

What if you remove the spaces? Seems strange to me to be using non-URL-safe characters here (i.e. spaces; dashes are fine)

I have tried just a basic word and the one in the docs my_proxy nothing works. It definitely “finds” the ID because if I use an ID that does not exist, it gives an error complaining it can not be found. So I guess it finds the selector but it returns 0 data for it, Content-Length: 0

Okay.

It’s most likely a regression introduced in this PR (cc @matt):

1 Like

That would be weird, those changes have nothing to do with the actual admin handlers, or config IDs… looking into it.

Looks like I touched an adjacent function and made a mistake when rebasing. Fixed on master now.

That was super fast :slight_smile: thanks for the help…

I have only been downloading the Caddy executable from the website because I need to include the Route53 package.

How can I test this change you made, I have seen GitHub - caddyserver/xcaddy: Build Caddy with plugins being mentioned a few places. Do I just point it to the master branch/to that new commit of yours and then instruct it that I also want the Route53 package with it?

Yep.

xcaddy build master --with https://github.com/caddy-dns/route53

Awesome thanks, I will try it tomorrow (+12hours) and let know if it worked.

@matt Thanks that worked… Guess I was the first one that upgraded and used that on the latest version then, would have thought it be more popular…

What do others do then, just rewrite the whole config as opposed to what I am doing now, which is changing specific routes? OR I guess if you simple logic then you can use the path based, just gets tricky when you have an array and when the ordering of routes matter.

Anyway, thanks a million!

A large majority of users just use the Caddyfile and don’t make use of the API. And I would postulate that those that do typically want more stability over updating early.

FYI v2.4.1 is out as of last night, which includes this fix.

I just tried using caddy upgrade, but the version is still 2.4.0??

The build server’s build cache still hasn’t been kicked I think. See the explanation here:

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.