Skip to content

Reject unknown YAML config keys instead of silently ignoring them#80

Merged
LarsLaskowski merged 1 commit into
mainfrom
claude/issue-60-d1ly80
Jul 17, 2026
Merged

Reject unknown YAML config keys instead of silently ignoring them#80
LarsLaskowski merged 1 commit into
mainfrom
claude/issue-60-d1ly80

Conversation

@LarsLaskowski

@LarsLaskowski LarsLaskowski commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • loadYAMLFile used plain yaml.Unmarshal, so a typo like api_kay: (instead of api_key:) or a mis-indented block was silently dropped, and the built-in default applied without warning. For api_key that default is no authentication, which undermines the point of Validate() catching config typos at startup.
  • Switched to yaml.NewDecoder(...) with dec.KnownFields(true), so any unknown key at the top level or nested under thresholds/alerts/webhooks now fails Load() with a descriptive error naming the offending key.
  • An empty or comment-only config file is explicitly still accepted (not an error): Decode reports "nothing to decode" as io.EOF rather than a no-op like Unmarshal did, so that case is handled explicitly to avoid a regression for minimal/placeholder config files.
  • Verified packaging/pimonitor.example.yaml still loads cleanly under strict decoding and resolves to the same values as before.

Related Issue

Closes #60

Checklist

  • Tests added/updated for the change (go test ./... passes locally)
  • go vet ./... and golangci-lint run are clean
  • Documentation updated if this changes the REST API (docs/API.md), configuration (README.md, packaging/pimonitor.example.yaml), or installation/packaging (packaging/install.sh, systemd units) — not applicable, no config keys or shapes changed, this only makes existing typos fail loudly
  • No breaking change to /api/v1/... response shapes, or a new API version was introduced instead

loadYAMLFile used plain yaml.Unmarshal, so a typo like api_kay: (instead
of api_key:) or a mis-indented block was silently dropped and the
built-in default applied without warning. For a security-relevant key
like api_key, that default is no authentication, which is a real
footgun for anyone relying on Validate() to catch config typos at
startup.

Switch to yaml.NewDecoder with KnownFields(true) so an unknown key at
any level now fails Load() with a descriptive error naming the
offending key. Explicitly tolerate io.EOF from an empty or
comment-only file, since Decode (unlike Unmarshal) treats "nothing to
decode" as EOF rather than a no-op.

Closes #60
@LarsLaskowski
LarsLaskowski merged commit bde3ebe into main Jul 17, 2026
3 checks passed
@LarsLaskowski
LarsLaskowski deleted the claude/issue-60-d1ly80 branch July 17, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Robustness: unknown YAML config keys are silently ignored (typo in api_key falls back to no auth)

2 participants