Skip to content

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.

  1. Write a reference in the env of a service. The form is ${secret:path}. The path is a name that you select, for example stripe/key.

    localspace.yaml
    services:
    orders:
    repo: orders-api
    port: 8080
    env:
    STRIPE_KEY: ${secret:stripe/key}
  2. Store the value. lo secret set reads the value from standard input:

    Terminal window
    printf '%s' "sk_test_123" | lo secret set stripe/key

    Use lo secret set stripe/key < key.txt to read the value from a file. localspace removes one trailing newline from the value.

  3. Start the workspace:

    Terminal window
    lo up shop-a

    The 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.

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.

Terminal window
lo secret ls

The 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 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 mode 0600. Only your user can read them.
  • lo doctor tells you if the secrets directory has a different mode. Run chmod 700 on it to correct this.
  • The files are not encrypted. Do not copy the directory to a place that other users can read.

localspace masks a secret in its output. A variable is secret if its value in the template holds a ${secret:...} reference.

Terminal window
lo env shop-a orders

The command shows STRIPE_KEY=********. To show the real values, add --reveal:

Terminal window
lo env shop-a orders --reveal

The 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.

The secrets: machine setting gives the name of the store. The default is file.

~/.localspace/config.yaml
secrets: env

A 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.