Skip to content

Commit e184705

Browse files
authored
Fix blocking publish route (#338)
* Fix blocking publish route * Added common routes * Default to open - which was the previous functionality * Update spacetimedb-standalone.md * Update spacetimedb-standalone.md * Updated with support for the typescript SDK * Updated with known good subscribe route * Updated doc text * Clarified comment * nit
1 parent 5c85e76 commit e184705

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

docs/deploying/spacetimedb-standalone.md

+47-7
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,69 @@ server {
8282
listen 80;
8383
server_name example.com;
8484
85-
location / {
85+
#########################################
86+
# By default SpacetimeDB is completely open so that anyone can publish to it. If you want to block
87+
# users from creating new databases you should keep this section commented out. Otherwise, if you
88+
# want to open it up (probably for dev environments) then you can uncomment this section and then
89+
# also comment out the location / section below.
90+
#########################################
91+
# location / {
92+
# proxy_pass http://localhost:3000;
93+
# proxy_http_version 1.1;
94+
# proxy_set_header Upgrade $http_upgrade;
95+
# proxy_set_header Connection "Upgrade";
96+
# proxy_set_header Host $host;
97+
# }
98+
99+
# Anyone can subscribe to any database.
100+
# Note: This is the only section *required* for the websocket to function properly. Clients will
101+
# be able to create identities, call reducers, and subscribe to tables through this websocket.
102+
location ~ ^/v1/database/[^/]+/subscribe$ {
86103
proxy_pass http://localhost:3000;
87104
proxy_http_version 1.1;
88105
proxy_set_header Upgrade $http_upgrade;
89106
proxy_set_header Connection "Upgrade";
90107
proxy_set_header Host $host;
91108
}
92109
93-
# This restricts who can publish new databases to your SpacetimeDB instance. We recommend
94-
# restricting this ability to local connections.
95-
location /v1/publish {
96-
allow 127.0.0.1;
97-
deny all;
110+
# Uncomment this section to allow all HTTP reducer calls
111+
# location ~ ^/v1/[^/]+/call/[^/]+$ {
112+
# proxy_pass http://localhost:3000;
113+
# proxy_http_version 1.1;
114+
# proxy_set_header Upgrade $http_upgrade;
115+
# proxy_set_header Connection "Upgrade";
116+
# proxy_set_header Host $host;
117+
# }
118+
119+
# Uncomment this section to allow all HTTP sql requests
120+
# location ~ ^/v1/[^/]+/sql$ {
121+
# proxy_pass http://localhost:3000;
122+
# proxy_http_version 1.1;
123+
# proxy_set_header Upgrade $http_upgrade;
124+
# proxy_set_header Connection "Upgrade";
125+
# proxy_set_header Host $host;
126+
# }
127+
128+
# NOTE: This is required for the typescript sdk to function, it is optional
129+
# for the rust and the C# SDKs.
130+
location /v1/identity {
98131
proxy_pass http://localhost:3000;
99132
proxy_http_version 1.1;
100133
proxy_set_header Upgrade $http_upgrade;
101134
proxy_set_header Connection "Upgrade";
102135
proxy_set_header Host $host;
103136
}
137+
138+
# Block all other routes explicitly. Only localhost can use these routes. If you want to open your
139+
# server up so that anyone can publish to it you should comment this section out.
140+
location / {
141+
allow 127.0.0.1;
142+
deny all;
143+
}
104144
}
105145
```
106146

107-
This configuration contains a restriction to the `/v1/publish` route. This restriction makes it so that you can only publish to the database if you're publishing from a local connection on the host.
147+
This configuration by default blocks all connections other than `/v1/identity` and `/v1/database/<database-name>/subscribe` which only allows the most basic functionality. This will prevent all remote users from publishing to your SpacetimeDB instance.
108148

109149
Enable the configuration:
110150

0 commit comments

Comments
 (0)