Skip to content
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

feat: add SSL to new DB parameters #14673

Merged
merged 3 commits into from
May 18, 2021

Conversation

betodealmeida
Copy link
Member

SUMMARY

Expose an option to configure an encrypted connection when adding a new database with the new parameters flow.

In the new flow, users can just specify that they want SSL on, and we'll build a SQLAlchemy URI that enforces encryption. For Postgres, eg, this is done by adding sslmode=verify-ca to the query parameters.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TEST PLAN

Updated unit tests.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

== "postgresql+psycopg2://username:password@localhost:5432/dbname?foo=bar"
assert sqlalchemy_uri == (
"postgresql+psycopg2://username:password@localhost:5432/dbname?"
"foo=bar&sslmode=verify-ca"
Copy link
Member

@hughhhh hughhhh May 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could go with an enum approach to make sure the user is entering one of the 5 properly

https://www.postgresql.org/docs/9.1/libpq-ssl.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hughhhh the user is not choosing one, with the new form they only choose between SSL on or off. If they choose "on" we set it to verify-ca, since it's the least restrictive one that still ensures an encrypted connection (note that require is identical to verify-ca).

If the user wants to use a different value (eg, verify-full) they need to edit the SQLAlchemy URI directly.

Copy link
Member

@hughhhh hughhhh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put encryption under a enum to make sure users are entering the proper information

@@ -1339,8 +1343,16 @@ class BasicParametersMixin:
"drivername://user:password@host:port/dbname[?key=value&key=value...]"
)

# query parameter to enable encryption in the database connection
# for Postgres this would be `{"sslmode": "verify-ca"}`, eg.
encryption_parameters: Dict[str, str] = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you feel that we will need to check/enforce that this is defined on the engine specs that use this mixin?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good idea... maybe if the users passes encryption=True when configuring a database we should raise an exception if this is empty.

@codecov
Copy link

codecov bot commented May 18, 2021

Codecov Report

Merging #14673 (6dad46d) into master (4f5c537) will increase coverage by 0.00%.
The diff coverage is 91.66%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #14673   +/-   ##
=======================================
  Coverage   77.54%   77.55%           
=======================================
  Files         958      958           
  Lines       48541    48559   +18     
  Branches     5702     5702           
=======================================
+ Hits        37640    37658   +18     
  Misses      10700    10700           
  Partials      201      201           
Flag Coverage Δ
hive 81.11% <91.66%> (+0.01%) ⬆️
mysql 81.38% <91.66%> (+0.01%) ⬆️
postgres 81.40% <91.66%> (+0.01%) ⬆️
presto 81.10% <91.66%> (+0.01%) ⬆️
python 81.93% <91.66%> (+0.01%) ⬆️
sqlite 81.03% <91.66%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/db_engine_specs/base.py 88.46% <90.90%> (+<0.01%) ⬆️
superset/db_engine_specs/postgres.py 96.96% <100.00%> (+0.03%) ⬆️
superset/databases/schemas.py 99.54% <0.00%> (ø)
superset/views/dynamic_plugins.py 100.00% <0.00%> (ø)
superset/app.py 81.59% <0.00%> (+0.28%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f5c537...6dad46d. Read the comment docs.

@hughhhh hughhhh self-requested a review May 18, 2021 01:18
@betodealmeida betodealmeida merged commit 971f588 into apache:master May 18, 2021
cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
* feat: add SSL to new DB parameters

* Fix test

* Raise if cls.encryption_parameters is empty
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
* feat: add SSL to new DB parameters

* Fix test

* Raise if cls.encryption_parameters is empty
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
* feat: add SSL to new DB parameters

* Fix test

* Raise if cls.encryption_parameters is empty
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.3.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants