Store secrets
A template is a file that you can share and commit. A secret, such as an API key, must not be in it. The template holds a reference to the secret, and not the secret. localspace reads the value from a secret store when it starts the service.
Use a secret in a template
Section titled “Use a secret in a template”-
Write a reference in the
envof a service. The form is${secret:path}. The path is a name that you select, for examplestripe/key.localspace.yaml services:orders:repo: orders-apiport: 8080env:STRIPE_KEY: ${secret:stripe/key} -
Store the value.
lo secret setreads the value from standard input:Terminal window printf '%s' "sk_test_123" | lo secret set stripe/keyUse
lo secret set stripe/key < key.txtto read the value from a file. localspace removes one trailing newline from the value. -
Start the workspace:
Terminal window lo up shop-aThe service gets the real value in
STRIPE_KEY.
A path must be relative, such as stripe/key. It cannot start with /, and it cannot go out of the store with ... A value cannot be empty.
If a secret is not in the store, lo up fails with the error not_found. The message tells you the lo secret set command to run.
Store and list secrets
Section titled “Store and list secrets”lo secret set <path> stores a value. If the path has a value, the command replaces it.
lo secret ls lists the paths that are stored. It does not show a value.
lo secret lsThe dashboard has the same operations on the Secrets page. It lists the paths. You type a path and a value, and the dashboard sends the value one time to lo ui serve. It does not show the value again.
The file store
Section titled “The file store”The default store is a directory of files. Each secret is one file in the secrets directory of the localspace home, for example ~/.localspace/secrets/stripe/key. The path of the secret is the path of the file.
- localspace makes the directories with the mode
0700, and the files with the mode0600. Only your user can read them. lo doctortells you if thesecretsdirectory has a different mode. Runchmod 700on it to correct this.- The files are not encrypted. Do not copy the directory to a place that other users can read.
Masked values
Section titled “Masked values”localspace masks a secret in its output. A variable is secret if its value in the template holds a ${secret:...} reference.
lo env shop-a ordersThe command shows STRIPE_KEY=********. To show the real values, add --reveal:
lo env shop-a orders --revealThe env tool of the MCP server always masks secret values. The dashboard masks them until you select Reveal secrets.
The masking applies to the output of localspace. The service itself gets the real value in its environment.
Use a different secret store
Section titled “Use a different secret store”The secrets: machine setting gives the name of the store. The default is file.
secrets: envA plugin can add a store. For example, the example plugin envsecret in the sdk module reads the values from environment variables. Install the plugin, then set secrets: to the name of its store. See Write a plugin.
A store of a plugin can be read-only. Then lo secret set fails. The commands lo secret set and lo secret ls, and each ${secret:path} reference, use the store that secrets: gives. localspace does not read the file store when you select a different store.
Related
Section titled “Related”- Write a template shows the other references in
env. - References gives each
${...}form. lo secret set,lo secret lsandlo envgive all the flags.- Machine settings gives the
secrets:setting.