Skip to content

Commit b5124d4

Browse files
authored
docs: Document secure and insecure modes (#2405)
Docs update for #2404 I think we should also extend other parts of the documentation to explain that this secret must be passed when making shape requests. Otherwise, people will follow the docs but it won't work. So either the docs show usage in INSECURE mode which doesn't seem ideal, or we add the secret where needed. But i'm a bit afraid of polluting code snippets/docs with a secret. Open for suggestions on the best way to communicate this in the docs.
1 parent 0a8195f commit b5124d4

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

website/docs/api/config.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,34 @@ Suffix for the logical replication publication and slot name.
105105

106106
## Electric
107107

108+
### ELECTRIC_SECRET
109+
110+
<EnvVarConfig
111+
name="ELECTRIC_SECRET"
112+
required={true}
113+
example="1U6ItbhoQb4kGUU5wXBLbxvNf">
114+
115+
Secret for shape requests to the [HTTP API](/docs/api/http). This is required unless `ELECTRIC_INSECURE` is set to `true`.
116+
By default, the Electric API is public and authorises all shape requests against this secret.
117+
More details are available in the [security guide](/docs/guides/security).
118+
119+
</EnvVarConfig>
120+
121+
### ELECTRIC_INSECURE
122+
123+
<EnvVarConfig
124+
name="ELECTRIC_INSECURE"
125+
defaultValue="false"
126+
example="true">
127+
128+
When set to `true`, runs Electric in insecure mode and does not require an `ELECTRIC_SECRET`.
129+
Use with caution.
130+
API requests are unprotected and may risk exposing your database.
131+
Good for development environments.
132+
If used in production, make sure to [lock down access](/docs/guides/security#network-security) to Electric.
133+
134+
</EnvVarConfig>
135+
108136
### ELECTRIC_INSTANCE_ID
109137

110138
<EnvVarConfig
@@ -135,7 +163,7 @@ Name of the electric service. Used as a resource identifier and namespace.
135163
example="true">
136164

137165
Expose some unsafe operations that faciliate integration testing.
138-
Do not enable this production.
166+
Do not enable this in production.
139167

140168
</EnvVarConfig>
141169

website/docs/guides/security.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Electric is a [sync service](/product/electric) that runs in front of Postgres.
3535
</a>
3636
</figure>
3737

38-
This API is [public by default](#public-by-default). It should be secured in production using [network security](#network-security) and/or an [authorization proxy](#authorization).
38+
This API is [public by default](#public-by-default). It should be secured in production using an [API token](#api-token), [network security](#network-security) and/or an [authorization proxy](#authorization).
3939

4040
### Public by default
4141

@@ -62,6 +62,12 @@ Electric is designed to run behind an [authorizing proxy](/docs/guides/auth#requ
6262

6363
This is the primary method for securing data access to clients and apps and is documented in detail, with examples, in the [Auth guide](/docs/guides/auth).
6464

65+
### API token
66+
67+
Access to Electric can be secured with an [API token](/docs/api/config#electric-secret). This is a secret string that can be set when starting Electric and will be used to authenticate requests to the Electric HTTP API. When an API token is set, Electric will require all requests to include the API token.
68+
69+
The token should *not* be sent from the client as it will be exposed in the HTTP requests. Instead, it should be added by the [authorizing proxy](/docs/guides/auth#requests-can-be-proxied) when proxying requests to Electric.
70+
6571
## Encryption
6672

6773
Electric syncs ciphertext as well as it syncs plaintext. You can encrypt and decrypt data in HTTP middleware or in the local client.

website/public/docker-compose.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ services:
2323
image: electricsql/electric
2424
environment:
2525
DATABASE_URL: postgresql://postgres:password@postgres:5432/electric?sslmode=disable
26+
# Not suitable for production. Only use insecure mode in development or if you've otherwise secured the Electric API.
27+
# See https://electric-sql.com/docs/guides/security
28+
ELECTRIC_INSECURE: true
2629
ports:
2730
- "3000:3000"
2831
depends_on:

0 commit comments

Comments
 (0)