Lockwell

Use case

Get secrets out of .env files

A .env file gets copied to laptops, pasted into chats and committed by accident. Move it into Lockwell once, and start the app with its secrets in its environment.

  1. Make a write identity

    In the console, make a machine identity with read and write on prod/ (or the whole space) for the move. Copy its secret ID: it's shown once.

  2. Import the file

    Each line becomes a secret named after the variable, holding it in its value field.

  3. Run with it

    A read-only identity for the server, and lw_env in its start script. Then delete the .env file.

1. Import a .env file

export VAULT_ADDR=https://vault.lunaor.com
# a machine identity made in the console logs in (Vault's AppRole): a token for an hour
export VAULT_TOKEN=$(curl -sf "$VAULT_ADDR/v1/auth/approle/login" \
  -d "{\"role_id\":\"$ROLE_ID\",\"secret_id\":\"$SECRET_ID\"}" | jq -r .auth.client_token)
# each KEY=value line becomes the secret prod/KEY with {"value": "..."}; comments and blank lines skipped
grep -v '^[[:space:]]*#' .env | grep '=' | while IFS='=' read -r k v; do
  v=$(printf '%s' "$v" | sed -e 's/^"\(.*\)"$/\1/' -e "s/^'\(.*\)'$/\1/")
  jq -n --arg v "$v" '{data: {value: $v}}' \
    | curl -sf -o /dev/null -H "X-Vault-Token: $VAULT_TOKEN" --data @- "$VAULT_ADDR/v1/lw-<team>/data/prod/$k" \
    && echo "imported $k" || echo "failed: $k" >&2
done

This simple reader takes one KEY=value per line. Multi-line values, export prefixes and escapes need a few more lines, or the secrets editor.

2. Start the app with its secrets

On the server, a read-only identity for prod/, and this in the start script:

# lw_env <tenant> <folder/>...: export every secret in the folders as variables, later folders winning.
# A secret's "value" field is named after the secret (DATABASE_URL); another field is NAME_FIELD (DB_PASSWORD).
lw_env() {
  t=$1; shift
  for f in "$@"; do
    j=$(curl -sf -H "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/$t/resolved/$f?values=true&resolve=true") \
      || { echo "lw_env: can't read $t/$f" >&2; return 1; }
    eval "$(printf '%s' "$j" | jq -r '.data.secrets[] | .name as $n | (.data // {}) | to_entries[]
      | (if .key == "value" then $n else "\($n)_\(.key)" end | ascii_upcase | gsub("[^A-Z0-9_]"; "_")) as $k
      | "export \($k)=\(.value | if type == "string" then . else tojson end | @sh)"')"
  done
}
lw_env lw-<team> shared/ prod/ && exec ./server --port 8080

Shared values (a Sentry DSN, a feature flag) go in shared/. prod/ holds what differs, and wins.

3. Local development

Give each developer's laptop its own read-only identity for dev/, so nobody holds production's values. Delete one when someone leaves, and that laptop's logins stop at once.

More use cases

Secrets in CI

Give each pipeline an identity that reads one folder for an hour, mask values in logs, and fail the build on a leak.

Hand a secret to someone once

A contractor or a vendor needs one API key. Send a link that opens once, not a message that stays forever.

Undo a bad change

A script overwrote production's secrets. See what changed and put the folder back as it was at 09:00.

Move your first app's secrets in an afternoon.

Free for up to 100 secrets and 2 machine identities. Every teammate is free on every plan.