Skip to content

Secret references ​

A secret's value can use another secret from the same environment. Write ${KEY} and Dopbase fills it in when an app gets its secrets:

dotenv
DB_USER=app
DB_PASS=s3cret
DB_URL=pgsql://${DB_USER}:${DB_PASS}@db.internal:5432/billing

dopbase run gives the app DB_URL=pgsql://app:s3cret@db.internal:5432/billing. Change DB_PASS and the next run gets the new password in DB_URL too, with no edit to DB_URL.

Turn it on ​

References are off until the server starts with them on:

bash
DOPBASE_SECRET_REFERENCES=true dopbase server start

Or put secret_references = true in server.toml. While they are off, every value goes out exactly as written, ${...} included. See optional features.

Turning them on changes what an app gets for any value that already contains ${NAME} where NAME is a secret in the same environment. A value such as tar -czf ${HOME}/backup.tgz is unaffected as long as no secret is named HOME.

How a reference is written ​

There is one way to write a reference, and it has to be typed exactly:

WrittenWhat the app gets
${DB_PASS}The value of DB_PASS
${PORT:-5432}The value of PORT, or 5432 when PORT is missing or empty
${HOME}${HOME} as text, when no secret is named HOME
${db_pass}Text. Names match exactly, upper and lower case included
${ DB_PASS }Text. No spaces inside the braces
$DB_PASSText. The braces are required
${shared.DB_URL}Text. A reference names a secret in the same environment only

The fallback after :- is plain text up to the first }.

There is no escape syntax. If you want an app to get the literal text ${NAME}, don't create a secret named NAME in that environment.

What else to know ​

  • A name that matches no secret stays as text. If you add a secret with that name later, the reference starts resolving on the next fetch, with no edit.
  • Nothing is checked or blocked when you save, import, copy, roll back or delete a secret. Deleting DB_PASS is allowed, and DB_URL then delivers ${DB_PASS} as text until you fix it.
  • A secret can name a secret that has references of its own. The chain is followed to the end.
  • Secrets that refer to each other in a loop, and any reference into such a loop, stay as written. A secret that names itself is a loop too. With Show references on, the web app names the secrets in the loop.
  • File secrets are never read for references and can't be named. ${TLS_CERT} stays as text, and ${TLS_CERT:-none} gives none.
  • Text that a reference brings in is not scanned again.
  • A secret whose final value would be larger than 64 KiB goes out as written. If the whole environment would be larger than 2 MiB, every value in it goes out as written for that fetch, so dopbase run never fails on size.

Where values are filled in ​

WhereWhat you get
dopbase run, runner tokens, the runtime APIFinal values
dopbase export, Export in the web appFinal values
dopbase export --raw, Keep referencesValues as stored, with ${KEY} left in place
Reveal in the web appValues as stored, or final values with Show references on
dopbase secret get, historyValues as stored
The .env editor, dopbase environment editValues as stored

Use --raw when you move secrets to another environment or keep a backup, so the references come along.

In the web app ​

While references are on, the Value box in Add secret and Edit value, and the .env editor, help you write them:

  • Type ${ and the keys of this environment are listed. Arrow keys and Enter pick one, Escape closes the list.
  • References that will be filled in are coloured. A ${NAME} that matches no secret stays plain.
  • A name that matches no secret gets a note, with the closest key when there is one. Saving is never blocked, because the name may be meant for a shell.
  • The hint under Value shows the fallback form, ${PORT:-5432}.

A revealed value shows as stored, with its references coloured. When it has a reference, turn on Show references to see the value apps get. That is a second reveal, so it may ask for your password and the audit log records it. Copy copies whichever one is on screen. A reference that nothing fills in stays as written, and a line under the value says so.

{KEY} with --mount is something else ​

dopbase run --mount replaces {KEY}, without a $, in the command's arguments with the path of a mounted file. That happens on your machine, in the command line. ${KEY} in a value is a secret reference, filled in on the server. See give a command a file.

Open-source secrets management for developers.