-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VAULT_AGENT_ADDR
has higher precedence than -agent-address
#27404
Comments
I created a test for all sixteen possible combination of flags and environment variables (or lack thereof). Half of them (in my opinion) simply don't make sense and if they occurred, would probably be user or developer bugs. They might be best left as undefined behavior, but I still wanted to enumerate them, figure out my logical expectations, and see the behavior both pre- and post-fix. Without changes, four out of the sixteen possibilities fail; one is my bug report, one is a variation of my report, and two are "this probably wouldn't happen in the real world". With my proposed changes, all sixteen pass (and all other existing tests continue to pass as well). I'll create a PR early next week with my proposal unless you indicate you want to hash it out here, or handle it yourselves. |
Hi, I'm a little bit confused by something in your issue description:
From my experience with using Vault and the test I just did locally using the latest version, the flag for I'm curious about the tests you wrote and how they behave in a circumstance similar. Another thing to note is that VAULT_AGENT_ADDR is deprecated in favor of VAULT_PROXY_ADDR. Have you tried using the latter? |
Even the latest release version prioritizes environment over flag: $ docker run --rm -it -e VAULT_AGENT_ADDR=http://i-am-bogus hashicorp/vault:1.17.5 vault status -agent-address=https://vault.mycorp.com:8200
Couldn't start vault with IPC_LOCK. Disabling IPC_LOCK, please use --cap-add IPC_LOCK
WARNING! VAULT_ADDR and -address unset. Defaulting to https://127.0.0.1:8200.
Error checking seal status: Get "http://i-am-bogus/v1/sys/seal-status": dial tcp: lookup i-am-bogus on 172.17.0.1:53: no such host
$ docker run --rm -it hashicorp/vault:1.17.5 vault status -agent-address=https://vault.mycorp.com:8200
Couldn't start vault with IPC_LOCK. Disabling IPC_LOCK, please use --cap-add IPC_LOCK
WARNING! VAULT_ADDR and -address unset. Defaulting to https://127.0.0.1:8200.
Key Value
--- -----
Seal Type shamir
<snip> Building from source is quite intensive on my machine, but if you think it is actually different on HEAD, I can try. But this behavior was present in the three release binaries I mentioned in my report, and
I was not aware; my company is still a few versions behind, so maybe that deprecation happens in a future release. That said, the current docs don't mention anything about |
Hey @rrjjvv 👋 thanks for your patience with this issue. I've put up a PR here that aims to fix this problem. If y'all have the time and/or bandwidth, feel free to check out the PR and give it a spin in your test environment(s) and see if it fixes the issue you've described. Also, many thanks for the excellent repro script that made tracking this bug down trivial. I can't overstate just how helpful things like that are. |
Awesome! I think the act of enumerating all sixteen possible combinations (some which don't make sense) led me to assuming it was an oversight in defining behavior rather than a true bug. Reasoning through it, your one-line fix on the command side should behave the same as my eight-line change on the api side... while being only one line 😄.
Thanks, I appreciate that. Sometimes that much detail can be off-putting and have the opposite affect; I'm glad it was welcome and useful! |
Describe the bug
From the docs:
Thus, given
I would expect the 'cli-host' to be used. I do not know if this holds true for every sub-command, but
vault status
andvault read
use the environment variable (I suspect it affects the majority of sub-commands, if not all).To Reproduce
I encountered this issue in a live environment (actual running server and agent), but the actual issue does not require these and using
-output-curl-string
is a convenient/quick way to illustrate in isolation.Expected behavior
(using address
http://cli.invalid
, nothttp://env.invalid
)Environment:
vault status
):1.12.6
(but not relevant)vault version
): verified with1.11.6
,1.12.6
,1.16.3
, andmain
Vault server configuration file(s):
N/A
Additional context
I created a longer reproduction to
I ran this against a few release binaries; all behaved the same, so only showing the oldest version I tried:
This is from
main
(at some point last night), which also has the issue, but with some selective logging to show the flow:So the issue is that on the
command
side, the environment is read earlyvault/command/base.go
Line 101 in d382103
and proceeds to (correctly) prioritize flag values (as well as "agent trumps server")
vault/command/base.go
Lines 105 to 110 in d382103
but the problem is that on the
api
side (which has no concept of flags), it performs the same "agent trumps server", with its only data source being the environmentvault/api/client.go
Lines 637 to 639 in d382103
In short, the
config
on the command side is deliberately/correctly configured before passing it toNewClient
on the api side, butNewClient
isn't fully respecting it.I have a possible fix but I can't validate it, since the test suite (
make test
) has failures (on a pristine checkout). So before spending time trying to figure that out, I figured I'd wait for confirmation that it is indeed a bug and that it should be fixed. As well, the conversation on the PR that introduced these changes made it seem like "agent wins over server" had some nuances and that maybe this 'bug' isn't as straightforward as I thought, and maybe you want to handle it yourselves.The text was updated successfully, but these errors were encountered: