Skip to content

Commit 8e7edc4

Browse files
committed
Refresh documentation for securing MongoDB, make internal documentation links consistent (and fix some incorrect paths)
1 parent d4445a3 commit 8e7edc4

File tree

5 files changed

+95
-118
lines changed

5 files changed

+95
-118
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
Refacto makes it easy to run team retros with remote team members. You can use
44
the official public deployment at <https://retro.davidje13.com/>, or
5-
[host your own instance](docs/DEPLOYING.md).
5+
[host your own instance](./docs/DEPLOYING.md).
66

7-
![Refacto](docs/screenshot.png)
7+
![Refacto](./docs/screenshot.png)
88

99
## Running Locally
1010

@@ -17,20 +17,20 @@ npm start
1717
The site will be available at <http://localhost:5000/>, using a mock Google
1818
authentication server and an in-memory database.
1919

20-
See [CONTRIBUTING.md](docs/CONTRIBUTING.md) for full guidance on local
20+
See [CONTRIBUTING.md](./docs/CONTRIBUTING.md) for full guidance on local
2121
development.
2222

2323
## Self-Hosting
2424

25-
See the [deploying documentation](docs/DEPLOYING.md) for details on hosting your
26-
own instance of Refacto.
25+
See [DEPLOYING.md](./docs/DEPLOYING.md) for details on hosting your own instance
26+
of Refacto.
2727

2828
## Services
2929

30-
See the [services documentation](docs/SERVICES.md) for details on setting up a
31-
database and integrating with authentication providers.
30+
See [SERVICES.md](./docs/SERVICES.md) for details on setting up a database and
31+
integrating with authentication providers.
3232

3333
## Extra Security
3434

35-
See the [security documentation](docs/SECURITY.md) for details on configuring
36-
additional security for deployments.
35+
See [SECURITY.md](./docs/SECURITY.md) for details on configuring additional
36+
security for deployments.

docs/CONTRIBUTING.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ changed.
1919

2020
By default, this will run a mock Google authentication provider and an in-memory
2121
database. To enable real authentication providers (e.g. Google sign in) and data
22-
persistence, see the [services documentation](./SERVICES.md). Note that all
23-
backend state (e.g. created retros) is lost when the backend rebuilds if you are
24-
using the default in-memory database.
22+
persistence, see [SERVICES.md](./SERVICES.md). Note that all backend state (e.g.
23+
created retros) is lost when the backend rebuilds if you are using the default
24+
in-memory database.
2525

2626
## Running tests
2727

@@ -106,11 +106,11 @@ This client ID is configured for use on `localhost` on ports 80, 443, 8080,
106106
8443, and 5000. The client secret is not required, as Refacto does not access
107107
any personal data.
108108

109-
See the [services documentation](./SERVICES.md) for details on setting up a
110-
database and integrating with authentication providers.
109+
See [SERVICES.md](./SERVICES.md) for details on setting up a database and
110+
integrating with authentication providers.
111111

112-
See the [security documentation](./SECURITY.md) for additional considerations
113-
when running in production.
112+
See [SECURITY.md](./SECURITY.md) for additional considerations when running in
113+
production.
114114

115115
## Dependency management
116116

docs/DEPLOYING.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ updating to a later version) by adding this to the `docker run` command:
3333
--mount type=volume,src=my-refacto-data,dst=/data
3434
```
3535

36-
Or see [SERVICES.md](docs/SERVICES.md) for details on using an external
37-
database. Note that SQLite databases cannot be shared between multiple proceses
38-
at once.
36+
Or see [SERVICES.md](./SERVICES.md) for details on using an external database.
37+
Note that SQLite databases cannot be shared between multiple proceses at once.
3938

4039
The [releases](https://github.com/davidje13/Refacto/releases) also contain
4140
`Dockerfile`s if you wish to generate your own docker image, or you can
@@ -116,8 +115,7 @@ By default:
116115
- haveibeenpwned integration _is_ enabled;
117116
- the server listens on port `5000`.
118117

119-
See [SERVICES.md](docs/SERVICES.md) and [SECURITY.md](docs/SECURITY.md) for
120-
details.
118+
See [SERVICES.md](./SERVICES.md) and [SECURITY.md](./SECURITY.md) for details.
121119

122120
The full list of recognised configuration options (and their default values) can
123121
be found in [config/default.ts](../backend/src/config/default.ts) (nested
@@ -229,5 +227,5 @@ server {
229227
```
230228

231229
See the
232-
[NGINX upstream documentation](https://nginx.org/en/docs/http/ngx_http_upstream_module.html)
230+
[NGINX upstream module documentation](https://nginx.org/en/docs/http/ngx_http_upstream_module.html)
233231
for more details.

docs/SECURITY.md

Lines changed: 71 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -143,117 +143,95 @@ will invalidate any active sessions, forcing all users to reauthenticate.**
143143

144144
### User authentication (access control)
145145

146-
Before configuring authentication, you should create the database, collections
147-
and indices necessary; the `refacto` user will not have permission to change
148-
these. You can do this by running the application without exposing it to the
149-
internet; after startup the configuration will be complete.
150-
151-
1. Create users:
152-
153-
```
154-
use admin
155-
db.createUser({
156-
user: 'admin',
157-
pwd: '<something secret>',
158-
roles: [
159-
{ role: 'userAdminAnyDatabase', db: 'admin' },
160-
'readWriteAnyDatabase',
161-
],
162-
});
163-
164-
use refacto
165-
db.createUser({
166-
user: 'refacto',
167-
pwd: '<another secret>',
168-
roles: [
169-
{ role: 'readWrite', db: 'refacto' },
170-
],
171-
});
172-
```
173-
174-
2. Enforce authorization:
175-
176-
```sh
177-
echo 'security.authorization: enabled' >> /usr/local/etc/mongod.conf
178-
brew services restart mongodb
179-
```
180-
181-
You can now connect as the `admin` user:
146+
Refacto manages its own database, creating and modifying collections and indices
147+
automatically. For this reason, it is best to configure mongo access with the
148+
`readWrite` and `dbAdmin` roles within the database you want it to use.
182149

183-
```sh
184-
mongo --authenticationDatabase admin -u admin -p
185-
```
150+
These permissions are quite broad, but enabling user authentication is still
151+
beneficial for a number of reasons:
186152

187-
And configure Refacto to connect as the `refacto` user:
153+
- Without authentication, any user on the machine is able to connect to MongoDB
154+
and perform any operation (and if MongoDB is exposed on a network, any machine
155+
which can reach the server can connect and perform any operation);
156+
- Admin-level commands such as managing users and clusters can be restricted;
157+
- Access to other databases hosted in the same MongoDB instance can be
158+
restricted.
188159

189-
```sh
190-
DB_URL="mongodb://refacto:<pass>@localhost:27017/refacto" ./index.js
191-
```
160+
To set up user roles from scratch in a MongoDB deployment:
192161

193-
<https://docs.mongodb.com/manual/tutorial/enable-authentication/>
162+
1. Create an admin user: (this will be used to create the other users)
194163

195-
### Encrypted communication
164+
- Pick a secure password for the admin user, and note it somewhere safe. For
165+
example:
196166

197-
To enable SSL (encrypted) communications, but without server or client identity
198-
checks:
167+
```sh
168+
openssl rand -base64 30 | tr '/+' '_-'
169+
```
199170

200-
```sh
201-
# macOS
202-
MONGO_VAR="/usr/local/var/mongodb"
203-
MONGO_CONF="/usr/local/etc/mongod.conf"
204-
205-
# Ubuntu
206-
MONGO_VAR="/var/mongodb"
207-
MONGO_CONF="/etc/mongod.conf"
208-
209-
openssl req \
210-
-x509 \
211-
-newkey rsa:4096 \
212-
-keyout "$MONGO_VAR/server-key.pem" \
213-
-out "$MONGO_VAR/server-cert.pem" \
214-
-subj "/C=/ST=/L=/O=/OU=/CN=localhost" \
215-
-nodes \
216-
-days 36500 \
217-
-batch
218-
219-
cat \
220-
"$MONGO_VAR/server-key.pem" \
221-
"$MONGO_VAR/server-cert.pem" \
222-
> "$MONGO_VAR/server.pem"
223-
224-
cat <<EOF >> "$MONGO_CONF"
225-
net.ssl:
226-
mode: requireSSL
227-
PEMKeyFile: $MONGO_VAR/server.pem
228-
EOF
229-
230-
# macOS
231-
brew services restart mongodb
232-
233-
# Ubuntu
234-
sudo service mongod restart
235-
```
171+
- Create the user:
172+
173+
```sh
174+
mongosh admin --eval 'db.createUser({user:"my-admin-user",pwd:passwordPrompt(),roles:["root"],mechanisms:["SCRAM-SHA-256"]})';
175+
```
176+
177+
Replace `my-admin-user` with the username you want to use.
178+
179+
Note: if you want to specify the password programmatically rather than
180+
entering it manually, you can pipe the password to the `mongosh` command
181+
via `stdin`.
236182

237-
After enabling security, change the database URL when starting Refacto:
183+
2. Create a refacto user with access to the specific database you plan to use:
184+
185+
```sh
186+
mongosh my-refacto-db --authenticationDatabase=admin -u my-admin-user -p \
187+
--eval 'db.createUser({user:"my-refacto-user",pwd:passwordPrompt(),roles:[{"db":"my-refacto-db","role":"readWrite"},{"db":"my-refacto-db","role":"dbAdmin"}],mechanisms:["SCRAM-SHA-256"]})';
188+
```
189+
190+
Replace all occurrences of `my-refacto-db` with the database name you are
191+
using, and replace `my-refacto-user` with the username you want to use.
192+
193+
Note: if you want to specify the passwords programmatically rather than
194+
entering them manually, you can pipe the passwords to the `mongosh` command
195+
via `stdin`, separated by newlines (admin password + newline + refacto user
196+
password).
197+
198+
3. Enforce authorization:
199+
200+
Check the location of your `mongod.conf` file
201+
([typical locations](https://www.mongodb.com/docs/manual/reference/configuration-options/#configuration-file))
202+
and modify it to enable authorization:
203+
204+
```sh
205+
echo 'security.authorization: enabled' >> /etc/mongod.conf
206+
```
207+
208+
Restart MongoDB: (the exact command will depend on your system and how you
209+
installed it)
210+
211+
```sh
212+
sudo systemctl restart mongod
213+
```
214+
215+
You can now connect as the `my-admin-user` user:
238216

239217
```sh
240-
DB_URL="mongodb://localhost:27017/refacto?ssl=true" ./index.js
218+
mongosh --authenticationDatabase admin -u my-admin-user -p
241219
```
242220

243-
Note that after enabling this, unless you also configure identity checks, you
244-
will need to skip certificate validation when connecting via the commandline:
221+
And configure Refacto to connect as the `my-refacto-user` user:
245222

246223
```sh
247-
mongo --ssl --sslAllowInvalidCertificates
224+
DB_URL="mongodb://my-refacto-user:<pass>@localhost:27017/my-refacto-db" ./index.js
248225
```
249226

250-
### Client / server identity checks
227+
<https://docs.mongodb.com/manual/tutorial/enable-authentication/>
251228

252-
If the database is running on a separate server, you should enable client &
253-
server identity checks. The following resources offer guidance:
229+
### Encrypted communication
254230

255-
- <https://docs.mongodb.com/manual/tutorial/configure-ssl/>
256-
- <https://medium.com/@rajanmaharjan/secure-your-mongodb-connections-ssl-tls-92e2addb3c89>
231+
If the database is running on a separate server, you should enable encrypted
232+
communication (to avoid eavesdropping) as well as client and server identity
233+
checks (to avoid man-in-the-middle attacks). See the
234+
[MongoDB documentation for guidance](https://www.mongodb.com/docs/manual/tutorial/configure-ssl/).
257235

258236
## Analytics / Diagnostics
259237

docs/SERVICES.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ The configuration file will be created at `/usr/local/etc/mongod.conf` on macOS
4242
and `/etc/mongod.conf` on Ubuntu.
4343

4444
_Note: MongoDB's default security model is enough for local development, but you
45-
should lock it down further in deployments. See the
46-
[security documentation](./SECURITY.md) for details._
45+
should lock it down further in deployments. See [SECURITY.md](./SECURITY.md) for
46+
details._
4747

4848
### Redis
4949

@@ -265,7 +265,8 @@ line containing a JSON-encoded object of the form:
265265
```
266266

267267
When analytics are enabled, client-related log entries will also contain browser
268-
and OS versions (see the [security documentation](./SECURITY.md)).
268+
and OS versions (see the configuration options in
269+
[SECURITY.md](./SECURITY.md#analytics--diagnostics)).
269270

270271
#### Log rotation
271272

0 commit comments

Comments
 (0)