Repository navigation
access: apply CLI -u/-k/-s overrides after -p profile load and isolate supplied credentials - #232
Open
Paramveersingh-S wants to merge 1 commit into
Conversation
…e supplied credentials Fixes apache#188
Author
|
cc @shwstppr @DaanHoogland @weizhouapache for review whenever you get a chance — fixes |
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.
Fixes #188
Problem
Following PR #174 (which addressed #168), three credential-handling bugs remained when combining
-p <profile>with-k/-s/-uor when launching the interactivecmkshell with CLI credentials (as noted in #174 (comment) and #174 (comment)):-p <profile>overwrote-u,-k, and-sCLI flags (cmk.go:101-115):In
main(),cfg.LoadProfile(*profile, true)ran aftercfg.UpdateConfig("url", ...),cfg.UpdateConfig("apikey", ...), andcfg.UpdateConfig("secretkey", ...). BecauseLoadProfilereplacescfg.ActiveProfilewith the profile section from.cmk/config, runningcmk -p randy -k <key> -s <secret>discarded the CLI-k,-s, and-uflags and silently authenticated withrandy's profile credentials.ExecLine/completer) droppedcredentialsSupplied:When launching an interactive shell with
cmk -k <key> -s <secret>,ExecLinehardcodedExecCmd(args, false)(cli/exec.go:51). Additionally,cmk.goleftcfg.ActiveProfile.UsernameandPasswordintact from the loaded profile. If only-kwas supplied or if the key failed in the interactive shell,cmkfell back to the profile'susername/password.-kor only-s) fell back to profile credentials:If a user passed only
-k <key>(without-s),len(APIKey) > 0 && len(SecretKey) > 0evaluated tofalseandNewAPIRequestfell through toLogin(r)with the profile'susername/password.Solution
cmk.go:-p <profile>before applying-u,-k, and-soverrides so CLI flags and environment variables take precedence over the loaded profile.-kor-sis supplied on the command line (or viaCMK_API_KEY/CMK_SECRET_KEY), setcfg.CredentialsSupplied = true, clearActiveProfile.UsernameandActiveProfile.Passwordin memory, and set bothActiveProfile.APIKey = *apiKeyandActiveProfile.SecretKey = *secretKeyso stored profile credentials cannot leak into the session.config/config.go&cli/exec.go&cli/completer.go:CredentialsSuppliedonconfig.Configand propagatecfg.CredentialsSuppliedinExecLineandautoCompleter.Do. ResetCredentialsSupplied = falseif the user explicitly switches profiles (set profile) or setsusername/passwordin the shell.cmd/network.go&cmd/network_test.go:CredentialsSupplied && (len(APIKey) == 0 || len(SecretKey) == 0)) with a clear error ("both apikey and secretkey must be provided when authenticating with keys") instead of falling back to profileusername/passwordlogin.TestPartialCLICredentialsFailWithoutFallingBackToProfileLoginincmd/network_test.go.Verification / Solution Proof