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(ssh-tunnel): ssh manager config + feature flag #22201

Merged
merged 18 commits into from
Dec 15, 2022

Conversation

hughhhh
Copy link
Member

@hughhhh hughhhh commented Nov 22, 2022

SUMMARY

Created a config object class to manage how ssh tunnels can be configured. The main use case for this is to allow mutation and validation on ssh tunnels being created for a given superset instance. For the SSHManager the

class SSHManager:  # pylint: disable=too-few-public-methods
    local_bind_address = "127.0.0.1"

    def mutator(  # pylint: disable=no-self-use
        self, sqlalchemy_url: str, server: sshtunnel.SSHTunnelForwarder
    ) -> str:
        # override any ssh tunnel configuration object
        from superset.databases.utils import make_url_safe

        url = make_url_safe(sqlalchemy_url)
        return url.set(
            host=self.local_bind_address,
            port=server.local_bind_port,
        )

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • 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

@codecov
Copy link

codecov bot commented Nov 22, 2022

Codecov Report

Merging #22201 (c6a3dee) into create-sshtunnelconfig-tbl (e3ef835) will decrease coverage by 11.16%.
The diff coverage is 69.23%.

❗ Current head c6a3dee differs from pull request most recent head 146c476. Consider uploading reports for the commit 146c476 to get more accurate results

@@                       Coverage Diff                       @@
##           create-sshtunnelconfig-tbl   #22201       +/-   ##
===============================================================
- Coverage                       66.95%   55.79%   -11.17%     
===============================================================
  Files                            1852     1852               
  Lines                           70504    70511        +7     
  Branches                         7689     7689               
===============================================================
- Hits                            47206    39341     -7865     
- Misses                          21304    29176     +7872     
  Partials                         1994     1994               
Flag Coverage Δ
hive 52.58% <69.23%> (+<0.01%) ⬆️
mysql ?
postgres ?
presto 52.47% <69.23%> (+<0.01%) ⬆️
python 57.97% <69.23%> (-23.38%) ⬇️
sqlite ?
unit 51.11% <69.23%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
superset/constants.py 100.00% <ø> (ø)
superset/config.py 90.82% <66.66%> (-1.03%) ⬇️
superset/models/core.py 76.73% <66.66%> (-13.05%) ⬇️
superset/databases/ssh_tunnel/models.py 75.86% <100.00%> (ø)
superset/utils/dashboard_import_export.py 0.00% <0.00%> (-100.00%) ⬇️
superset/tags/core.py 4.54% <0.00%> (-95.46%) ⬇️
superset/key_value/commands/update.py 0.00% <0.00%> (-90.91%) ⬇️
superset/key_value/commands/delete.py 0.00% <0.00%> (-87.88%) ⬇️
superset/key_value/commands/delete_expired.py 0.00% <0.00%> (-84.00%) ⬇️
superset/dashboards/commands/importers/v0.py 15.62% <0.00%> (-76.25%) ⬇️
... and 288 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@hughhhh hughhhh changed the title Ssh manager config feat(ssh-tunnel): ssh manager config + feature flag Nov 24, 2022
@pull-request-size pull-request-size bot added size/L and removed size/M labels Nov 25, 2022
@hughhhh hughhhh marked this pull request as ready for review November 29, 2022 16:31
# # `server` return value
# return "127.0.0.1"

SSH_TUNNEL_MANAGER = None
Copy link
Member

Choose a reason for hiding this comment

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

Should we provide a default impl here?

@@ -20,16 +20,24 @@
from flask_appbuilder.models.sqla import Model
from marshmallow import ValidationError


from superset import app, is_feature_enabled
Copy link
Member

Choose a reason for hiding this comment

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

Don't directly import app here. Instead, use flask.current_app

from superset.commands.base import BaseCommand
from superset.dao.exceptions import DAOCreateFailedError
from superset.databases.dao import DatabaseDAO
from superset.databases.ssh_tunnel.commands.exceptions import SSHTunnelCreateFailedError
from superset.databases.ssh_tunnel.dao import SSHTunnelDAO

config = app.config
ssh_tunnel_manager = config["SSH_TUNNEL_MANAGER"]
Copy link
Member

Choose a reason for hiding this comment

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

Put this inside the command's init() and leverage current_app.config

# FIREWALL (only port 22 is open)

# ----------------------------------------------------------------------
# class SSHManager:
Copy link
Member

Choose a reason for hiding this comment

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

The default manager should leverage the app_init pattern. So, inside the AppInitializer, the actual manager would be instantiated and then would have init_app(app: Flask) invoked on it

@@ -33,6 +34,9 @@

logger = logging.getLogger(__name__)

config = app.config
ssh_tunnel_manager = config["SSH_TUNNEL_MANAGER"]
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as before. We should be getting the SSHManager from the current_app

Copy link
Member

@craig-rueda craig-rueda left a comment

Choose a reason for hiding this comment

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

@hughhhh hughhhh force-pushed the create-sshtunnelconfig-tbl branch 2 times, most recently from 225ea11 to 466703a Compare November 29, 2022 23:56

# def mutator(self, ssh_tunnel_params: Dict[str, Any]) -> Dict[str, Any]:
# # override any ssh tunnel configuration object
# raise NotImplemented()
Copy link
Member

Choose a reason for hiding this comment

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

do we need to make these two methods required? They seems more like nice to haves.

logger = logging.getLogger(__name__)


class CreateSSHTunnelCommand(BaseCommand):
def __str__(self) -> str:
return super().__str__()
Copy link
Member

Choose a reason for hiding this comment

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

isn't this redundant?

# using the config.SSH_TUNNEL_MANAGER
return
if is_feature_enabled("SSH_TUNNELING") and ssh_tunnel_manager:
ssh_tunnel_manager.validate(self._properties)
Copy link
Member

Choose a reason for hiding this comment

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

is this the only validation that we want to do here?

else:
# do look up in table for using database_id
try:
with sshtunnel.open_tunnel(**ssh_params) as server:
Copy link
Member

Choose a reason for hiding this comment

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

are there any known errors from the library that we need to catch here?

@hughhhh hughhhh force-pushed the create-sshtunnelconfig-tbl branch from 1a1141a to b25ff51 Compare December 2, 2022 00:47
@hughhhh hughhhh force-pushed the create-sshtunnelconfig-tbl branch 5 times, most recently from 2ba07f5 to 1f57d4a Compare December 7, 2022 21:33
@pull-request-size pull-request-size bot added size/M and removed size/L labels Dec 14, 2022
@hughhhh hughhhh force-pushed the ssh-manager-config branch 5 times, most recently from dde7f64 to 19f9368 Compare December 15, 2022 04:19
@hughhhh hughhhh merged commit c5c50ed into create-sshtunnelconfig-tbl Dec 15, 2022
@mistercrunch mistercrunch deleted the ssh-manager-config branch March 26, 2024 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants