Skip to content

Commit 25c8281

Browse files
thomas-tacquetttacquet
andauthored
add documentation about credentials management (#78)
Co-authored-by: ttacquet <[email protected]>
1 parent 0c592c0 commit 25c8281

File tree

2 files changed

+69
-7
lines changed

2 files changed

+69
-7
lines changed

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Serverless Framework handles everything from creating namespaces to function/cod
88
- [Requirements](#requirements)
99
- [Create a Project](#create-a-project)
1010
- [Configure your functions](#configure-your-functions)
11+
- [Security and secret management](#security-and-secret-management)
1112
- [Functions Handler](#functions-handler)
1213
- [Using ES Modules](#using-es-modules)
1314
- [Node](#node)
@@ -57,15 +58,18 @@ Your functions are defined in the `serverless.yml` file created:
5758
service: scaleway-python3
5859
configValidationMode: off
5960

61+
useDotenv: true
62+
6063
provider:
6164
name: scaleway
6265
runtime: python310
6366
# Global Environment variables - used in every functions
6467
env:
6568
test: test
69+
# Storing credentials in this file is strongly not recommanded for security concerns, please refer to README.md about best practices
6670
scwToken: <scw-token>
6771
scwProject: <scw-project-id>
68-
# region in which the deployment will happen, (default fr-par)
72+
# region in which the deployment will happen (default: fr-par)
6973
scwRegion: <scw-region>
7074

7175
plugins:
@@ -92,6 +96,8 @@ of the same runtime (here `python3`)
9296

9397
The different parameters are:
9498
* `service`: your namespace name
99+
* `useDotenv`: Load environment variables from .env files (default: false), read [Security and secret management](#security-and-secret-management)
100+
* `configValidationMode`: Configuration validation: 'error' (fatal error), 'warn' (logged to the output) or 'off' (default: warn)
95101
* `provider.runtime`: the runtime of your functions (check the supported runtimes above)
96102
* `provider.env`: environment variables attached to your namespace are injected to all your namespace functions
97103
* `provider.secret`: secret environment variables attached to your namespace are injected to all your namespace functions, see [this example project](./examples/secrets)
@@ -110,6 +116,40 @@ The different parameters are:
110116
* `runtime`: (Optional) runtime of the function, if you need to deploy multiple functions with different runtimes in your Serverless Project. If absent, `provider.runtime` will be used to deploy the function, see [this example project](./examples/multiple).
111117
* `events` (Optional): List of events to trigger your functions (e.g, trigger a function based on a schedule with `CRONJobs`). See `events` section below
112118

119+
### Security and secret management
120+
121+
You configuration file may contains sensitive data, your project ID and your Token must not be shared and must not be commited in VCS.
122+
123+
To keep your informations safe and be able to share or commit your `serverles.yml` file you should remove your credentials from the file. Then
124+
you can :
125+
- use global environment variables
126+
- use `.env` file and keep it secret
127+
128+
To use `.env` file you can modify your `serverless.yml` file as following :
129+
130+
```yml
131+
# This will alow the plugin to read your .env file
132+
useDotenv: true
133+
134+
provider:
135+
name: scaleway
136+
runtime: node16
137+
138+
scwToken: ${env:SCW_SECRET_KEY}
139+
scwProject: ${env:SCW_DEFAULT_PROJECT_ID}
140+
scwRegion: ${env:SCW_REGION}
141+
```
142+
143+
And then create a `.env` file next to your `serverless.yml` file, containing following values :
144+
145+
```bash
146+
SCW_SECRET_KEY=XXX
147+
SCW_DEFAULT_PROJECT_ID=XXX
148+
SCW_REGION=fr-par
149+
```
150+
151+
You can use this pattern to hide your secrets (for example a connexion string to a database or a S3 bucket).
152+
113153
## Functions Handler
114154

115155
Based on the chosen runtime, the `handler` variable on function might vary.

docs/README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,30 @@ Now, when running `serverless` commands from your project directory, serverless
6060

6161
### Use your credentials
6262

63-
Once you retrieved your `project ID` and created a new `token`, you will have to use these credentiasl with the Serverless Framework.
63+
Once you retrieved your `project ID` and created a new `token`, you will have to use these credentials with the Serverless Framework.
6464

6565
There are multiple ways to do it:
6666

67-
- **serverless.yml** manifest. Inside your manifest, you may inquire your credentials with the following structure under the `provider` key:
67+
- **Using `.env` file** (recommanded):
68+
6869
```yml
70+
# This will alow the plugin to read your .env file
71+
useDotenv: true
72+
6973
provider:
70-
scwToken: <scw-token>
71-
scwProject: <scw-project-id>
74+
name: scaleway
75+
runtime: node16
76+
77+
scwToken: ${env:SCW_SECRET_KEY}
78+
scwProject: ${env:SCW_DEFAULT_PROJECT_ID}
7279
```
73-
- **CLI arguments**:
7480
75-
[link to CLI documentation](https://github.com/scaleway/scaleway-cli/blob/master/docs/commands/function.md)
81+
Create a `.env` file next to your `serverless.yml` file :
82+
83+
```bash
84+
SCW_SECRET_KEY=XXX
85+
SCW_DEFAULT_PROJECT_ID=XXX
86+
```
7687

7788
- **Environment variables**:
7889
```bash
@@ -81,6 +92,17 @@ export SCW_PROJECT=<scw-project-id>
8192
serverless deploy
8293
```
8394

95+
- **CLI arguments**:
96+
97+
[link to CLI documentation](https://github.com/scaleway/scaleway-cli/blob/master/docs/commands/function.md)
98+
99+
- **serverless.yml** (discouraged) manifest. Inside your manifest, you may inquire your credentials with the following structure under the `provider` key:
100+
```yml
101+
provider:
102+
scwToken: <scw-token>
103+
scwProject: <scw-project-id>
104+
```
105+
84106
The priority order is the following (from top: + priority to bottom: - priority):
85107
- CLI
86108
- Environment variables

0 commit comments

Comments
 (0)