[GH-ISSUE #292] Bad things happen if [general] is missing #153

Open
opened 2026-03-13 15:57:28 +03:00 by kerem · 4 comments
Owner

Originally created by @candlerb on GitHub (Feb 21, 2022).
Original GitHub issue: https://github.com/acme-dns/acme-dns/issues/292

I found this out the hard way... I couldn't understand why acme-dns was trying to do weird stuff, like use the root domain, and then crashing:

# /usr/local/bin/acme-dns
INFO[0000] Using config file                             file=/etc/acme-dns/config.cfg
INFO[0000] Connected to database
DEBU[0000] Adding new record to domain                   domain=. recordtype=SOA
INFO[0000] Listening DNS                                 addr= proto=
FATA[0000] name does not qualify for automatic certificate management:

It turns out that due to a copy-paste error I'd missed [general] from the top of the config file. D'oh!

It would be very helpful if the config parser rejected unexpected or bad settings.

Originally created by @candlerb on GitHub (Feb 21, 2022). Original GitHub issue: https://github.com/acme-dns/acme-dns/issues/292 I found this out the hard way... I couldn't understand why acme-dns was trying to do weird stuff, like use the root domain, and then crashing: ``` # /usr/local/bin/acme-dns INFO[0000] Using config file file=/etc/acme-dns/config.cfg INFO[0000] Connected to database DEBU[0000] Adding new record to domain domain=. recordtype=SOA INFO[0000] Listening DNS addr= proto= FATA[0000] name does not qualify for automatic certificate management: ``` It turns out that due to a copy-paste error I'd missed `[general]` from the top of the config file. D'oh! It would be very helpful if the config parser rejected unexpected or bad settings.
Author
Owner

@gbonnefille commented on GitHub (Feb 22, 2022):

It is generally hard to do what you request. Config files are read to find values that override default ones. To detect extra-numerous keys requires to have a schema of the configuration and validate any input against this schema. But a INI is « open » by nature.

<!-- gh-comment-id:1047572108 --> @gbonnefille commented on GitHub (Feb 22, 2022): It is generally hard to do what you request. Config files are read to find values that override default ones. To detect extra-numerous keys requires to have a schema of the configuration and validate any input against this schema. But a INI is « open » by nature.
Author
Owner

@candlerb commented on GitHub (Feb 22, 2022):

Seems to be a limit of toml.DecodeFile then.

OK: how about make general.domain a mandatory setting and give a clearer error if it's missing? (e.g. "Required setting 'domain' in section '[general]' is missing")

<!-- gh-comment-id:1047591577 --> @candlerb commented on GitHub (Feb 22, 2022): ~~Seems to be a limit of `toml.DecodeFile` then.~~ OK: how about make `general.domain` a mandatory setting and give a clearer error if it's missing? (e.g. "Required setting 'domain' in section '[general]' is missing")
Author
Owner

@candlerb commented on GitHub (Feb 22, 2022):

Aha, it is possible: see "Example (StrictDecoding)" at https://godocs.io/github.com/BurntSushi/toml

Something like this should do the trick:

        md, err := toml.DecodeFile(fname, &conf)
        if err != nil {
                // Return with config file parsing errors from toml package
                return conf, err
        }
        undecoded := md.Undecoded()
        if len(undecoded) > 0 {
                return conf, fmt.Errorf("Unexpected keys: %v", undecoded)
        }
<!-- gh-comment-id:1047595431 --> @candlerb commented on GitHub (Feb 22, 2022): Aha, it *is* possible: see "Example (StrictDecoding)" at https://godocs.io/github.com/BurntSushi/toml Something like this should do the trick: ``` md, err := toml.DecodeFile(fname, &conf) if err != nil { // Return with config file parsing errors from toml package return conf, err } undecoded := md.Undecoded() if len(undecoded) > 0 { return conf, fmt.Errorf("Unexpected keys: %v", undecoded) } ```
Author
Owner

@rhadov commented on GitHub (Mar 16, 2025):

Just noting the last error if dns beginner like me finds this
level=fatal msg="dns: bad network"

yes I managed to waste hours on this googling and switching between dockerized/vm installations and arm/x86... :D

<!-- gh-comment-id:2727299525 --> @rhadov commented on GitHub (Mar 16, 2025): Just noting the last error if dns beginner like me finds this `level=fatal msg="dns: bad network"` yes I managed to waste hours on this googling and switching between dockerized/vm installations and arm/x86... :D
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/acme-dns#153
No description provided.