-
-
Notifications
You must be signed in to change notification settings - Fork 641
docs: document SSL options #3384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
505e848
Update 00-index.mdx
pkuczynski 7a6404c
Create ssl.mdx
pkuczynski 8a2fa96
Update ssl.mdx
pkuczynski 84dcbdf
Update ssl.mdx
pkuczynski 0add7d6
Update ssl.mdx
pkuczynski d05e993
Merge branch 'sidorares:master' into patch-1
pkuczynski 03f2c7d
add default cert example
pkuczynski 3dc5a48
Update website/docs/documentation/ssl.mdx
pkuczynski 0f13576
Update website/docs/documentation/ssl.mdx
pkuczynski b927a0c
Update website/docs/documentation/ssl.mdx
pkuczynski 06dd09a
Update website/docs/documentation/ssl.mdx
pkuczynski bc1e869
Update website/docs/documentation/ssl.mdx
pkuczynski 2fb93e3
some changes
pkuczynski 7a3778f
Merge remote-tracking branch 'origin/patch-1' into patch-1
pkuczynski 0650077
lint
pkuczynski fb98204
Update website/docs/documentation/ssl.mdx
wellwelwel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,70 @@ | ||
# SSL | ||
|
||
As part of the connection options one can specify an object with ssl parameters or a string containing name of SSL profile. | ||
|
||
```ts | ||
ssl?: string | SslOptions; | ||
``` | ||
|
||
See full list of [SslOptions](../../../typings/mysql/lib/Connection.d.ts), which are in the same format as [tls.createSecureContext](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options). | ||
wellwelwel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## SSL Options | ||
|
||
To enable SSL without manually providing certificates and assuming they are already trusted by the host machine, you can specify empty object: | ||
pkuczynski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```ts | ||
const connection = 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 | ||
const connection = mysql.createConnection({ | ||
pkuczynski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
host: 'localhost', | ||
ssl: { | ||
ca: fs.readFileSync(__dirname + '/mysql-ca.crt') | ||
} | ||
}); | ||
``` | ||
|
||
When cerificate is read from environment variable, you might need to replace escaped `\n` characters with proper new line characters: | ||
pkuczynski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```ts | ||
const connection = mysql.createConnection({ | ||
host: 'localhost', | ||
ssl: { | ||
ca: process.env.DB_SSL_CA?.replace(/\\n/gm, '\n') | ||
} | ||
}); | ||
``` | ||
|
||
You can also connect to a MySQL server without properly providing an appropriate CA to trust. **This is highly discouraged** as being insecure. | ||
|
||
```ts | ||
const connection = mysql.createConnection({ | ||
host: 'localhost', | ||
ssl: { | ||
// DO NOT DO THIS | ||
// set up your ca correctly to trust the connection | ||
pkuczynski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rejectUnauthorized: false | ||
} | ||
}); | ||
``` | ||
|
||
## SSL Profile (deprecated) | ||
|
||
Alternativelly you can also specify a string containing name of SSL profile: | ||
|
||
```ts | ||
const connection = mysql.createConnection({ | ||
host: 'localhost', | ||
ssl: 'Amazon RDS' | ||
}); | ||
``` | ||
|
||
Following profiles are included in the package: | ||
|
||
* `Amazon RDS` - contains certificates from https://rds.amazonaws.com/doc/rds-ssl-ca-cert.pem and https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem | ||
wellwelwel marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.