Skip to content

Commit dc8eeae

Browse files
committed
docs: Restructure secrets section for more clarity and improve explanation
1 parent f2c7af7 commit dc8eeae

File tree

1 file changed

+58
-19
lines changed

1 file changed

+58
-19
lines changed

docs/06-concepts/07-configuration.md

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,77 @@ These can be separately declared for each run mode in the corresponding yaml fil
7373

7474
Secrets are declared in the `passwords.yaml` file. The password file is structured with a common `shared` section, any secret put here will be used in all run modes. The other sections are the names of the run modes followed by respective key/value pairs.
7575

76+
You can define your own custom secrets in the [passwords file](#passwords-file-example) by adding them to either the `shared` section (to make them available in all run modes) or to specific run mode sections. These custom secrets will be available in your code through the `Session.passwords` map.
77+
78+
#### Built-in Secrets
79+
80+
The following table shows the built-in secrets that Serverpod uses for its core functionality. These can be configured either through environment variables or by adding the corresponding key in a respective run mode or shared section in the passwords file. These are separate from any custom passwords you might define.
81+
7682
| Environment variable | Passwords file | Default | Description |
7783
| --------------------------- | -------------- | ------- | ----------------------------------------------------------------- |
7884
| SERVERPOD_DATABASE_PASSWORD | database | - | The password for the database |
7985
| SERVERPOD_SERVICE_SECRET | serviceSecret | - | The token used to connect with insights must be at least 20 chars |
8086
| SERVERPOD_REDIS_PASSWORD | redis | - | The password for the Redis server |
8187

88+
#### Secrets for First Party Packages
89+
90+
The following secrets are used by official Serverpod packages:
91+
92+
- [serverpod_cloud_storage_gcp](https://pub.dev/packages/serverpod_cloud_storage_gcp): Google Cloud Storage
93+
- [serverpod_cloud_storage_s3](https://pub.dev/packages/serverpod_cloud_storage_s3): Amazon S3
94+
95+
| Environment variable | Passwords file | Default | Description |
96+
| ---------------------------- | --------------- | ------- | ------------------------------------------------------------------------- |
97+
| SERVERPOD_HMAC_ACCESS_KEY_ID | HMACAccessKeyId | - | The access key ID for HMAC authentication for serverpod_cloud_storage_gcp |
98+
| SERVERPOD_HMAC_SECRET_KEY | HMACSecretKey | - | The secret key for HMAC authentication for serverpod_cloud_storage_gcp |
99+
| SERVERPOD_AWS_ACCESS_KEY_ID | AWSAccessKeyId | - | The access key ID for AWS authentication for serverpod_cloud_storage_s3 |
100+
| SERVERPOD_AWS_SECRET_KEY | AWSSecretKey | - | The secret key for AWS authentication for serverpod_cloud_storage_s3 |
101+
82102
### Custom Passwords
83103

84-
In addition to the predefined secrets above, you can define custom passwords using environment variables with the `SERVERPOD_PASSWORD_` prefix. For example, `SERVERPOD_PASSWORD_myApiKey` will be available in your code as `myApiKey` (the prefix is stripped) through the `Session.passwords` map. These environment variables will override any passwords defined in the [passwords file](#passwords-file-example) if the name (after stripping the prefix) matches. Like the `shared` section in the passwords file, these environment variables are available in all run modes.
104+
You can define custom passwords in two ways:
105+
106+
#### 1. Via Passwords File
107+
108+
Add your custom secrets directly to the passwords file under the `shared` section (available in all run modes) or under specific run mode sections:
109+
110+
```yaml
111+
shared:
112+
myCustomSharedSecret: 'secret_key'
113+
stripeApiKey: 'sk_test_123...'
114+
115+
development:
116+
database: 'development_password'
117+
redis: 'development_password'
118+
serviceSecret: 'development_service_secret'
119+
twilioApiKey: 'dev_twilio_key'
120+
121+
production:
122+
database: 'production_password'
123+
redis: 'production_password'
124+
serviceSecret: 'production_service_secret'
125+
twilioApiKey: 'prod_twilio_key'
126+
```
127+
128+
#### 2. Via Environment Variables
129+
130+
You can also define custom passwords using environment variables with the `SERVERPOD_PASSWORD_` prefix. For example, `SERVERPOD_PASSWORD_myApiKey` will be available as `myApiKey` (the prefix is stripped). These environment variables will override any passwords defined in the passwords file if the name (after stripping the prefix) matches. Like the `shared` section in the passwords file, these environment variables are available in all run modes.
85131

86-
| Environment variable format | Description |
87-
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
88-
| SERVERPOD_PASSWORD\_\* | Custom password that will be available in the Session.passwords map. The prefix `SERVERPOD_PASSWORD_` prefix will be stripped from the key name. |
132+
| Environment variable format | Description |
133+
| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
134+
| SERVERPOD_PASSWORD\_\* | Custom password that will be available in the Session.passwords map. The prefix `SERVERPOD_PASSWORD_` will be stripped from the key name. |
89135

90-
#### Example
136+
**Example:**
91137

92-
To define a custom password through an environment variable, set it as an environment variable with the prefix:
138+
To define a custom password through an environment variable:
93139

94140
```bash
95141
export SERVERPOD_PASSWORD_stripeApiKey=sk_test_123...
96142
```
97143

98-
You can then access it in your endpoint code:
144+
**Accessing Custom Passwords:**
145+
146+
You can then access any custom password (whether defined in the passwords file or via environment variables) in your endpoint code through the `Session.passwords` map:
99147

100148
```dart
101149
Future<void> processPayment(Session session, PaymentData data) async {
@@ -105,18 +153,6 @@ Future<void> processPayment(Session session, PaymentData data) async {
105153
}
106154
```
107155

108-
#### Secrets for first party packages
109-
110-
- [serverpod_cloud_storage_gcp](https://pub.dev/packages/serverpod_cloud_storage_gcp): Google Cloud Storage
111-
- [serverpod_cloud_storage_s3](https://pub.dev/packages/serverpod_cloud_storage_s3): Amazon S3
112-
113-
| Environment variable | Passwords file | Default | Description |
114-
| ---------------------------- | --------------- | ------- | ------------------------------------------------------------------------- |
115-
| SERVERPOD_HMAC_ACCESS_KEY_ID | HMACAccessKeyId | - | The access key ID for HMAC authentication for serverpod_cloud_storage_gcp |
116-
| SERVERPOD_HMAC_SECRET_KEY | HMACSecretKey | - | The secret key for HMAC authentication for serverpod_cloud_storage_gcp |
117-
| SERVERPOD_AWS_ACCESS_KEY_ID | AWSAccessKeyId | - | The access key ID for AWS authentication for serverpod_cloud_storage_s3 |
118-
| SERVERPOD_AWS_SECRET_KEY | AWSSecretKey | - | The secret key for AWS authentication for serverpod_cloud_storage_s3 |
119-
120156
### Config file example
121157

122158
The config file should be named after the run mode you start the server in and it needs to be placed inside the `config` directory in the root of the server project. As an example, you have the `config/development.yaml` that will be used when running in the `development` run mode.
@@ -172,16 +208,19 @@ The password file contains the secrets used by the server to connect to differen
172208
```yaml
173209
shared:
174210
myCustomSharedSecret: 'secret_key'
211+
stripeApiKey: 'sk_test_123...'
175212
176213
development:
177214
database: 'development_password'
178215
redis: 'development_password'
179216
serviceSecret: 'development_service_secret'
217+
twilioApiKey: 'dev_twilio_key'
180218
181219
production:
182220
database: 'production_password'
183221
redis: 'production_password'
184222
serviceSecret: 'production_service_secret'
223+
twilioApiKey: 'prod_twilio_key'
185224
```
186225

187226
### Dart config object example

0 commit comments

Comments
 (0)