carlos / carloku Public

Clone
git clone https://amadan.net/carlos/carloku

Plain git — no account needed to clone.

Download

Download this file

1# Env and secrets
2
3Your app's configuration lives in two stores. Both arrive at your process
4as ordinary environment variables, and from inside the app you cannot
5tell them apart. The difference is what happens to the value on the way
6there, and it is worth getting right the first time.
7
8Plain config goes in `carlos env`:
9
10```sh
11carlos env set -app hello LOG_LEVEL=debug
12```
13
14Credentials go in `carlos secrets`. Same shape:
15
16```sh
17carlos secrets set -app hello STRIPE_KEY=sk_live_example
18```
19
20## Which store a value belongs in
21
22Ask whether you would mind the value appearing in a screenshot. A log
23level, a feature flag, the public URL of a service you call — nobody
24cares, and `carlos env` keeps them readable, which is what you want when
25you are working out why staging behaves oddly.
26
27An API key, a database URL with a password in it, a signing secret,
28anything a third party issued you: `carlos secrets`. If in doubt, the
29sealed store costs you nothing except the ability to read the value back,
30so put it there.
31
32## What sealing actually does
33
34`carlos secrets set` seals the value on your machine, using the
35deployment's public key, before anything leaves your terminal. What gets
36stored is an envelope. The private half of that key lives on the box that
37runs your app and never leaves it, so the console holds a secret it
38cannot itself open.
39
40The consequence is the one thing people trip over: nothing can show you
41the value again. `carlos secrets list` prints key names and stops there.
42Lose the value and your only move is setting a new one.
43
44One practical wrinkle. The value is on your command line when you type
45it, so your shell history keeps a copy of it. Clear that out on a machine
46other people use.
47
48## Getting the new value into your app
49
50Changing config converges on its own. The write bumps a marker, every box
51serving the app notices within seconds, rewrites the environment file for
52each of the app's routes, and cycles the process so it comes back holding
53the new value. There is no separate deploy, and no restart for you to
54remember.
55
56Two things follow from the cycling. A config change is a small
57interruption for a running app, so batch related changes into one call —
58`carlos env set` takes several `KEY=value` pairs at once. And a change
59that appears not to have taken effect is more likely to be your app
60reading the variable once at startup than the platform failing to deliver
61it.
62
63To see what is set:
64
65```sh
66carlos env list -app hello
67```
68
69That prints values as well as names, and the sealed store's `list` prints
70names alone. Both families also take `unset` with a key name, and the
71reference pages for
72[carlos env](https://carlosframework.com/docs/cli/#carlos-env) and
73[carlos secrets](https://carlosframework.com/docs/cli/#carlos-secrets)
74have their remaining sub-verbs.
75
76If you take one thing from this page: put the credential in the sealed
77store on the day you first set it. Moving it later means rotating it,
78because by then it has been sitting somewhere readable.
79