Skip to content

Commit ada8c16

Browse files
author
Jonas Hendrickx
authored
PAS-452 | Matching documentation for e-mail provider fallback (#146)
1 parent da3d337 commit ada8c16

File tree

1 file changed

+152
-39
lines changed

1 file changed

+152
-39
lines changed

src/guide/self-hosting/configuration.md

Lines changed: 152 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ By default, the container will use Sqlite if nothing else is specified. The data
5050
| Key | Default | Required | Description |
5151
| --------------------- | --------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
5252
| BWP_ENABLE_SSL | false | N | [true/false] See warning below. |
53-
| BWP_PORT | 5701 | Y | [0-65536] This will determine the port your self-hosted instance will be accessible from. |
53+
| BWP_PORT | 5701 | N | [0-65536] Only required if you don't use a reverse proxy. |
5454
| BWP_DOMAIN | localhost | N | [example.com] This will be the domain your self-hosted instance will be accessible from. It is important it matches for everything to work correctly. |
5555
| BWP_DB_PROVIDER | | N | [mssql/sqlserver/] Defaults to using Sqlite if not set |
5656
| BWP_DB_SERVER | | N | For any non-file hosted database, enter its domain name. Required for Microsoft SQL Server. |
@@ -63,85 +63,198 @@ By default, the container will use Sqlite if nothing else is specified. The data
6363
:::warning
6464
Setting SSL with `BWP_ENABLE_SSL` is required in [insecure contexts](https://w3c.github.io/webappsec-secure-contexts/#secure-contexts). Running the container locally on 'localhost' is considered a secure context.
6565

66+
If you are using a load balancer or reverse proxy, you can leave it set to false and handle SSL termination there.
67+
6668
Read the 'WebAuthn' specification here: [See specification](https://www.w3.org/TR/webauthn-2/#web-authentication-api).
6769
:::
6870

6971
## E-mail
7072

7173
Email is used by Passwordless Admin Console to notify administrators of changes to their organization. This is specifically useful for verifying administrators when first signing up.
7274

73-
By default, all e-mail communication is written to a file for each application.
74-
75-
- `/app/Admin/mail.md`
76-
- `/app/Api/mail.md`
75+
By default, all e-mail communication is written to a file:
7776

78-
When using the default configuration, the following commands will output the contents of each file.
77+
- `/app/mail.md`
7978

80-
For Admin Console:
79+
When using the default configuration, the following command will output the contents of the file.
8180

8281
```bash
83-
docker exec -it {name-of-container} cat /app/AdminConsole/mail.md
82+
docker exec -it {name-of-container} cat /app/mail.md
83+
```
84+
85+
### JSON
86+
87+
Reference: [Configuration in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-8.0)
88+
89+
What is important is to configure ‘Mail.From' as shown below. This is required to have a fallback e-mail address to send e-mails from. On the 'Mail.Providers’ is an array, which is an ordered list of e-mail providers that we will attempt to execute in order if they fail. To configure an e-mail provider, see the sub sections below.
90+
91+
```json
92+
"Mail": {
93+
"From": "[email protected]",
94+
"Providers": [
95+
{
96+
// Provider 1
97+
},
98+
{
99+
// Provider 2
100+
},
101+
{
102+
...
103+
}
104+
]
105+
},
106+
```
107+
108+
#### AWS
109+
110+
```json
111+
{
112+
"Name": "aws",
113+
"AccessKey": "aws_access_key_id",
114+
"SecretKey": "aws_secret_key",
115+
"Region": "us-west-2"
116+
}
117+
```
118+
119+
#### File
120+
121+
```json
122+
{
123+
"Name": "file",
124+
"Path": "/path/on/your/machine" //(optional)
125+
}
84126
```
85127

86-
For Api:
128+
#### SendGrid
129+
130+
```json
131+
{
132+
"Name": "sendgrid",
133+
"ApiKey": "sendgrid_api_key"
134+
}
135+
```
136+
137+
#### SMTP
138+
139+
```json
140+
{
141+
"Name": "smtp",
142+
"Host": "smtp.example.com",
143+
"Port": 123,
144+
"Username": "johndoe",
145+
"Password": "YourPassword123!",
146+
"StartTls": true/false,
147+
"Ssl": true/false,
148+
"SslOverride": true/false,
149+
"TrustServer": true/false // skips SSL certificate validation when set to `true`.
150+
}
151+
```
152+
153+
Example with SendGrid:
154+
155+
```json
156+
{
157+
"Name": "smtp",
158+
"Host": "smtp.sendgrid.net",
159+
"Port": 465,
160+
"Username": "apikey",
161+
"Password": "<your-sendgrid-api-key>",
162+
"StartTls": false,
163+
"Ssl": true,
164+
"SslOverride": false,
165+
"TrustServer": true
166+
}
167+
```
168+
169+
### Environment variables
170+
171+
Reference: [Configuration in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-8.0)
172+
173+
<!-- prettier-ignore -->
174+
What is important is to configure ‘Mail__From' as shown below. This is required to have a fallback e-mail address to send e-mails from. On the 'Mail__Providers’ is an array, which is an ordered list of e-mail providers that we will attempt to execute in order if they fail. To configure an e-mail provider, see the sub sections below.
175+
176+
Arrays start at zero so we configure AWS to be the first in line to attempt to send e-mails from, if that fails, we fall back to SendGrid.
87177

88178
```bash
89-
docker exec -it {name-of-container} cat /app/Api/mail.md
179+
-e Mail__From='[email protected]'
180+
-e Mail__FromName='John Doe'
181+
-e Mail__Providers__0__Name='aws'
182+
-e Mail__Providers__0__AccessKey='aws_access_key_id'
183+
-e Mail__Providers__0__SecretKey='aws_secret_key'
184+
-e Mail__Providers__1__Name='sendgrid'
185+
-e Mail__Providers__1__ApiKey='sendgrid_api_key'
90186
```
91187

92-
If you provide a directory for the application configuration to be stored in on your machine, the `mail.md` file will be located there.
188+
In the vendor specific examples below, we will always use '#' as the provider index.
93189

94-
It's recommended you configure the SMTP parameters below:
190+
#### AWS
95191

96-
| Key | Default | Required | Description |
97-
| -------------------- | ------- | -------- | --------------------------------------------------------------------------------------- |
98-
| BWP_SMTP_FROM | | Y | Use your sender e-mail. |
99-
| BWP_SMTP_USERNAME | | Y | |
100-
| BWP_SMTP_PASSWORD | | Y | |
101-
| BWP_SMTP_HOST | | Y | Hostname |
102-
| BWP_SMTP_PORT | | Y | [0-65535] |
103-
| BWP_SMTP_STARTTLS | false | N | [true/false] |
104-
| BWP_SMTP_SSL | false | N | [true/false] |
105-
| BWP_SMTP_TRUSTSERVER | false | N | [true/false] Allows you to skip certificate validation. Not recommended for production. |
192+
```bash
193+
-e Mail__Providers__#__Name='aws'
194+
-e Mail__Providers__#__AccessKey='aws_access_key_id'
195+
-e Mail__Providers__#__SecretKey='aws_secret_key'
196+
-e Mail__Providers__#__Region='us-west-2'
197+
```
106198

107-
:::warning
108-
To verify e-mailing is working correctly:
199+
#### File
109200

110-
- Create an admin with a new organization.
111-
- Invite an admin to an existing organization.
112-
:::
201+
```bash
202+
-e Mail__Providers__#__Name='file'
203+
-e Mail__Providers__#__Path='/path/on/your/machine' #(optional)
204+
```
113205

114-
### SendGrid example with SSL
206+
#### SendGrid
115207

116-
For verifying e-mailing is working correctly, you can use health-checks, read more [here](health-checks).
208+
```bash
209+
-e Mail__Providers__#__Name='sendgrid'
210+
-e Mail__Providers__#__ApiKey='sendgrid_api_key'
211+
```
212+
213+
#### SMTP
117214

118215
```bash
216+
-e Mail__Providers__#__Name='smtp'
217+
-e Mail__Providers__#__Host='smtp.example.com'
218+
-e Mail__Providers__#__Port=123
219+
-e Mail__Providers__#__Username='johndoe'
220+
-e Mail__Providers__#__Password='YourPassword123!'
221+
-e Mail__Providers__#__StartTls=true/false
222+
-e Mail__Providers__#__Ssl=true/false
223+
-e Mail__Providers__#__SslOverride=true/false
224+
-e Mail__Providers__#__TrustServer=true/false # skips SSL certificate validation when set to `true`.
225+
```
119226

120-
* BWP_SMTP_FROM: [email protected]
121-
* BWP_SMTP_USERNAME: apikey
122-
* BWP_SMTP_PASSWORD: <your-api-key>
123-
* BWP_SMTP_HOST: smtp.sendgrid.net
124-
* BWP_SMTP_PORT: 465
125-
* BWP_SMTP_SSL: true
126-
* BWP_SMTP_TRUSTSERVER: true (for local testing)
227+
Example with SendGrid:
228+
229+
```bash
230+
-e Mail__Providers__#__Name='smtp'
231+
-e Mail__Providers__#__Host='smtp.sendgrid.net'
232+
-e Mail__Providers__#__Port=465
233+
-e Mail__Providers__#__Username='apikey'
234+
-e Mail__Providers__#__Password='<your-sendgrid-api-key>'
235+
-e Mail__Providers__#__StartTls=false
236+
-e Mail__Providers__#__Ssl=true
237+
-e Mail__Providers__#__SslOverride=false
238+
-e Mail__Providers__#__TrustServer=true
239+
```
127240

128241
## config.json
129242

130243
:::warning
131244
Requirements:
245+
132246
- Persistent storage, see 'Volumes'.
133-
:::
247+
:::
134248

135249
`/etc/bitwarden_passwordless/config.json` is only generated when you have not specified the following environment variables:
136250

137-
138251
If you mount `/etc/bitwarden_passwordless` to your host. You can specify a `config.json`.
139252

140253
If the following keys do not exist, they will be generated automatically:
254+
141255
- Passwordless::ApiKey
142256
- Passwordless::ApiSecret
143257
- PasswordlessManagement::ManagementKey
144258
- SALT_KEY
145259

146260
It is recommended that you have them generated automatically, the first time you run `bitwarden/passwordless-self-host`.
147-
```

0 commit comments

Comments
 (0)