Repository navigation
fix(cli): a config kates cannot read or parse fails API calls instead of sending them to localhost:8080 without a key - #390
Merged
Conversation
… of sending them to localhost:8080 without a key When ~/.kates.yaml could not be read or parsed, kates printed a warning and went on with no contexts. The empty current context then resolved to the built-in http://localhost:8080 context, so a YAML typo in a file whose current context is prod sent every command to whatever listened on 8080 (a stale `kates ports` forward to another cluster, say) without the context's API key, and a DELETE went there too. Such a config now fails every API call through client.Failing, naming the file and saying to fix it or pass --url or set KATES_URL, as #274 does for an unknown context. --url and KATES_URL still work, and commands that never call the API still run. loadConfig keeps its signature; the root pre-run uses the new loadConfigErr to get the error it warned about.
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.
Item 1.2 of the CLI performance and stability plan (finding F6). Independent of the other Wave 1 PRs.
Why
A malformed
~/.kates.yamlsends every command tolocalhost:8080without the API key. On main (6f4cf61):loadConfigonly warns (cli/cmd/root.go:65-72).:82-103).http://localhost:8080context (:317-318).So a YAML typo in a file whose current context is
prodsends every command to whatever listens on 8080, with no API key. That can be a stalekates portsforward to another cluster, and a DELETE goes there too.The new test shows it. Run against main's
root.gowhile writing it,kates healthwith a broken config printed "System Status: UP": it reached the Kates API behind the port-forward on this machine's 8080. That was one GET of health.Changes
cli/cmd/root.go:--urlnorKATES_URLnames the server, the root pre-run sets the context error. Every API call then fails throughclient.Failing, as fix(cli): a context that does not exist is an error, not localhost #274 does for an unknown context. The message names the file and the cause, and says "Fix the file, or pass --url or set KATES_URL".loadConfigkeeps its signature for its other callers (11 in the product, more in tests). The newloadConfigErrreturns the error it warned about, and only the pre-run uses it.A missing file still means the built-in default context, as before.
Tests
Added
TestUnreadableConfigReachesNoServer, which runs the test binary as kates with a broken config in its home (KATES_TEST_HOME):healthexits 1 after no request, and the error says "could not load config" and names.kates.yaml.--url <server> test listandKATES_URL=<server> test listreach that server and exit 0.runKatesCLIis now a wrapper overrunKatesCLIConfig, which takes the config text.On main's
root.gothe test fails withexit 0 after 0 requests, because the command went to localhost:8080 instead.Run locally, passing:
cd cli && go test ./...,go test -race ./cmd,go vet ./....golangci-lint run --new-from-rev=origin/main ./...: 0 issues.scripts/check-cli-style.shandscripts/check-cli-compat.sh: OK.cli/**triggers (Build & Test): this PR touches nothing underkates/../mvnw teston main'skates/tree ran 1,254 tests with 0 failures and 0 errors, once for all of Wave 1.Skipped locally:
govulncheck, asgo.modis unchanged.CI only:
./mvnw verifywith the*ITtests, the Kind and Docker jobs, CodeQL and Trivy.