You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(cubejs-server): Integrated support for TLS (#213)
* feat(cubejs-server): Integrated support for TLS
@cubejs-backend/server listen supports receiving an option object.
Given env CUBEJS_ENABLE_TLS=true, the CubejsServer will use the option object in order to setup https connection.
* fix(packages/cubejs-server): Fix https string for redirection
* test(packages/cubejs-server): Updated snapshot test for redirector handler fn
* docs(packages/cubejs-server): Updated documentation to include TLS
Updated documentation to reflect changes in API and introduction of TLS support.
* chore(packages/cubejs-server): Removed dependency on config/env script
Copy file name to clipboardExpand all lines: docs/Cube.js-Backend/@cubejs-backend-server.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,3 +29,13 @@ server.listen().then(({ port }) => {
29
29
console.log(`🚀 Cube.js server is listening on ${port}`);
30
30
});
31
31
```
32
+
33
+
### this.listen([options])
34
+
35
+
Instantiates the Express.js App to listen to the specified `PORT`. Returns a promise that resolves with the following members:
36
+
37
+
*`port {number}` The port at which CubejsServer is listening for insecure connections for redirection to HTTPS, as specified by the environment variable `PORT`. Defaults to 4000.
38
+
*`app {Express.Application}` The express App powering CubejsServer
39
+
*`server {http.Server}` The `http` Server instance. If TLS is enabled, returns a `https.Server` instance instead.
40
+
41
+
Cube.js can also support TLS encryption. See the [Security page on how to enable tls](security#enabling-tls) for more information.
Copy file name to clipboardExpand all lines: docs/Cube.js-Backend/Security.md
+85Lines changed: 85 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,8 @@ Cube.js Javascript client accepts auth token as a first argument to [cubejs(auth
22
22
**In the development environment the token is not required for authorization**, but
23
23
you can still use it to [pass a security context](security#security-context).
24
24
25
+
Cube.js also supports Transport Layer Encryption (TLS) using Node.js native packages. For more information, see [Enabling TLS](security#enabling-tls).
26
+
25
27
## Generating Token
26
28
27
29
Auth token is generated based on your API secret. Cube.js CLI generates API Secret on app creation and saves it in `.env` file as `CUBEJS_API_SECRET` variable.
@@ -115,3 +117,86 @@ SELECT
115
117
) AS orders
116
118
LIMIT 10000
117
119
```
120
+
121
+
## Enabling TLS
122
+
123
+
Cube.js server package supports transport layer encryption.
124
+
125
+
By setting the environment variable `CUBEJS_ENABLE_TLS` to true (`CUBEJS_ENABLE_TLS=true`), `@cubejs-backend/server` expects an argument to its `listen`functionspecifying the tls encryption options. The `tlsOption` object must match Node.js' [`https.createServer([options][, requestListener])` option object](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener).
126
+
127
+
This enables you to specify your TLS security directly within the Node process without having to rely on external deployment tools to manage your certificates.
console.log(`🚀 Cube.js server is listening securely on ${tlsPort}`);
145
+
});
146
+
```
147
+
148
+
Notice that the response from the resolution of `listen`'s promise returns more than just the `port` and the express `app` as it would normally do without `CUBEJS_ENABLE_TLS` enabled. When `CUBEJS_ENABLE_TLS` is enabled, `cubejsServer.listen` will resolve with the following:
149
+
150
+
*`port {number}` The port at which CubejsServer is listening for insecure connections for redirection to HTTPS, as specified by the environment variable `PORT`. Defaults to 4000.
151
+
*`tlsPort {number}` The port at which TLS is enabled, as specified by the environment variable `TLS_PORT`. Defaults to 4433.
152
+
*`app {Express.Application}` The express App powering CubejsServer
153
+
*`server {https.Server}` The `https` Server instance.
154
+
155
+
The `server` object is especially useful if you want to use self-signed, self-renewed certificates.
156
+
157
+
### Self-signed, self-renewed certificates
158
+
159
+
Self-signed, self-renewed certificates are useful when dealing with internal data transit, like when answering requests from private server instance to another private server instance without being able to use an external DNS CA to sign the private certificates. _Example:_ EC2 to EC2 instance communications within the private subnet of a VPC.
160
+
161
+
Here is an example of how to do leverage `server` to have self-signed, self-renewed encryption:
`🚨 Certificate renewal failed with error "${error.message}"`
187
+
);
188
+
// take some action here to notify the DevOps
189
+
return;
190
+
}
191
+
console.log(`🔐 Certificate renewal successful`);
192
+
});
193
+
}
194
+
195
+
main();
196
+
```
197
+
198
+
To generate your self-signed certificates, look into [`pem`](https://www.npmjs.com/package/pem) and [`node-forge`](https://www.npmjs.com/package/node-forge).
199
+
200
+
### 🚨 Node Support for Self Renewal of Secure Context
201
+
202
+
Certificate Renewal using [`server.setSecureContext(options)`](https://nodejs.org/api/tls.html#tls_server_setsecurecontext_options) is only available as of Node.js v11.x
0 commit comments