Fill HashiCorp Vault logins in a Steel session
HashiCorp Vault is a secret manager that you run or rent. With a Secret Connection, 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.
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_KEYenvironment variable, for the API, SDK and CLI steps. See API keys. Secret Connections 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.
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.
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:
- Open Credentials in the sidebar, then the Connections tab.
- Click Connect provider.
- Type a Name, and choose HashiCorp Vault as the Provider.
- Type the Vault address, such as
https://vault.example.com, with no path. - If you need them, type the Vault namespace and paste the CA certificate in PEM format.
- 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. - Click Connect provider. With a token, you can click Test first.
With the API, an SDK or the CLI, and a token:
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"'" }
}'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);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)printf '{ "name": "production", "provider": "hashicorp_vault", "config": { "address": "https://vault.example.com" }, "auth": { "type": "token", "token": "%s" } }' \
"$VAULT_TOKEN" | steel secret-connections createWith an AppRole, send this auth instead. In Python, the keys are role_id and secret_id.
{ "type": "approle", "roleId": "ROLE_ID", "secretId": "SECRET_ID" }| Field | Required | Description |
|---|---|---|
config. | Yes | The HTTPS address of the server. |
config. | No | The Vault namespace. |
config. | No | A CA certificate in PEM format, for a server whose certificate a public CA did not sign. |
auth. | 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:// | One secret |
steel:// | 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.
In the dashboard:
- Open Sessions, and click Start session.
- Under Credential access, choose Choose what this session can use.
- Under Binding type, choose External provider item, then choose the connection.
- Type the KV v2 mount and the Exact secret path.
- Type the Allowed origins.
- 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 -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"]
}
]
}
}'const session = await client.sessions.create({
credentials: {
bindings: [
{
reference: "steel://connections/production/kv/secret/team/acme-billing",
allowedOrigins: ["https://app.example.com"],
},
],
},
});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 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.
Check that it worked
List what the session can use:
curl https://api.steel.dev/v1/sessions/$SESSION_ID/credentials \
-H "steel-api-key: $STEEL_API_KEY"const access = await client.sessions.credentials.list(session.id);
console.log(access.lookup, access.bindings);access = client.sessions.credentials.list(session.id)
print(access.lookup, access.bindings)steel sessions credentials list $SESSION_IDThe response has "lookup": "explicit", and your binding in bindings with its allowedOrigins. Then open the sign-in page in the session's 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 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 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.