Set passwords: plain, env or bxsecret
On this page
Set passwords: plain, environment variable or bxsecret
The console needs a password. The SMTP and AI settings take secrets too. There are three ways to give BxLens a secret. All three go in boxlang.json, under modules.bxLens.settings.
| How | Effort | Verdict | |
|---|---|---|---|
| 1. Plain | "password": "my-password" | Easiest | A bad idea. The secret sits in a file you may commit or back up. Fine for a throwaway demo. |
| 2. Environment variable | "password": "${env.BXLENS_PASSWORD}" | Easy | Great. Nothing secret in the file, and every container platform and CI knows how to set one. |
3. bxsecret: | "password": "bxsecret:AbCdEf123...==" | More steps | Good. Encrypted in the file, but you must look after the seed. |
You can also combine 2 and 3: an environment variable can hold a bxsecret: value (see below).
1. Plain
{ "modules": { "bxLens": { "settings": { "console": { "password": "my-password" } } } } }
It works, and it is the quickest way to try the console. Do not use it on a server people can reach, and never commit it.
2. Environment variable
BoxLang replaces ${...} placeholders in boxlang.json when it loads the file, module settings included. Set the variable on the server, then name it in the file:
{
"modules": {
"bxLens": {
"settings": {
"console": {
"password": "${env.BXLENS_PASSWORD}",
"viewerPassword": "${env.BXLENS_VIEWER_PASSWORD}"
}
}
}
}
}
export BXLENS_PASSWORD="a long random password"
- The
env.prefix is optional since BoxLang 1.17:${BXLENS_PASSWORD}works too. If a Java system property has the same name, the property wins. - The variable is read at startup. Restart the runtime after you change it.
- Check that the variable is set. BoxLang leaves a placeholder it cannot resolve as plain text, so with
BXLENS_PASSWORDmissing the password becomes the literal text${env.BXLENS_PASSWORD}. Anyone who guesses the variable name can sign in. Test the sign in after a deploy, and leave outviewerPasswordentirely if you do not use the viewer role. - A default goes after a colon,
${env.NAME:default}, and needs at least one character. Do not use a default for a password.
This is a BoxLang feature, so it works for any setting, see the BoxLang configuration docs. Some BxLens settings also have their own variable setting: ai.apiKeyEnv, the SMTP password in Settings, Notifications, and registration.keyEnv. They take the variable name, not a placeholder.
3. bxsecret
A bxsecret: value is encrypted with the runtime's secret seed. BoxLang decrypts it when it loads the configuration (BoxLang 1.17 or newer). Make one with:
boxlang generatesecret "a long random password"
# bxsecret:AbCdEf123...==
Copy the whole output, prefix included, into the setting. Make a different value for each password.
{
"modules": {
"bxLens": {
"settings": {
"console": {
"password": "bxsecret:AbCdEf123...==",
"viewerPassword": "bxsecret:GhIjKl456...=="
}
}
}
}
}
The command is the one BoxLang uses for any secret, see boxlang generatesecret in the BoxLang docs.
An environment variable can hold the bxsecret: value, and the placeholder decrypts it: set BXLENS_PASSWORD to the bxsecret: text and keep "password": "${env.BXLENS_PASSWORD}" in the file. That keeps the file free of both the secret and the ciphertext.
4. Set it in the console
An admin can also set the admin and the viewer password in the console (Settings, Security). The password is kept as a salted slow hash in the Secret Store, and it wins over boxlang.json. The order is: set in the console, then boxlang.json, then nothing (the setup page).
- Use it when you do not want to edit a file to rotate a password. The hash is not reversible and never leaves the server.
- Reset to boxlang.json removes the console's password, so the value of
boxlang.jsonis in charge again. It is also how you recover when nobody knows the console's password: see lockout recovery. - The viewer login can be removed even where
boxlang.jsonholds a viewer password. - Changing the admin password needs the current one and ends the other sessions of that role.
Write only secrets
The AI key and the SMTP password can also be pasted into the console (Settings, Assistant, Notifications or Security, Secrets). The field is write only: the value goes to the server, is sealed in the Secret Store and never comes back to the page, an API, Lensy, a log, the audit log or the diagnostic bundle. The page shows set in console, set in boxlang.json or env NAME, with Replace and Clear. Clearing removes only the console's value, so boxlang.json or the variable is in charge again. No second password is asked for: a signed in admin is enough. The setting is refused when console.readOnly is on, needs BoxLang+ (the AI and Notifications features) and is audited as secret.change with the name only.
Which settings take a secret
| Setting | What it is | Notes |
|---|---|---|
console.password | The admin password | Required, unless one was set in the console (which wins over this one). Without any the console shows the "Set a password first" page (HTTP 503), with a tab for each of the three ways below, and refuses every other route. Plain, ${env.NAME} or bxsecret:. |
console.viewerPassword | The viewer password | Optional. A second password for the read only role. |
notifications.smtp.password | The SMTP password for alerts and reports | A password set in the console wins (write only, Settings, Notifications or Security). Then boxlang.json, then the environment variable named in Settings, Notifications. |
ai.apiKey | The API key of a hosted model | A key set in the console wins (write only, Settings, Assistant or Security). Then ai.apiKey in boxlang.json, then the variable named by ai.apiKeyEnv. Leave it empty for a local model. |
The console never shows these values. The Settings page shows only set or not set.
The seed (bxsecret only)
A bxsecret: value is encrypted with the secret seed of the runtime that made it. Each BoxLang installation creates its own seed in {boxlang-home}/config/.seed. A value only decrypts with the seed it was made with.
This matters in three cases:
- Several servers share one config. Give them all the same seed, or each server will fail to decrypt the password and show the setup page. Copy the same
.seedfile to each server, or setBOXLANG_SECURITY_SECRETSEEDon each one. - A container or a new machine. The seed is created again, so values made elsewhere stop working. Pin it with the environment variable.
- A lost seed. The values cannot be recovered. Make them again.
export BOXLANG_SECURITY_SECRETSEED=my-shared-seed-value
boxlang generatesecret "a long random password"
You can also set security.secretSeed in boxlang.json, but that keeps the seed in plain text next to the values it protects. Prefer the environment variable or the .seed file.
Do not commit the .seed file or a plain text password.
Secrets BxLens keeps for itself
The three ways above are for the values you put in boxlang.json. Secrets that BxLens saves on its own (the passwords set in the console today, other features later) go in the free Secret Store: AES-256-GCM, one key file beside the data, or the key in the environment variable BXLENS_SECRETS_KEY to keep it off the volume. A lost key means entering those secrets again.
When it does not work
- The console shows the setup page, and the log says
console.password is empty or cannot be decrypted. The value was made with another seed, was copied without its prefix or was cut. Make it again on a runtime that uses the server's seed. See Troubleshooting. - A password with special characters on the command line. Quote it, and use single quotes in a shell where
$or!would expand.
See also Running Lens in production and Security.