@@ -42,21 +42,33 @@ client_secret = "notes-staging-client-secret"
4242cookie_key = " notes-staging-cookie-key"
4343```
4444
45- ## Store the client secret
45+ ## Store the secrets
4646
4747piqueld gives a service each secret as a file under ` /run/secrets ` , never as an
48- environment variable.
48+ environment variable. Each environment needs two: its app's client secret, and
49+ the key that seals the SDKs' session cookies.
4950
50- 1 . Store each environment's secret, mountable by that environment only. Paste
51- the secret when ` piquelctl ` asks for it:
51+ 1 . Store each environment's client secret, mountable by that environment only.
52+ Paste the secret when ` piquelctl ` asks for it:
5253
5354 ``` console
5455 piquelctl app secret notes set notes-client-secret --stdin --environments production --no-previews
5556 piquelctl app secret notes set notes-staging-client-secret --stdin --environments staging --no-previews
5657 ```
5758
58- 2 . Mount the secret the environment's ` client_secret ` variable names in ` web ` ,
59- at the same path in every environment, with the rest of the app's settings:
59+ 2 . Store each environment's cookie key the same way. The cookie key seals a
60+ whole session, tokens included, so an environment that could read another's
61+ key could forge its sessions: never share one. The SDKs read standard base64,
62+ which piqueld's generated secrets don't use, so generate each with ` openssl ` :
63+
64+ ``` console
65+ openssl rand -base64 32 | piquelctl app secret notes set notes-cookie-key --stdin --environments production --no-previews --yes
66+ openssl rand -base64 32 | piquelctl app secret notes set notes-staging-cookie-key --stdin --environments staging --no-previews --yes
67+ ```
68+
69+ 3 . Mount the secrets the environment's ` client_secret ` and ` cookie_key `
70+ variables name in ` web ` , at the same paths in every environment, with the
71+ rest of the app's settings:
6072
6173 ``` toml
6274 [[spec .services ]]
@@ -75,31 +87,31 @@ environment variable.
7587 target = " /run/secrets/piquel-cookie-key"
7688 ```
7789
78- 3 . Read the secret from the file in your app. In Rust:
90+ 4 . Read the secrets from their files in your app. In Rust:
7991
8092 ``` rust
8193 let secret = std :: fs :: read_to_string (" /run/secrets/piquel-client-secret" )? ;
8294 let credentials = Credentials :: Secret (secret . trim (). to_owned (). into ());
8395 ```
8496
8597 In TypeScript, pass `readFileSync('/run/secrets/piquel-client-secret',
86- 'utf8').trim()` as the client's ` clientSecret`.
98+ 'utf8').trim()` as the client's ` clientSecret`. Read the cookie key from
99+ ` /run/secrets/piquel-cookie-key ` the same way.
87100
88- 4 . Deploy each environment:
101+ 5 . Save the manifest. If the application deploys from a repository, commit and
102+ push it to the branch each environment deploys from. Otherwise, save it:
103+
104+ ``` console
105+ piquelctl app apply --file piqueld.toml
106+ ```
107+
108+ 6 . Deploy each environment:
89109
90110 ``` console
91111 piquelctl env deploy notes staging
92112 piquelctl env deploy notes production
93113 ```
94114
95- Store the key that seals the SDKs' session cookies the same way: one per
96- environment, mountable by that environment only, named by its ` cookie_key `
97- variable. The cookie key seals a whole session, tokens included, so an
98- environment that could read another's key could forge its sessions. Generate
99- each with ` openssl rand -base64 32 ` : the SDKs read standard base64, which
100- piqueld's generated secrets don't use. Step 2 mounts it at
101- ` /run/secrets/piquel-cookie-key ` : read it the same way as the client secret.
102-
103115## Rotate the secret
104116
1051171 . [ Rotate the secret] ( rotate-secrets.md ) in the console, with a grace period
0 commit comments