Skip to main content

Cubbyhole Response Wrapping

The term cubbyhole comes from an Americanism where you get a "locker" or "safe place" to store your belongings or valuables. In Vault, the cubbyhole is your "locker". All secrets are namespaced under your token. If that token expires or is revoked, all the secrets in its cubbyhole are revoked as well.

It is not possible to reach into another token's cubbyhole even as the root user. This is an important difference between the cubbyhole and the key/value secrets engine. The secrets in the key/value secrets engine are accessible to any token for as long as its policy allows it.

Personas

The end-to-end scenario described in this tutorial involves two personas:

  • admin with privileged permissions to create tokens
  • apps trusted entity retrieving secrets from Vault

Challenge

In order to tightly manage the secrets, you set the scope of who can do what using the Vault policy and attach that to tokens, roles, entities, etc.

Think of a case where you have a trusted entity (Chef, Jenkins, etc.) which reads secrets from Vault. This trusted entity must obtain a token. If the trusted entity or its host machine was rebooted, it must re-authenticate with Vault using a valid token.

How can you securely distribute the initial token to the trusted entity?

Solution

Use Vault's cubbyhole response wrapping where the initial token is stored in the cubbyhole secrets engine. The wrapped secret can be unwrapped using the single-use wrapping token. Even the user or the system created the initial token won't see the original value. The wrapping token is short-lived and can be revoked just like any other tokens so that the risk of unauthorized access can be minimized.

What is cubbyhole response wrapping?

  • When response wrapping is requested, Vault creates a temporary single-use token (wrapping token) and insert the response into the token's cubbyhole with a short TTL
  • Only the expecting client who has the wrapping token can unwrap this secret
  • Any Vault response can be distributed using the response wrapping

Benefits of using the response wrapping:

  • It provides cover by ensuring that the value being transmitted across the wire is not the actual secret. It's a reference to the secret.
  • It provides malfeasance detection by ensuring that only a single party can ever unwrap the token and see what's inside
  • It limits the lifetime of the secret exposure
    • The TTL of the response-wrapping token is separate from the wrapped secret's lease TTL

Scenario Introduction

Think of a scenario where apps read secrets from Vault. The apps need:

  • Policy granting "read" permission on the specific path (secret/dev)
  • Valid tokens to interact with Vault

Setting the appropriate policies and token generation are done by the admin persona. For the admin to distribute the initial token to the app securely, it uses cubbyhole response wrapping. In this tutorial, you perform the following:

  1. Create and wrap a token
  2. Unwrap the secret

NOTE: This tutorial demonstrates how the response wrapping works. To learn more about reading and writing secrets in Vault, refer to the Static Secret tutorial.

Step 1: Create and wrap a token

(Persona: admin)

When a newly created token is wrapped, Vault inserts the generated token into the cubbyhole of a single-use token, returning that single-use wrapping token. Retrieving the secret requires an unwrap operation against this wrapping token.

In this scenario, an admin user creates a token using response wrapping. To perform the steps in this tutorial, first create a policy for the app.

apps-policy.hcl:

path "secret/data/dev" {
capabilities = [ "read" ]
}
  1. First create an apps policy.

    vault policy write apps apps-policy.hcl
  2. Enable key/value v2 secrets engine at secret/ if it's not enabled already.

    vault secrets enable -path=secret kv-v2
  3. Write some test data at secret/dev.

    vault kv put secret/dev username="webapp" password="my-long-password"
  4. Generate a token for apps persona using response wrapping with TTL of 120 seconds. Also, the generated token should have the apps policy attached. Use the -wrap-ttl flag to specify that the response should be wrapped and the wrap TTL indicates the life of the wrapping token which can be either an integer number of seconds or a string duration of minutes (2m) or hours (1h).

    vault token create -policy=apps -wrap-ttl=120

    The response is the wrapping token; therefore the admin user does not even see the generated token from the token create command.

Step 2: Unwrap the secret

(Persona: apps)

The apps persona receives a wrapping token from the admin. In order for the apps to acquire a valid token to read secrets from secret/dev path, it must run the unwrap operation using this token.

NOTE: If a client has been expecting delivery of a response-wrapping token and none arrives, this may be due to an attacker intercepting the token and then preventing it from traveling further. This should cause an alert to trigger an immediate investigation.

The following tasks will be performed to demonstrate the client operations:

  1. Create a token with default policy

  2. Authenticate with Vault using this default token (less privileged token)

  3. Unwrap the secret to obtain more privileged token (apps persona token)

  4. Verify that you can read secret/dev using the appstoken

  5. First, create a token with default policy.

    vault token create -policy=default
  6. Authenticate using the generated token.

    vault login s.VR3mwdk9miJ6VRLFbQe0Duwq
  7. Unwrap the secret by passing the wrapping token you received in Step 1.

    VAULT_TOKEN="s.3Kf3Xfn58Asr3bSDkRXATHrw" vault unwrap
  8. Once the client acquired the token, future requests can be made using this token.

    Example:

    vault login s.e5XHvU78iR08vAUk4Wq9JOBk

    Verify to see if the token can access secret/dev.

    vault kv get secret/dev