003 · Domain 1: Authentication methods · 15% of the exam
Task 1.5: Authenticate to Vault using the API, CLI, and UI
vault login with -method and -path, the token helper, the login endpoints under /v1/auth, the X-Vault-Token header, and choosing a method and mount in the UI.
Study it
Logging in from the CLI, the HTTP API and the UI
Lesson coming
Sample questions
Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.
Question 1 · choose 1
A client logs in to the userpass auth method through the HTTP API, and Vault answers 200. Where is the token in the JSON response, and how does the client send it on later API calls?
AAt auth.client_token, sent in the X-Vault-Token header
BAt data.token, sent in the X-Vault-Token header
CAt auth.accessor, sent as an Authorization Bearer token
DAt auth.client_token, sent as a token query parameter
Show the answer and why
AAt auth.client_token, sent in the X-Vault-Token header
Correct
Login responses carry the token at auth.client_token, and the API accepts it in the X-Vault-Token header or as an Authorization Bearer token.
BAt data.token, sent in the X-Vault-Token header
Incorrect
A login response returns the token in the auth block, not in data.
CAt auth.accessor, sent as an Authorization Bearer token
Incorrect
The accessor is only a reference to a token; it cannot authorize requests.
DAt auth.client_token, sent as a token query parameter
Incorrect
Vault reads the token from the X-Vault-Token or Authorization header, not from a query string.
The login response's auth.client_token is the token, and every later API call sends it in a header.
The LDAP auth method is enabled at ldap-corp/. A user on a shared laptop runs vault login -method=ldap username=jdoe and gets an error that no handler exists for auth/ldap/login. The user also wants the token kept out of the local token helper. Which command does both?
Without -method the command uses the token method, which does not take a username.
When an auth method is enabled at a non-default path, -method still names its type and -path names the mount. -no-store keeps the token out of the local token helper, which suits a shared machine.
A developer logged in with vault login earlier in the day and now wants to see which token the CLI is sending on her behalf, without opening any file. Which command prints it?
Avault auth list
Bvault login -no-print
Cvault token capabilities
Dvault print token
Show the answer and why
Avault auth list
Incorrect
This lists the enabled auth methods, not the CLI's current token.
Bvault login -no-print
Incorrect
This starts a new login and hides the resulting token; it does not show the current one.
Cvault token capabilities
Incorrect
This does not print the token value.
Dvault print token
Correct
print token prints the Vault token the CLI currently uses.
vault print has a single subcommand, token, which shows the token the CLI currently uses; treat its output like any other secret.
A CI job already receives a Vault token from its secret store and must run vault kv get without calling vault login first. How does the job authenticate the CLI?
AExport the token in the VAULT_ADDR environment variable
BExport the token in the VAULT_TOKEN environment variable
CPass the token to vault kv get with -method=token
DExport the token in the VAULT_AGENT_ADDR environment variable
Show the answer and why
AExport the token in the VAULT_ADDR environment variable
Incorrect
VAULT_ADDR sets the server address, not the token.
BExport the token in the VAULT_TOKEN environment variable
Correct
The CLI accepts a token from VAULT_TOKEN, as an alternative to vault login.
CPass the token to vault kv get with -method=token
Incorrect
-method belongs to vault login, not to kv commands.
DExport the token in the VAULT_AGENT_ADDR environment variable
Incorrect
That variable points the CLI at a Vault Agent; it does not carry a token.
Unauthenticated users must use vault login or set VAULT_TOKEN before running other commands.
A developer works with the CLI every day and now has to write the same calls in a script that talks to the HTTP API. For vault token lookup, she wants the exact equivalent HTTP request printed instead of running the command. Which flag does that?
A-output-curl-string
B-format=json
C-output-policy
D-wrap-ttl=1m
Show the answer and why
A-output-curl-string
Correct
It prints the command as an equivalent cURL request instead of executing it.
B-format=json
Incorrect
This runs the command and formats the response; it does not show the request.
C-output-policy
Incorrect
This prints a minimal policy that would allow the command, not the HTTP request.
D-wrap-ttl=1m
Incorrect
This wraps the response in a single-use token; the request is still sent and not shown.
Seeing the HTTP request behind a CLI command is a quick way to learn the API path, method and body that a script must send.