Skip to content

fix: multi-host auth with scheme-aware host resolution#25

Merged
eskp merged 1 commit intomainfrom
fix/multi-host-auth
Mar 16, 2026
Merged

fix: multi-host auth with scheme-aware host resolution#25
eskp merged 1 commit intomainfrom
fix/multi-host-auth

Conversation

@eskp
Copy link
Copy Markdown
Contributor

@eskp eskp commented Mar 16, 2026

Summary

  • Scheme-aware host lookup: HostEntry() now strips URL scheme before matching hosts.yml keys, so --host https://app-staging.keeperhub.com correctly finds the app-staging.keeperhub.com entry and applies CF-Access headers
  • Tokens in hosts.yml: Login now stores tokens in the hosts.yml token field (merged into existing entries) instead of per-host JWE keyring files. Keyring kept as legacy fallback. Priority chain: KH_API_KEY env > hosts.yml > keyring
  • API key validation: FetchTokenInfo detects kh_ prefix and validates via /api/workflows probe instead of /api/auth/get-session (which only works for session tokens)

Test plan

  • go test ./... passes (29 packages, all green)
  • kh auth login --with-token --host https://app-staging.keeperhub.com stores token in hosts.yml under bare hostname alongside CF headers
  • kh wf list --host https://app-staging.keeperhub.com sends CF-Access headers and returns data (3 workflows)
  • kh auth login --with-token (prod) stores token in hosts.yml (30 workflows returned)
  • Legacy keyring tokens still work as fallback (unit test TestResolveToken_KeyringLegacyFallback covers this)
  • kh auth logout clears both hosts.yml and keyring

Three fixes for multi-host authentication:

1. HostEntry() now strips URL scheme before lookup, so --host
   https://app-staging.keeperhub.com matches a hosts.yml key of
   app-staging.keeperhub.com. This fixes CF-Access headers not
   being sent for staging requests.

2. Tokens now stored in hosts.yml instead of per-host keyring files.
   SetHostToken/ClearHostToken merge into existing bare-hostname
   entries. Keyring kept as legacy fallback. Priority chain is now:
   KH_API_KEY env > hosts.yml token > keyring (legacy).

3. FetchTokenInfo handles API keys (kh_ prefix) separately from
   session tokens, validating via /api/workflows instead of
   /api/auth/get-session which only works for session tokens.
@eskp eskp merged commit 78d76f0 into main Mar 16, 2026
4 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