VAULT-ASSOCIATE-002 · Question #96
You manage two Vault dusters: "vaultduster1.acme.corp" and "vaultduster2.acme.corp". You want to write a secret to the first Vaultcluster vaultcluster1.acme.corp and run vault kv put secret/foo…
The correct answer is C. Flags take precedence over environment variables. The second attempt succeeded because command-line flags, specifically the -address flag, take precedence over environment variables like VAULT_ADDR when specifying the target Vault server.
Question
Options
- AEnvironment variables take precedence over flags
- BVAULT_CLUSTER_ADDR needs to be provided
- CFlags take precedence over environment variables
- DVault listener is misconfigured
How the community answered
(51 responses)- A6% (3)
- B2% (1)
- C88% (45)
- D4% (2)
Why each option
The second attempt succeeded because command-line flags, specifically the `-address` flag, take precedence over environment variables like `VAULT_ADDR` when specifying the target Vault server.
This statement is incorrect; command-line flags override environment variables, not the other way around, in the Vault CLI's order of precedence.
`VAULT_CLUSTER_ADDR` is not a standard environment variable used by the Vault CLI for specifying the target Vault address; the correct variable is `VAULT_ADDR`.
When both an environment variable like `VAULT_ADDR` and a command-line flag such as `-address` are present in a Vault CLI command, the command-line flag is always given higher priority. This design allows users to override default configurations set by environment variables for specific commands without changing their environment permanently.
The Vault listener was likely correctly configured for `vaultcluster1.acme.corp`, but the initial command targeted the wrong cluster due to the `VAULT_ADDR` environment variable being overridden by the flag in the second attempt.
Concept tested: Vault CLI environment variables and flags precedence
Source: https://developer.hashicorp.com/vault/docs/commands#environment-variables
Topics
Community Discussion
No community discussion yet for this question.