Skip to content

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?

  1. AAt auth.client_token, sent in the X-Vault-Token header
  2. BAt data.token, sent in the X-Vault-Token header
  3. CAt auth.accessor, sent as an Authorization Bearer token
  4. 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.

Question 2 · choose 1

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?

  1. Avault login -method=ldap -path=ldap-corp -no-store username=jdoe
  2. Bvault login -method=ldap-corp -no-store username=jdoe
  3. Cvault login -method=ldap -path=ldap-corp -no-print username=jdoe
  4. Dvault login -path=ldap-corp -no-store username=jdoe
Show the answer and why
  • Avault login -method=ldap -path=ldap-corp -no-store username=jdoe

    Correct

    -method names the type, -path names where it is enabled, and -no-store prints the token without saving it to the token helper.

  • Bvault login -method=ldap-corp -no-store username=jdoe

    Incorrect

    -method takes the auth method type, not the path where it is enabled, so ldap-corp is not a valid method.

  • Cvault login -method=ldap -path=ldap-corp -no-print username=jdoe

    Incorrect

    -no-print only hides the token; it is still stored in the token helper.

  • Dvault login -path=ldap-corp -no-store username=jdoe

    Incorrect

    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.

Question 3 · choose 1

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?

  1. Avault auth list
  2. Bvault login -no-print
  3. Cvault token capabilities
  4. 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.

Question 4 · choose 1

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?

  1. AExport the token in the VAULT_ADDR environment variable
  2. BExport the token in the VAULT_TOKEN environment variable
  3. CPass the token to vault kv get with -method=token
  4. 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.

Question 5 · choose 1

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?

  1. A-output-curl-string
  2. B-format=json
  3. C-output-policy
  4. 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.

Question 6 · choose 1

After a successful vault login, later CLI commands work without logging in again. Where does the CLI keep the credential by default?

  1. AIn the user's cubbyhole on the Vault server
  2. BIn the VAULT_TOKEN variable of the current shell
  3. CIn ~/.vault-token, written by the token helper
  4. DIn the operating system's keychain by default
Show the answer and why
  • AIn the user's cubbyhole on the Vault server

    Incorrect

    The cubbyhole stores data for a token; it is not where the CLI caches the token.

  • BIn the VAULT_TOKEN variable of the current shell

    Incorrect

    The CLI reads VAULT_TOKEN if it is set but does not set it.

  • CIn ~/.vault-token, written by the token helper

    Correct

    The token helper caches tokens after vault login; the default file is ~/.vault-token.

  • DIn the operating system's keychain by default

    Incorrect

    The default token helper writes a file; a custom helper is needed for other stores.

Deleting ~/.vault-token logs the CLI user out; a custom token helper can store tokens elsewhere.

Practice domain 1 →Practice all domains →