caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
58.13k stars 4.03k forks source link

panic: certificate worker: runtime error invalid memory address or nil pointer dereference from certmagic #6672

Closed pimlie closed 1 hour ago

pimlie commented 5 hours ago

This is not the same error as #6609 as I built caddy manually with certmagic@0.21.4.

I tracked the panic down to a network issue, it occurs when the api of the dns provider isn't reachable. So it seems that network issues might not be nicely handled yet? To be clear, the api hostname could be resolved through DNS, but actually connecting to the api failed due to a network routing issue.

Unfortunately I don't have a stack trace anymore as docker only kept 100 lines of the log, but let me know if you really need one as I can break the network routing again if needed. The panic occured on this line though (Im also using that dev branch as my PR hasnt been merged yet) :)

mholt commented 5 hours ago

Thanks for the report, but yeah we'll need the stack trace. Otherwise it could be anything, anywhere.

pimlie commented 5 hours ago

I just added the line the error occured on in case that helps. Trying to get Caddy to recreate the certificate now but just removing the certificate folder in the caddy/certificates/acme-v02.api.letsencrypt.org-directory/ folder doesn't seem to trigger a DNS-01 re-validation :(

pimlie commented 4 hours ago

Creating a new cert for a test domain, so here ya go :)

INF ts=1730489131.3124416 msg=panic: certificate worker: runtime error: invalid memory address or nil pointer dereference
goroutine 96 [running]:
github.com/caddyserver/certmagic.(*jobManager).worker.func1()
    github.com/caddyserver/certmagic@v0.21.4/async.go:58 +0x65
panic({...})
    runtime/panic.go:770 +0x132
github.com/libdns/leaseweb.(*Provider).createRecordSet(...)
    github.com/libdns/leaseweb@v0.3.1/client.go:84 +0x35f
github.com/libdns/leaseweb.(*Provider).AppendRecords(...)
    github.com/libdns/leaseweb@v0.3.1/provider.go:56 +0x235
github.com/caddyserver/certmagic.(*DNSManager).createRecord(...)
    github.com/caddyserver/certmagic@v0.21.4/solvers.go:401 +0x815
github.com/caddyserver/certmagic.(*DNS01Solver).Present(...)
    github.com/caddyserver/certmagic@v0.21.4/solvers.go:265 +0x19e
github.com/caddyserver/certmagic.solverWrapper.Present(...)
    github.com/caddyserver/certmagic@v0.21.4/solvers.go:827 +0x22e
github.com/mholt/acmez/v2.(*Client).presentForNextChallenge(...)
    github.com/mholt/acmez/v2@v2.0.3/client.go:410 +0x7ab
github.com/mholt/acmez/v2.(*Client).solveChallenges(...)
    github.com/mholt/acmez/v2@v2.0.3/client.go:361 +0x26d
github.com/mholt/acmez/v2.(*Client).ObtainCertificate(...)
    github.com/mholt/acmez/v2@v2.0.3/client.go:136 +0x598
github.com/caddyserver/certmagic.(*ACMEIssuer).doIssue(...)
    github.com/caddyserver/certmagic@v0.21.4/acmeissuer.go:477 +0x668
github.com/caddyserver/certmagic.(*ACMEIssuer).Issue(...)
    github.com/caddyserver/certmagic@v0.21.4/acmeissuer.go:371 +0xa7
github.com/caddyserver/caddy/v2/modules/caddytls.(*ACMEIssuer).Issue(...)
    github.com/caddyserver/caddy/v2@v2.8.4/modules/caddytls/acmeissuer.go:248 +0x25
github.com/caddyserver/certmagic.(*Config).obtainCert.func2(...)
    github.com/caddyserver/certmagic@v0.21.4/config.go:626 +0xcb4
github.com/caddyserver/certmagic.doWithRetry(...)
    github.com/caddyserver/certmagic@v0.21.4/async.go:104 +0x233
github.com/caddyserver/certmagic.(*Config).obtainCert(...)
    github.com/caddyserver/certmagic@v0.21.4/config.go:700 +0x729
github.com/caddyserver/certmagic.(*Config).ObtainCertAsync(...)
    github.com/caddyserver/certmagic@v0.21.4/config.go:505
github.com/caddyserver/certmagic.(*Config).manageOne.func1()
    github.com/caddyserver/certmagic@v0.21.4/config.go:415 +0x73
github.com/caddyserver/certmagic.(*jobManager).worker(0x2ab12c0)
    github.com/caddyserver/certmagic@v0.21.4/async.go:73 +0x11b
created by github.com/caddyserver/certmagic.(*jobManager).Submit in goroutine 1
    github.com/caddyserver/certmagic@v0.21.4/async.go:50 +0x279
francislavoie commented 4 hours ago

How did you build Caddy exactly? Show caddy build-info

Make sure you're using master to ensure you're using the latest version of Caddy.

mholt commented 4 hours ago

That actually looks like a bug in the leaseweb plugin.

pimlie commented 3 hours ago
Dockerfile Checkout in the same folder as the Dockerfile ```bash $ git clone https://github.com/pimlie/libdns-leaseweb $ git checkout fix-create-recordset ``` ```Dockerfile FROM caddy:builder-alpine AS builder RUN mkdir -p /tmp/libdns-leaseweb COPY ./libdns-leaseweb /tmp/libdns-leaseweb/ RUN xcaddy build \ --with github.com/caddyserver/certmagic@v0.21.4 \ --with github.com/caddy-dns/leaseweb \ --with github.com/libdns/leaseweb=/tmp/libdns-leaseweb ``` FROM caddy:alpine COPY --from=builder /usr/bin/caddy /usr/bin/caddy
caddy build-info Note that for libdns/leaseweb it says devel, that was pointing to a local version of my PR branch. ``` go go1.22.8 path caddy mod caddy (devel) dep filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= dep github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= dep github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= dep github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g= dep github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= dep github.com/alecthomas/chroma/v2 v2.13.0 h1:VP72+99Fb2zEcYM0MeaWJmV+xQvz5v5cxRHd+ooU1lI= dep github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI= dep github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b h1:uUXgbcPDK3KpW29o4iy7GtuappbWT0l5NaMo9H9pJDw= dep github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= dep github.com/caddy-dns/leaseweb v0.2.0 h1:VAKB+N3TXKoTgcJ23k+47aZKzVzPHo95jwhjqVRBkK8= dep github.com/caddyserver/caddy/v2 v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk= dep github.com/caddyserver/certmagic v0.21.4 h1:e7VobB8rffHv8ZZpSiZtEwnLDHUwLVYLWzWSa1FfKI0= dep github.com/caddyserver/zerossl v0.1.3 h1:onS+pxp3M8HnHpN5MMbOMyNjmTheJyWRaZYwn+YTAyA= dep github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= dep github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= dep github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI= dep github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM= dep github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= dep github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= dep github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= dep github.com/fxamacker/cbor/v2 v2.6.0 h1:sU6J2usfADwWlYDAFhZBQ6TnLFBHxgesMrQfQgk1tWA= dep github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s= dep github.com/go-jose/go-jose/v3 v3.0.3 h1:fFKWeig/irsp7XD2zBxvnmA/XaRWp5V3CBsZXJF7G7k= dep github.com/go-kit/kit v0.13.0 h1:OoneCcHKHQ03LfBpoQCUfCluwd2Vt3ohz+kvbJneZAU= dep github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= dep github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= dep github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= dep github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= dep github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= dep github.com/google/cel-go v0.20.1 h1:nDx9r8S3L4pE61eDdt8igGj8rf5kjYR3ILxWIpWNi84= dep github.com/google/certificate-transparency-go v1.1.8-0.20240110162603-74a5dd331745 h1:heyoXNxkRT155x4jTAiSv5BVSVkueifPUm +Q8LUXMRo= dep github.com/google/go-tpm v0.9.0 h1:sQF6YqWMi+SCXpsmS3fd21oPy/vSddwZry4JnmltHVk= dep github.com/google/go-tspi v0.3.0 h1:ADtq8RKfP+jrTyIWIZDIYcKOMecRqNJFOew2IT0Inus= dep github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= dep github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk= dep github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= dep github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= dep github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= dep github.com/jackc/pgconn v1.14.3 h1:bVoTr12EGANZz66nZPkMInAV/KHD2TxH9npjXXgiB3w= dep github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= dep github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= dep github.com/jackc/pgproto3/v2 v2.3.3 h1:1HLSx5H+tXR9pW3in3zaztoEwQYRC9SQaYUHjTSUOag= dep github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= dep github.com/jackc/pgtype v1.14.0 h1:y+xUdabmyMkJLyApYuPj38mW+aAIqCe5uuBB51rH3Vw= dep github.com/jackc/pgx/v4 v4.18.3 h1:dE2/TrEsGX3RBprb3qryqSV9Y60iZN1C6i8IrmW9/BA= dep github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= dep github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM= dep github.com/libdns/leaseweb v0.3.1 => /tmp/libdns-leaseweb (devel) dep github.com/libdns/libdns v0.2.2 h1:O6ws7bAfRPaBsgAYt8MDe2HcNBGC29hkZ9MX2eUSX3s= dep github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= dep github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= dep github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= dep github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI= dep github.com/mholt/acmez/v2 v2.0.3 h1:CgDBlEwg3QBp6s45tPQmFIBrkRIkBT4rW4orMM6p4sw= dep github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ= dep github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= dep github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= dep github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= dep github.com/pires/go-proxyproto v0.7.0 h1:IukmRewDQFWC7kfnb66CSomk2q/seBuilHBYFwyq0Hs= dep github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= dep github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= dep github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= dep github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= dep github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= dep github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= dep github.com/quic-go/quic-go v0.44.0 h1:So5wOr7jyO4vzL2sd8/pD9Kesciv91zSk8BoFngItQ0= dep github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= dep github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= dep github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= dep github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= dep github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= dep github.com/slackhq/nebula v1.6.1 h1:/OCTR3abj0Sbf2nGoLUrdDXImrCv0ZVFpVPP5qa0DsM= dep github.com/smallstep/certificates v0.26.1 h1:FIUliEBcExSfJJDhRFA/s8aZgMIFuorexnRSKQd884o= dep github.com/smallstep/go-attestation v0.4.4-0.20240109183208-413678f90935 h1:kjYvkvS/Wdy0PVRDUAA0gGJIVSEZYhiAJtfwYgOYoG A= dep github.com/smallstep/nosql v0.6.1 h1:X8IBZFTRIp1gmuf23ne/jlD/BWKJtDQbtatxEn7Et1Y= dep github.com/smallstep/pkcs7 v0.0.0-20231024181729-3b98ecc1ca81 h1:B6cED3iLJTgxpdh4tuqByDjRRKan2EvtnOfHr2zHJVg= dep github.com/smallstep/scep v0.0.0-20231024192529-aee96d7ad34d h1:06LUHn4Ia2X6syjIaCMNaXXDNdU+1N/oOHynJbWgpXw= dep github.com/smallstep/truststore v0.13.0 h1:90if9htAOblavbMeWlqNLnO9bsjjgVv2hQeQJCi/py4= dep github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA= dep github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= dep github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= dep github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU= dep github.com/tailscale/tscert v0.0.0-20240517230440-bbccfbf48933 h1:pV0H+XIvFoP7pl1MRtyPXh5hqoxB5I7snOtTHgrn6HU= dep github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk= dep github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= dep github.com/yuin/goldmark v1.7.1 h1:3bajkSilaCbjdKVsKdZjZCLBNPL9pYzrCakKaf4U49U= dep github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc h1:+IAOyRda+RLrxa1WC7umKOZRsGq4QrFFMY ApOeHzQwQ= dep github.com/zeebo/blake3 v0.2.4 h1:KYQPkhpRtcqh0ssGYcKLG1JYvddkEA8QwCM/yBqhaZI= dep go.etcd.io/bbolt v1.3.9 h1:8x7aARPEXiXbHmtUwAIv7eV2fQFHrLLavdiJ3uzJXoI= dep go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk= dep go.opentelemetry.io/contrib/propagators/autoprop v0.42.0 h1:s2RzYOAqHVgG23q8fPWYChobUoZM6rJZ98EnylJr66w= dep go.opentelemetry.io/contrib/propagators/aws v1.17.0 h1:IX8d7l2uRw61BlmZBOTQFaK+y22j6vytMVTs9wFrO+c= dep go.opentelemetry.io/contrib/propagators/b3 v1.17.0 h1:ImOVvHnku8jijXqkwCSyYKRDt2YrnGXD4BbhcpfbfJo= dep go.opentelemetry.io/contrib/propagators/jaeger v1.17.0 h1:Zbpbmwav32Ea5jSotpmkWEl3a6Xvd4tw/3xxGO1i05Y= dep go.opentelemetry.io/contrib/propagators/ot v1.17.0 h1:ufo2Vsz8l76eI47jFjuVyjyB3Ae2DmfiCV/o6Vc8ii0= dep go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= ```

Make sure you're using master to ensure you're using the latest version of Caddy.

I'm using the caddy:builder container, see Dockerfile above.

That actually looks like a bug in the leaseweb plugin.

To be honest, I just tried to make the existing plugin work. If there is missing error handling in the plugin then I believe you.

But what happened was that it was already working on server X, then I tried the same branch on server Y on which I got the panic. After debugging I noticed I couldn't contact the api either using wget, so I fixed a routing issue and after that the panic was resolved too.

pimlie commented 3 hours ago

You might be able to repro this with any dns provider if you add a 0.0.0.1 api.provider.com entry to your /etc/hosts file. It seems at least I can repro the panic with a valid route but pointing the api domain to an invalid/unreachable ip

francislavoie commented 2 hours ago
xcaddy build \
    --with github.com/caddyserver/certmagic@v0.21.4

That's the wrong way to build. You can't just upgrade certmagic without upgrading Caddy as well. Do xcaddy build master, and omit certmagic (latest Caddy on master uses latest certmagic).

pimlie commented 1 hour ago

Ah ok, sorry had no idea. Maybe I'm just too spoiled by other dev env's that I expected some internal dependency check if two closely developed packages shouldn't be used without each other's corresponding versions ;)

As I dont have the time to retest this again I'm gonna assume that that was the issue until it bites me again. Thanks.