---
site: steel.dev
collection: docs
canonical_url: https://steel.dev/docs/integrations/hashicorp-vault
markdown_url: https://steel.dev/docs/integrations/hashicorp-vault.md
content_signal: ai-input=yes, ai-train=yes, search=yes
title: Fill HashiCorp Vault logins in a Steel session
description: Connect HashiCorp Vault to Steel and bind a KV version 2 secret to a session, so the session fills logins that stay in your Vault.
summary: Connect HashiCorp Vault to Steel and bind a KV version 2 secret to a session, so the session fills logins that stay in your Vault.
type: integration-guide
prerequisites: []
related:
  - https://steel.dev/docs/integrations/1password.md
agent_setup: https://setup.steel.dev/install.md
docs_index: https://steel.dev/docs/sitemap.md
---

# Fill HashiCorp Vault logins in a Steel session

HashiCorp Vault is a secret manager that you run or rent. With a [Secret Connection](https://steel.dev/docs/logins/secret-connections), a Steel session fills a login from a Vault secret into a sign-in form. The login stays in HashiCorp Vault: Steel reads it when the session needs it and does not store a copy. Your code and your agent never get the password.

Steel reads the KV version 2 secrets engine only. It signs in with a token or an AppRole. A session can use only the secrets that you bind to it.

> **Note**
>
> This page says "HashiCorp Vault" for the provider. A Steel [Vault](https://steel.dev/docs/logins/vaults) is a different thing: a group of credentials that Steel stores.

## Before you begin

- A HashiCorp Vault server with an HTTPS address that the public internet can reach. Steel does not connect to a private address, and it does not follow redirects.
- A KV version 2 mount, such as `secret`.
- A Steel API key in the `STEEL_API_KEY` environment variable, for the API, SDK and CLI steps. See [API keys](https://steel.dev/docs/account/api-keys). [Secret Connections](https://steel.dev/docs/logins/secret-connections#before-you-begin) says what the SDK and CLI examples need.

## Set up the integration

### Store the login as a secret

Steel reads a login from the keys of one secret:

| Part of the login | Key |
| - | - |
| Username | The first of `username`, `email`, `login` and `identifier` that the secret has |
| Password | `password` |
| One-time password secret | `otp`, `totp`, `authenticator`, `mfa` or `2fa`, alone or with `_secret`, `_seed` or `_key` at the end, such as `totp_secret` |

Steel ignores the case of a key. Each value must be a string. Steel does not read a secret that has an object or an array as a value.

```sh
vault kv put secret/team/acme-billing username="$SITE_USERNAME" password="$SITE_PASSWORD"
```

### Give Steel read access

Write a policy that lets Steel read the secrets. To bind a path prefix, Steel must also list the paths under it.

```text
path "secret/data/team/*" {
  capabilities = ["read"]
}

path "secret/metadata/team/*" {
  capabilities = ["list"]
}
```

Then make a token with this policy, or an AppRole. With an AppRole, Steel signs in again when its Vault token expires, so do not limit the secret ID to one use.

### Connect HashiCorp Vault

In the dashboard:

1. Open **Credentials** in the sidebar, then the **Connections** tab.
2. Click **Connect provider**.
3. Type a **Name**, and choose **HashiCorp Vault** as the **Provider**.
4. Type the **Vault address**, such as `https://vault.example.com`, with no path.
5. If you need them, type the **Vault namespace** and paste the **CA certificate** in PEM format.
6. Choose the **Authentication method**. For **Token**, paste the token. For **AppRole**, paste the **Role ID** and the **Secret ID**, and type the **AppRole auth mount** if it is not `approle`.
7. Click **Connect provider**. With a token, you can click **Test** first.

With the API, an SDK or the CLI, and a token:

**cURL**

```sh
curl -X POST https://api.steel.dev/v1/secret-connections \
  -H "steel-api-key: $STEEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "production",
    "provider": "hashicorp_vault",
    "config": { "address": "https://vault.example.com" },
    "auth": { "type": "token", "token": "'"$VAULT_TOKEN"'" }
  }'
```

**TypeScript**

```ts
const connection = await client.secretConnections.create({
  name: "production",
  provider: "hashicorp_vault",
  config: { address: "https://vault.example.com" },
  auth: { type: "token", token: process.env.VAULT_TOKEN! },
});
console.log(connection.id);
```

**Python**

```python
connection = client.secret_connections.create(
    name="production",
    provider="hashicorp_vault",
    config={"address": "https://vault.example.com"},
    auth={"type": "token", "token": os.environ["VAULT_TOKEN"]},
)
print(connection.id)
```

**CLI**

```sh
printf '{ "name": "production", "provider": "hashicorp_vault", "config": { "address": "https://vault.example.com" }, "auth": { "type": "token", "token": "%s" } }' \
  "$VAULT_TOKEN" | steel secret-connections create
```

With an AppRole, send this `auth` instead. In Python, the keys are `role_id` and `secret_id`.

```json
{ "type": "approle", "roleId": "ROLE_ID", "secretId": "SECRET_ID" }
```

| Field | Required | Description |
| - | - | - |
| `config.address` | Yes | The HTTPS address of the server. |
| `config.namespace` | No | The Vault namespace. |
| `config.caPem` | No | A CA certificate in PEM format, for a server whose certificate a public CA did not sign. |
| `auth.mount` | No | The mount of the AppRole auth method. The default is `approle`. |

The response has the connection's `id`, `name`, `provider` and `enabled`. It never has the `config` or the `auth`.

### Bind a secret to a session

A binding names what the session can use, and the origins where Steel can fill it. You write the secret as a reference:

| Reference | The session can use |
| - | - |
| `steel://connections/<connection>/kv/<mount>/<path>` | One secret |
| `steel://connections/<connection>/kv/<mount>/<path>/` | Every secret under the path, at any depth. The reference ends with a slash |

`<connection>` is the connection's name or ID. Percent-encode each part of the path on its own, and do not encode the slashes between the parts. Steel reads the latest version of a secret.

A secret does not say which website it is for, so you give the origins in `allowedOrigins`. Steel fills the secret only on a page whose origin is in the list: the same scheme, host and port. A binding can have up to 20 origins.

> **Warning**
>
> A binding with no `allowedOrigins` fills nothing.

In the dashboard:

1. Open **Sessions**, and click **Start session**.
2. Under **Credential access**, choose **Choose what this session can use**.
3. Under **Binding type**, choose **External provider item**, then choose the connection.
4. Type the **KV v2 mount** and the **Exact secret path**.
5. Type the **Allowed origins**.
6. Click **Start session**.

The dashboard binds one secret. To bind a path prefix or more than one secret, use the API.

With the API or an SDK, pass each binding as an object in `credentials.bindings` when you create the session:

**cURL**

```sh
curl -X POST https://api.steel.dev/v1/sessions \
  -H "steel-api-key: $STEEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "credentials": {
      "bindings": [
        {
          "reference": "steel://connections/production/kv/secret/team/acme-billing",
          "allowedOrigins": ["https://app.example.com"]
        }
      ]
    }
  }'
```

**TypeScript**

```ts
const session = await client.sessions.create({
  credentials: {
    bindings: [
      {
        reference: "steel://connections/production/kv/secret/team/acme-billing",
        allowedOrigins: ["https://app.example.com"],
      },
    ],
  },
});
```

**Python**

```python
session = client.sessions.create(
    credentials={
        "bindings": [
            {
                "reference": "steel://connections/production/kv/secret/team/acme-billing",
                "allowed_origins": ["https://app.example.com"],
            }
        ],
    },
)
```

You can add or remove a binding while the session runs, as [Change what a running session can use](https://steel.dev/docs/logins/credentials#change-what-a-running-session-can-use) shows.

### Open the sign-in page

Open a sign-in page on one of the allowed origins. Steel fills the username, the password and, if the secret has a one-time password secret, the code. Steel makes the code itself. The one-time password secret never reaches the browser.

With a prefix binding, every secret under the path matches each allowed origin. When two secrets match one page, Steel does not choose between them and fills nothing. Bind one secret for each login where you can, or choose one with [`Steel.credentials.fill`](https://steel.dev/docs/logins/fill-a-sign-in-form#choose-between-credentials).

## Check that it worked

List what the session can use:

**cURL**

```sh
curl https://api.steel.dev/v1/sessions/$SESSION_ID/credentials \
  -H "steel-api-key: $STEEL_API_KEY"
```

**TypeScript**

```ts
const access = await client.sessions.credentials.list(session.id);
console.log(access.lookup, access.bindings);
```

**Python**

```python
access = client.sessions.credentials.list(session.id)
print(access.lookup, access.bindings)
```

**CLI**

```sh
steel sessions credentials list $SESSION_ID
```

The response has `"lookup": "explicit"`, and your binding in `bindings` with its `allowedOrigins`. Then open the sign-in page in the session's [live view](https://steel.dev/docs/observability/live-view). Steel fills the form shortly after the page loads.

## Troubleshooting

### The sign-in form stays empty

**Cause:** The page's origin is not in the binding's `allowedOrigins`, or the secret has no key that Steel reads, or one of its values is not a string. Under a prefix, Steel keeps the list of paths for up to 30 seconds, so a new secret can take that long to appear.

**Fix:** Compare the page's scheme, host and port with `allowedOrigins`. Name the secret's keys as [Store the login as a secret](https://steel.dev/docs/integrations/hashicorp-vault#store-the-login-as-a-secret) shows, and store each value as a string.

**Verify:** Steel fills the form.

### `credential_path_forbidden`

**Cause:** The token's policy does not let Steel read the secret. [`Steel.credentials.fill`](https://steel.dev/docs/logins/fill-a-sign-in-form) fails with this code, and Steel fills nothing on its own.

**Fix:** Add `read` on the secret's `data` path to the policy, and `list` on the `metadata` path for a prefix binding.

**Verify:** Steel fills the form.

### The connection does not save

**Cause:** Steel cannot reach the server. The address is not HTTPS, it has a path, it goes to a private network, or the server redirects.

**Fix:** Use the server's public HTTPS address with no path. If a private CA signed the server's certificate, add it as the CA certificate.

**Verify:** The connection's test returns `204`.

## Next steps

- [Secret Connections](https://steel.dev/docs/logins/secret-connections): Test a connection, replace its authentication, or disable it.
- [Fill a sign-in form from code](https://steel.dev/docs/logins/fill-a-sign-in-form): Decide when Steel fills and submits a form.
- [Credentials](https://steel.dev/docs/logins/credentials): Store a login in Steel instead.
