Skip to content

feat(2b): config hardening — .env, password_file, SIGHUP + rename-safe watcher#2

Merged
fjacquet merged 4 commits into
mainfrom
phase2b-config
Jun 15, 2026
Merged

feat(2b): config hardening — .env, password_file, SIGHUP + rename-safe watcher#2
fjacquet merged 4 commits into
mainfrom
phase2b-config

Conversation

@fjacquet

Copy link
Copy Markdown
Owner

Phase 2b — Config Hardening

Adds .env loading, file-backed secrets, and robust reload triggers without changing any metric output. Implements all of Phase 2 spec §2b (plan).

What's in it

  • .env loading (5f922fc) — config.LoadDotEnv runs before ${VAR} interpolation so config references resolve. Uses joho/godotenv, which never overrides already-set env vars (real secret injection always wins).
  • password_file secrets (c2077de) — per-host/auths password_file: read at validate time and trimmed; wins over inline password. Re-read on every reload, so secret rotation is picked up without a restart.
  • SIGHUP + rename-safe watcher (488f965) — kill -HUP triggers a reload; the fsnotify watcher now handles Rename/Remove (editor atomic-save) with a bounded re-add. Deliberately avoids upstream PR Improve config file watcher resilience mrlhansen/idrac_exporter#148's goroutine-leaking recursion and per-event sleep.

Contract-neutrality

internal/collector is byte-for-byte unchanged — metric output is unaffected. go.mod adds only github.com/joho/godotenv v1.5.1 (no errgroup/resty/OTLP scope creep).

Verification

  • gofmt -l . clean, go vet ./... clean
  • go test -race ./... → 9 pass across 5 packages
  • golangci-lint run ./... → 0 issues
  • govulncheck ./... → no vulnerabilities

Known follow-ups (pre-existing, out of scope)

  • The 1s dedup gate runs before the rename/remove re-add — an editor atomic-save (write→rename <1s later) can silently drop the watch. Identical at base; inherited, not introduced.
  • Reader-writer race on config.Config.Collect/.Event read without Config.Mutex in internal/collector — wants a Config.Snapshot() accessor.

🤖 Generated with Claude Code

fjacquet and others added 4 commits June 15, 2026 15:31
Three TDD tasks: godotenv .env loading (before ${VAR} interpolation, never
overriding real env); per-host password_file secrets; SIGHUP reload + a
rename-safe file watcher (folds upstream mrlhansen#148's fsnotify.Rename handling
cleanly — bounded re-add, no goroutine-leaking recursion).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add LoadDotEnv() to internal/config that uses godotenv.Load (never
Overload) to read .env from cwd and the config file's directory before
os.ExpandEnv runs in FromFile, so ${VAR} references resolve from .env
without ever overriding real environment variables. Wire it in main.go
immediately before LoadConfig.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Read a secret from a file at config validation time so that passwords
can be injected via Kubernetes secrets or similar mechanisms without
embedding them in YAML. Trailing whitespace is trimmed. An unreadable
file is a hard error (fail-fast). Covered by two new unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add SIGHUP signal handler (signals.go) that reloads configuration
on SIGHUP for the process lifetime. Rewrite WatchConfig event loop
to handle editor atomic-save patterns (rename/replace) via shouldReload
and bounded readd helpers, with burst deduplication. Add TestShouldReload
unit test for the pure shouldReload predicate.

Move the Collect/Event struct assignments inside ReloadConfig's mutex
to close the writer-writer race now that two live goroutines (WatchConfig
and handleSignals) can both call ReloadConfig concurrently.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@fjacquet, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 8 minutes and 25 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ba2c1419-0b9f-4e7d-bd5b-46c904f6bf17

📥 Commits

Reviewing files that changed from the base of the PR and between f0b9ebc and 488f965.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (11)
  • cmd/idrac_exporter/config.go
  • cmd/idrac_exporter/config_test.go
  • cmd/idrac_exporter/main.go
  • cmd/idrac_exporter/signals.go
  • docs/superpowers/plans/2026-06-15-phase2b-config-hardening.md
  • go.mod
  • internal/config/config.go
  • internal/config/config_test.go
  • internal/config/dotenv.go
  • internal/config/dotenv_test.go
  • internal/config/model.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch phase2b-config

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant