fix: multi-host auth with scheme-aware host resolution#25
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HostEntry()now strips URL scheme before matchinghosts.ymlkeys, so--host https://app-staging.keeperhub.comcorrectly finds theapp-staging.keeperhub.comentry and applies CF-Access headershosts.ymltokenfield (merged into existing entries) instead of per-host JWE keyring files. Keyring kept as legacy fallback. Priority chain:KH_API_KEYenv >hosts.yml> keyringFetchTokenInfodetectskh_prefix and validates via/api/workflowsprobe 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.comstores token inhosts.ymlunder bare hostname alongside CF headerskh wf list --host https://app-staging.keeperhub.comsends CF-Access headers and returns data (3 workflows)kh auth login --with-token(prod) stores token inhosts.yml(30 workflows returned)TestResolveToken_KeyringLegacyFallbackcovers this)kh auth logoutclears both hosts.yml and keyring