-
-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update 00-index.mdx * Create ssl.mdx * Update ssl.mdx * Update ssl.mdx * Update ssl.mdx * add default cert example * Update website/docs/documentation/ssl.mdx Co-authored-by: Weslley Araújo <[email protected]> * Update website/docs/documentation/ssl.mdx Co-authored-by: Weslley Araújo <[email protected]> * Update website/docs/documentation/ssl.mdx Co-authored-by: Weslley Araújo <[email protected]> * Update website/docs/documentation/ssl.mdx Co-authored-by: Weslley Araújo <[email protected]> * Update website/docs/documentation/ssl.mdx Co-authored-by: Weslley Araújo <[email protected]> * some changes * lint * Update website/docs/documentation/ssl.mdx --------- Co-authored-by: Weslley Araújo <[email protected]>
- Loading branch information
1 parent
37e4e74
commit a446fac
Showing
3 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# SSL | ||
|
||
As part of the connection options, you can specify the `ssl` object property or a string containing the SSL profile content (**deprecated**). | ||
|
||
```ts | ||
ssl?: string | SslOptions; | ||
``` | ||
|
||
See full list of [SslOptions](https://github.com/sidorares/node-mysql2/blob/master/typings/mysql/lib/Connection.d.ts#L24-L80), which are in the same format as [tls.createSecureContext](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options). | ||
|
||
## SSL Options | ||
|
||
To enable SSL without manually providing certificates and assuming they are already trusted by the host machine, you can specify an empty object, for example: | ||
|
||
```ts | ||
const connection = await mysql.createConnection({ | ||
host: 'localhost', | ||
ssl: {}, | ||
}); | ||
``` | ||
|
||
You can also specify custom certificate(s) as an individual string or array of strings. Please note the arguments expect a string of the certificate, not a file name to the certificate: | ||
|
||
```ts | ||
import fs from 'node:fs'; | ||
|
||
const connection = await mysql.createConnection({ | ||
host: 'localhost', | ||
ssl: { | ||
ca: fs.readFileSync(__dirname + '/mysql-ca.crt'), | ||
}, | ||
}); | ||
``` | ||
|
||
When a certificate is read from an environment variable, it's recommended to replace escaped `\n` characters with proper new line characters, for example: | ||
|
||
```ts | ||
const connection = await mysql.createConnection({ | ||
host: 'localhost', | ||
ssl: { | ||
ca: process.env.DB_SSL_CA?.replace(/\\n/gm, '\n'), | ||
}, | ||
}); | ||
``` | ||
|
||
## SSL Certificate Bundle | ||
|
||
Alternatively, you can use a bundle with CA certificates. For example for Amazon RDS you could use: | ||
|
||
```ts | ||
import awsCaBundle from 'aws-ssl-profiles'; | ||
|
||
const connection = await mysql.createConnection({ | ||
host: 'db.id.ap-southeast-2.rds.amazonaws.com', | ||
ssl: awsCaBundle, | ||
}); | ||
``` | ||
|
||
For detailed instructions, please follow [aws-ssl-profiles](https://github.com/mysqljs/aws-ssl-profiles) documentation. | ||
|
||
## SSL Profile (deprecated) | ||
|
||
There is also a **deprecated option** allowing to specify a string containing name of SSL profile: | ||
|
||
```ts | ||
const connection = await mysql.createConnection({ | ||
host: 'localhost', | ||
ssl: 'Amazon RDS', | ||
}); | ||
``` | ||
|
||
Following profiles are included in the package: | ||
|
||
- `Amazon RDS` - in this case https://s3.amazonaws.com/rds-downloads/mysql-ssl-ca-cert.pem CA cert is used | ||
|
||
## Ignoring Unauthorized SSL Errors | ||
|
||
You can also connect to a MySQL server without providing an appropriate CA to trust. **This is highly discouraged** as being insecure. | ||
|
||
```ts | ||
const connection = await mysql.createConnection({ | ||
host: 'localhost', | ||
ssl: { | ||
// Beware, set `rejectUnauthorized` as `false` is strongly discouraged for security reasons: | ||
rejectUnauthorized: false, | ||
}, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a446fac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pkuczynski @wellwelwel ideally links in the documentation should point to a tag / commit, not tip of the branch as line numbers might point to code other that initially intended in the future revisions. Press
y
key shortcut in github web ui to automaticaly switch to sha in the urla446fac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same feeling, that's why I pointed to a file not a line, but then @wellwelwel made an update in my PR. Shall I fix it in subsequent PR?
a446fac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sidorares, I forgot the
y
tip here. Sorry for that.@pkuczynski, the website doesn't have access to the source code files (e.g., using
../../some-file.js
), it's because the site relies on the directory./website/build
as its root path. The best approach is, in fact, the one mentioned by @sidorares 🙋🏻♂️Let's address it to #3387 (I haven't been able to review it yet) 🤝