Skip to content

feat(security): auto-detect local networks, hot-reload config, and 403 handling - #63

Merged
laolusrael merged 3 commits into
developfrom
feature/security-and-hot-reload
Jun 1, 2026
Merged

feat(security): auto-detect local networks, hot-reload config, and 403 handling#63
laolusrael merged 3 commits into
developfrom
feature/security-and-hot-reload

Conversation

@laolusrael

Copy link
Copy Markdown
Owner

Summary

Implements automatic local network detection, hot-reloadable configuration, and proper 403 access denied handling.

Changes

Security

  • Auto-detect local networks: On first run, \DetectLocalNetworks()\ scans all interfaces for RFC1918 private ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) plus loopback (127.0.0.0/8)
  • IP whitelist always active: Removed the no-op bypass when \�llowed_ips\ was empty - now returns 403 Forbidden
  • Migration safety: Existing installations with empty \�llowed_ips\ get auto-detected networks at runtime (without modifying config file)
  • /api/health now protected: Moved inside the API group so health checks also require whitelisted IP

Hot-Reload

  • ConfigManager: Thread-safe config access with \sync.RWMutex, reads applied per-request by middleware
  • Hot-reloadable settings: \�llowed_ips, logging (level/format/output), multipass timeout, SSH key path apply immediately
  • Require restart: \server.host\ and \server.port\ still need restart
  • Settings UX: Shows success or restart-required message based on what was changed

Frontend

  • /unauthorized page: Dedicated 403 access denied page with grayscale design
  • +error.svelte: Standard SvelteKit error page
  • 403 redirect: API service detects 403 and redirects to /unauthorized
  • Fixed duplicate types: Removed duplicate \InstanceState\ and \SnapshotList\ definitions

Files Changed (18)

  • 3 new files: \config_manager.go, +error.svelte, \unauthorized/+page.svelte\
  • 15 modified files across backend and frontend

Testing

  • All Go tests pass (70+ tests)
  • Frontend builds successfully
  • Added hot-reload test for IP whitelist middleware
  • Updated existing tests for ConfigManager integration

…3 handling

- Add DetectLocalNetworks() to auto-populate allowed_ips with RFC1918 ranges
- Add ConfigManager for thread-safe config access and hot-reload support
- IP whitelist now always active (removed no-op bypass), returns 403 Forbidden
- Hot-reload allowed_ips, logging, multipass timeout, and SSH key path
- Server host/port still require restart
- Move /api/health inside protected API group
- Add /unauthorized page and +error.svelte for 403 handling
- Fix duplicate TypeScript type definitions (InstanceState, SnapshotList)
- Auto-detect networks on existing installations with empty allowed_ips
- Fix +error.svelte to use page from \/state instead of wrong data props
- Fix logger data race: wrap globals in atomic.Pointer for thread-safe reads
- Fix config handler: reinit logger even when server settings require restart
- Add tests for DetectLocalNetworks, ConfigManager, and concurrent access
- Add IPv6 ULA (fd00::/8) support to DetectLocalNetworks
- Add debug logging to DetectLocalNetworks for troubleshooting
…riable

- Change Store to accept *zerolog.Logger pointer for explicit indirection
- Remove unused logOutput package-level variable (dead store)
- Use local writer variable in Init/Reinit instead of package-level assignment
@laolusrael
laolusrael merged commit d747c76 into develop Jun 1, 2026
5 checks passed
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