This package is a Varlock plugin that enables loading secrets from KeePass / KeePassXC databases (KDBX 4.0) into your configuration.
- KDBX 4.0 support — reads KeePass database files directly via kdbxweb with pure WASM argon2
- KeePassXC CLI integration — use
keepassxc-clifor development workflows - Key file support — authenticate with password + optional key file
- Custom attributes — read any entry field via
#attributesyntax - Bulk loading with
kpBulk()via@setValuesBulkto load all entries in a group - Custom attributes object — load all custom fields from a single entry via
customAttributesObj=true - Multiple instances for accessing different databases
If you are in a JavaScript based project and have a package.json file, you can either install the plugin explicitly:
npm install @varlock/keepass-pluginAnd then register the plugin without any version number:
# @plugin(@varlock/keepass-plugin)
# ---
Otherwise just set the explicit version number when you register it:
# @plugin(@varlock/keepass-plugin@0.0.1)
# ---
See our Plugin Guide for more details.
In file mode, the plugin opens and reads .kdbx files directly using kdbxweb. No external CLI is needed.
# @plugin(@varlock/keepass-plugin)
# @initKeePass(dbPath="./secrets.kdbx", password=$KP_PASSWORD)
# ---
When useCli=true, the plugin uses keepassxc-cli to read entries. This is useful during development when you want to leverage KeePassXC's system integration (e.g., YubiKey, Windows Hello). The useCli option can be dynamic — for example, useCli=forEnv(dev) to only use the CLI in development.
# @plugin(@varlock/keepass-plugin)
# @initKeePass(dbPath="./secrets.kdbx", password=$KP_PASSWORD, useCli=true)
# ---
You must have KeePassXC installed, which includes keepassxc-cli:
# macOS
brew install --cask keepassxc
# Ubuntu/Debian
sudo apt install keepassxc
# Fedora/RHEL
sudo dnf install keepassxc
# Arch
pacman -S keepassxcSee KeePassXC downloads for more options.
After registering the plugin, initialize it with the @initKeePass root decorator.
# @plugin(@varlock/keepass-plugin)
# @initKeePass(dbPath="./secrets.kdbx", password=$KP_PASSWORD)
# ---
# @type=kdbxPassword @sensitive
KP_PASSWORD=
# @plugin(@varlock/keepass-plugin)
# @initKeePass(dbPath="./secrets.kdbx", password=$KP_PASSWORD, keyFile="./secrets.keyx")
# ---
# @plugin(@varlock/keepass-plugin)
# @initKeePass(id=prod, dbPath="./prod.kdbx", password=$KP_PROD_PASSWORD)
# @initKeePass(id=dev, dbPath="./dev.kdbx", password=$KP_DEV_PASSWORD)
# ---
PROD_DB_PASS=kp(prod, "Database/production")
DEV_DB_PASS=kp(dev, "Database/development")
Once initialized, use the kp() resolver to fetch secrets.
# Fetch password (default attribute) from an entry
DB_PASSWORD=kp("Database/production")
# Fetch a different attribute using #attribute syntax
DB_USER=kp("Database/production#UserName")
DB_URL=kp("Database/production#URL")
# Read a custom string field
API_KEY=kp("Services/stripe#SecretKey")
When the env var key matches a KeePass entry title, you can omit the entry path:
# Looks up entry titled "DB_PASSWORD", reads the Password field
DB_PASSWORD=kp()
# Looks up entry titled "DB_USER", reads the UserName field
DB_USER=kp("#UserName")
You can also use the attribute named param as an alternative to #attribute:
DB_USER=kp("Database/production", attribute=UserName)
Entry paths use forward slashes to separate groups from the entry title:
Group/SubGroup/EntryTitle
For example, if your KeePass database has:
- Root
- Database
- production (entry with Password, UserName fields)
- Services
- stripe (entry with a custom "SecretKey" field)
- Database
You would reference them as "Database/production" and "Services/stripe".
Use customAttributesObj=true to load all custom (non-standard) fields from a single entry as a JSON object. This is useful with @setValuesBulk to expand custom fields into env vars:
# Given an entry "Database/production" with custom fields: HOST, PORT, DB_NAME
# @setValuesBulk(kp("Database/production", customAttributesObj=true), createMissing=true)
# ---
HOST=
PORT=
DB_NAME=
Standard fields (Title, Password, UserName, URL, Notes) are excluded — only custom fields are included.
Use kpBulk() with @setValuesBulk to fetch the Password field from all entries under a group:
# @plugin(@varlock/keepass-plugin)
# @initKeePass(dbPath="./secrets.kdbx", password=$KP_PASSWORD)
# @setValuesBulk(kpBulk(Production), createMissing=true)
# ---
# These will be populated from entries under the "Production" group
DB_PASSWORD=
API_KEY=
# Load all entries from the database root
# @setValuesBulk(kpBulk())
# Load from a specific group
# @setValuesBulk(kpBulk("Services/APIs"))
# With a named instance
# @setValuesBulk(kpBulk(prod, Production))
Entry paths in the JSON output are sanitized to valid env var names (uppercased, non-alphanumeric characters replaced with underscores).
Initialize a KeePass plugin instance.
| Parameter | Type | Required | Description |
|---|---|---|---|
dbPath |
string | yes | Path to the .kdbx database file |
password |
string | yes | Master password (typically from an env var like $KP_PASSWORD) |
keyFile |
string | no | Path to a key file for additional authentication |
useCli |
boolean | no | Use keepassxc-cli instead of reading the file directly (default: false). Can be dynamic, e.g. useCli=forEnv(dev) |
id |
string | no | Instance identifier for multiple databases (defaults to _default) |
A sensitive string type for KeePass database master passwords. Validates that the value is a non-empty string.
Fetch a single entry field from a KeePass database.
Signatures:
kp()— infer entry name from key, read Password fieldkp(entryPath)— read Password fieldkp("entryPath#Attribute")— read a specific attributekp("#Attribute")— infer entry name from key, read a specific attributekp(entryPath, attribute=X)— read a specific attribute (named param)kp(instanceId, entryPath)— read from a named database instancekp(entryPath, customAttributesObj=true)— return all custom fields as a JSON object
Returns: The field value as a string, or a JSON object string when customAttributesObj=true.
Fetch the Password field from all entries under a group as a JSON map. Intended for use with @setValuesBulk.
Signatures:
kpBulk()— load all entries from the database rootkpBulk(groupPath)— load entries under a specific groupkpBulk(instanceId, groupPath)— load from a named instance
Returns: JSON string of { "ENTRY_NAME": "password", ... } pairs. Entry paths are sanitized to valid env var names.
- Check that the database password is correct
- If using a key file, verify the path is correct and the file matches the database
- Entry paths are case-sensitive
- Use forward slashes to separate groups:
"Group/SubGroup/Entry" - In CLI mode, list entries with:
keepassxc-cli ls <database.kdbx>
- Install KeePassXC which includes the CLI (see Prerequisites)
- Ensure
keepassxc-cliis in yourPATH
- Check the
dbPathvalue — it's resolved relative to the working directory - Use an absolute path if needed
- KeePassXC — cross-platform KeePass-compatible password manager
- KeePass — original KeePass Password Safe
- KDBX format — KeePass database format specification
- kdbxweb — JavaScript KDBX reader library