-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Adding ssl config params to Postgres URI #6580
Conversation
…rseConfigParser.js. The allows for a more felxible uri for ssl and other params
Note that the parse-spec along with with any testing pg-promise and node-postures perform handles the test cases needed for this |
@dplewis this passed in travis, but for some reason CI still shows yellow here. Can you rerun when you get a chance? If you see no issues with this PR, it's ready to be merged |
I believe it is ready to merge. @dplewis agree? |
I believe the Custom Parser is there because of the limited options pg-connections has. I see the appeal to remove it but you could just add the additional options you want to it like sslcert etc to fix your use case. We do parse out a few custom items like poolSize which would no longer be there. @vitaly-t Thoughts? |
@dplewis If I'm understanding the readme of pg-connection-string correctly, "any other query parameters (for example, application_name) are preserved intact.". The custom parser actually provides the opposite of what you mentioned when compared to "pg-connection-string" because only parameters that the custom parser knows can be passed. Since all params are "preserved intact" and passed down to node-postgres, things like poolSize and any other parameter can be used assuming they are in a format node-postgres understands. If this is not the case, then using @vitaly-t connection-string might be a better option. I wrote about this a little bit here |
Another option could be to roll back to the previous version of pg-promise for now, if node-postgrres can't use the additional parameters passed to pg-connection-string. When a uri solution is provided, move back to the latest version |
I found a discussion about this on pg-connection-string, gajus/slonik#60. It doesn't look they decided on which one to use, connection-string or pg-connection-string. If pg-connection-string doesn't work the way I assumed it works above, using connection-string or editing the custom parser will be the next step. |
I wasted too much time in the past, trying to get the base driver to start using the generic connection-string. I even did a complete PR for to patch the limited string parser. But after all that, nothing happened. The internal to pg parser is limited, so is |
@dplewis @davimacedo based on the discussion I've reverted this back to using PostgresConfigParser and added in the ability to parse ssl params as well as the rest of the ones that show up on pg-promise. I've also added some test cases... A note, to create the ssl object as described on pg-promise, a uri is can be created using Lastly, I removed the default test-case of when ssl is not supplied and setting it to "ssl=false". This is already done by default in node-postgres and not needed. If I left it, it would create the scenario of switching the ssl variable from a boolean to an object, which I guess is allowed in js, but not something I like doing since I'm use to strongly-typed languages and I can see it creating some bugs in the future. The way I set it up, ssl is either a "boolean" or an "object". Let me know what you think... |
Codecov Report
@@ Coverage Diff @@
## master #6580 +/- ##
==========================================
+ Coverage 93.90% 93.95% +0.05%
==========================================
Files 169 169
Lines 11968 12301 +333
==========================================
+ Hits 11239 11558 +319
- Misses 729 743 +14
Continue to review full report at Codecov.
|
I've tested params like "rejectUnauthorized=false/true" and "ca=/path/to/file" on my servers that use ssl certs and this works. Some anecdotal notes about using pg-promise and it's underlying drivers with ssl:
A discussion about the ssl changes in pg-promise/node-postgres is here, but only some of the notes above are in the direct discussion |
This may need to be documented somewhere: Parse-server versions that use Postgres have the following compatibility with ssl:
|
Note that this is ready to be reviewed, it passed in Travis, but for some reason didn't update here. |
@dplewis have you had a chance to look at the changes here. What do you think about my comments about SSL and MITM in the previous versions of parse-server? |
@cbaker6 Thanks for taking the time to research and document your findings. Its really helpful. We just let users know to update to the latest version of Parse Server. I don't know why travis keeps getting stuck. |
@dplewis I couldn't determine a good place to document how to use the updated postgres uri. All available are: -- URI supports
Some useful combinations are below:
People should be able to figure out the rest from there... |
Hmm the Parse Server Guide would be a good place. |
Just adding some more details about ssl (w & w/o verification). node-postgres has made similar adjustments pg-connection-string, https://github.com/brianc/node-postgres/blob/master/CHANGELOG.md#pg810 No changes needed for parse-server since the changes in this PR on PostgresConfgParser.js worked around these issues. |
Use pg-promise native pg-connection-string to parse uri instead of PostgresConfigParser.js. The change allows for a more felxible uri for ssl along with the ability to supply additional parameters for establishing a connection with pg-promise.Update: Adding parameter parsing to PostgresConfigParser.js instead...
For example, the current PostgresConfigParser can only take a boolean ssl value and PostgresConfigParser limits the variables that can passed to pg-promise through an URI. This is important because #6555 upgraded pg-promise and added changes in node-postgres 8 below:
Change default behavior when not specifying rejectUnauthorized with the SSL connection parameters. Previously we defaulted to rejectUnauthorized: false when it was not specifically included. We now default to rejectUnauthorized: true. Manually specify { ssl: { rejectUnauthorized: false } } for old behavior.
In previous versions of pg-promise, this gave a warning. Currently you can't pass
rejectUnauthorized
through a URI string as an object to ssl. This means that postgres users who use ssl not known to node-posgres are automatically rejected (which is basically any cert because you can't pass inca
with the current PostgresConfigParser.js). Switching to the pg-connection-string (which is part of the node-postures driver) allows for:Allowing you to pass parameters like:
PostgresConfigParser is left intact for legacy purposes as well is it can possibly be used to parse other custom items out of the uri string in the future.