Pulse/internal/config
rcourtman accecdb50b Make api_tokens.json authoritative source for API tokens (fixes #685)
This is the proper architectural fix for #685. The previous commit was a
bandaid that prevented unnecessary .env writes. This commit addresses the
root cause: dual-source-of-truth for API tokens (.env vs api_tokens.json).

Changes:

1. Startup Migration (config.go:896-951):
   - When loading config, if API_TOKEN/API_TOKENS exist in .env but not in
     api_tokens.json, automatically migrate them
   - Migrated tokens are named "Migrated from .env (prefix)" for clarity
   - Logs a deprecation warning: API_TOKEN/API_TOKENS in .env are deprecated
   - Leaves .env untouched (safe for existing deployments)

2. Config Watcher Changes (watcher.go:338-424):
   - Only load tokens from .env if api_tokens.json is EMPTY
   - Once api_tokens.json has records, it becomes the authoritative source
   - .env changes no longer trigger token overwrites when api_tokens.json exists
   - Logs debug message when ignoring env tokens

Result:
- Existing deployments: env tokens automatically migrated to api_tokens.json
- UI-created tokens: never overwritten by .env changes
- Dark mode toggle: no longer triggers token reload from .env
- Backward compatible: fresh installs with API_TOKEN in .env still work
- Migration path: users can safely keep API_TOKEN in .env, it will be ignored

Future improvement: Add UI warning when API_TOKEN/API_TOKENS still present
in .env, prompting users to rotate tokens via the UI.
2025-11-11 00:17:40 +00:00
..
api_tokens.go feat: add native Windows service support and expandable host details 2025-10-23 22:11:56 +00:00
api_tokens_test.go Add API token scopes and standalone host agent 2025-10-23 11:40:31 +00:00
client_helpers.go Fix settings security tab navigation 2025-10-11 23:29:47 +00:00
config.go Make api_tokens.json authoritative source for API tokens (fixes #685) 2025-11-11 00:17:40 +00:00
credentials.go Fix settings security tab navigation 2025-10-11 23:29:47 +00:00
docker_metadata.go Clarify Docker agent cycling troubleshooting for cloned VMs/LXCs (related to #648) 2025-11-07 22:59:19 +00:00
export.go feat: production-ready import/export with API tokens and transactional rollback 2025-10-21 14:37:44 +00:00
guest_metadata.go Improve backup-age alerts to show VM/CT names in multi-cluster setups (related to #668) 2025-11-08 18:24:04 +00:00
import_transaction.go feat: production-ready import/export with API tokens and transactional rollback 2025-10-21 14:37:44 +00:00
oidc.go Fix settings security tab navigation 2025-10-11 23:29:47 +00:00
persistence.go Fix dark mode toggle wiping API tokens (related to #685) 2025-11-11 00:11:41 +00:00
persistence_fail_test.go Harden setup token flow and enforce encrypted persistence 2025-10-25 16:00:37 +00:00
persistence_test.go Add API token scopes and standalone host agent 2025-10-23 11:40:31 +00:00
registration.go Fix settings security tab navigation 2025-10-11 23:29:47 +00:00
watcher.go Make api_tokens.json authoritative source for API tokens (fixes #685) 2025-11-11 00:17:40 +00:00