Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caddyfile: subject does not qualify for certificate with http://* #3977

Closed
0az opened this issue Jan 18, 2021 · 8 comments
Closed

Caddyfile: subject does not qualify for certificate with http://* #3977

0az opened this issue Jan 18, 2021 · 8 comments
Assignees
Labels
bug 🐞 Something isn't working
Milestone

Comments

@0az
Copy link
Contributor

0az commented Jan 18, 2021

Caddy v2.3.0 errors on the previously-valid http-only wildcard site http://*, which is a regression from v2.2.0 behavior.

Example Caddyfile

http://* {
	respond "Hello, world!"
}

(I might get around to figuring out how git bisect run works in the morning: should be fun.)

@francislavoie
Copy link
Member

Wildcard characters only match a single domain segment. Just remove the * to match all domains.

@0az
Copy link
Contributor Author

0az commented Jan 18, 2021

Wildcard characters only match a single domain segment. Just remove the * to match all domains.

I'm 50% sure that the wildcard matching single segments was intentional, since this was deployed with a collection of HTTPS sites that I wanted auto-HTTPS for.

# 1.Caddyfile
{
	# Just for local replication
	local_certs
}

http://* {
	respond "Hello, world!"
}

localhost.internal {
	respond "Hello, https!"
}

If you drop the wildcard, in v2.2.0, it catches http://localhost.internal, and does not force the wildcard. In v2.3.0, it errors with

run: loading initial config: loading new config: loading tls app module: tls: invalid configuration: automation policy 1 is the second policy that acts as default/catch-all, but will never be used

Poking at the adapted JSON, it looks like there's two repeated blocks:

caddy adapt output of 1.Caddyfile, with wildcard removed.

{
  "apps": {
    "http": {
      "servers": {
        "srv0": {
          "listen": [
            ":443"
          ],
          "routes": [
            {
              "match": [
                {
                  "host": [
                    "localhost.internal"
                  ]
                }
              ],
              "handle": [
                {
                  "handler": "subroute",
                  "routes": [
                    {
                      "handle": [
                        {
                          "body": "Hello, https!",
                          "handler": "static_response"
                        }
                      ]
                    }
                  ]
                }
              ],
              "terminal": true
            }
          ]
        },
        "srv1": {
          "listen": [
            ":80"
          ],
          "routes": [
            {
              "handle": [
                {
                  "body": "Hello, world!",
                  "handler": "static_response"
                }
              ]
            }
          ]
        }
      }
    },
    "tls": {
      "automation": {
        "policies": [
          {
            "issuers": [
              {
                "module": "internal"
              }
            ]
          },
          {
            "issuers": [
              {
                "module": "internal"
              }
            ]
          }
        ]
      }
    }
  }
}

This seems like a different bug, though.

@francislavoie
Copy link
Member

francislavoie commented Jan 18, 2021

I'm 50% sure that the wildcard matching single segments was intentional, since this was deployed with a collection of HTTPS sites that I wanted auto-HTTPS for.

To clarify, cause I'm not certain we're on the same page on this, "single-segment" means a domain like "localhost", but not "localhost.internal", because that's two segments (separated by .). This is also known as "labels" (Caddy uses that terminology in the docs for the placeholders as well, I probably should have used that word instead)

But anyways, @mholt will need to take a look 😄

@0az
Copy link
Contributor Author

0az commented Jan 18, 2021

To clarify, cause I'm not certain we're on the same page on this, "single-segment" means a domain like "localhost", but not "localhost.internal", because that's two segments (separated by .). This is also known as "labels" (Caddy uses that terminology in the docs for the placeholders as well, I probably should have used that word instead)

Yeah, I'm aware of that, and I abuse that to ensure that only single-segment sites (localhost, and a couple others) have that wildcard block applied, and not anything public facing. localhost.internal is a poorly chosen stand-in for a """production""" domain.

@mholt mholt added the bug 🐞 Something isn't working label Jan 19, 2021
@mholt mholt self-assigned this Jan 19, 2021
@mholt mholt added this to the v2.3.1 milestone Jan 19, 2021
@mholt
Copy link
Member

mholt commented Jan 19, 2021

@0az Thanks for the report, I'm looking into this.

Meanwhile:

Does this commit fix the repeated automation policies bug for you? It's recent, you'll have to get the latest build artifacts from our CI or use xcaddy on the latest commit/master: 7846bc1

@mholt mholt closed this as completed in d68cff8 Jan 19, 2021
@mholt
Copy link
Member

mholt commented Jan 19, 2021

@0az I think the commit I just pushed, d68cff8, is a good way to fix the bug. We shouldn't be trying to create TLS automation policies for servers that are HTTP-only. (Right? I keep feeling like there's some edge case in here I'm not considering. Oh well... guess we'll see.)

Please try the latest commits and let me know if there are any further problems. Thanks!

mholt added a commit to caddyserver/certmagic that referenced this issue Jan 19, 2021
I suppose * is a valid subject -- technically -- but it probably won't
be accepted by browsers. They usually only accept wildcards
for subdomains.

Related, but only tangentially:
caddyserver/caddy#3977
@0az
Copy link
Contributor Author

0az commented Jan 21, 2021

Tested 3366384. LGTM.

@mholt
Copy link
Member

mholt commented Jan 21, 2021

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants