Skip to content

Conversation

@sdether
Copy link

@sdether sdether commented Aug 31, 2021

This commit changes connection behavior from storing the database
connection name to using the database alias mapped by SQL Explorer
instead.

The reason for this change is two-fold:

  1. Views take the connection name as input, allowing anyone who knows
    Django connection names to query those databases, even if SQL
    does not expose the connection directly.
  2. Query stores the connection name, which means that if the
    Django connection name changes or a different connection should
    be used (for example, one with reduced permissions) the stored
    Query will either stop working or at least continue using the old
    connection

This change modifies ExplorerConnections from being a dictionary
that proxies the Django connection dictionary to a dictionary-like
object that uses EXPLORER_CONNECTIONS to lookup and validate
the requested connection alias.

In addition all code that used to the EXPLORER_CONNECTIONS value
now uses the key instead.

For backwards compatibility, a migration will back-populate the alias
into Query instances (and fail if the mapping no longer exists),
EXPLORER_DEFAULT_CONNECTION is re-written on start-up to use the
alias in case it still uses the Django Connection name and
ExplorerConnections will still accept a Django Connection name as
long as that name is exposed by some alias in EXPLORER_CONNECTIONS.

… as lookup

This commit changes connection behavior from storing the database
connection name to using the database alias mapped by SQL Explorer
instead.

The reason for this change is two-fold:
1) Views take the connection name as input, allowing anyone who knows
   Django connection names to query those databases, even if SQL
   does not expose the connection directly.
2) `Query` stores the connection name, which means that if the
   Django connection name changes or a different connection should
   be used (for example, one with reduced permissions) the stored
   Query will either stop working or at least continue using the old
   connection

This change modifies `ExplorerConnections` from being a dictionary
that proxies the Django connection dictionary to a dictionary-like
object that uses `EXPLORER_CONNECTIONS` to lookup and validate
the requested connection alias.

In addition all code that used to the `EXPLORER_CONNECTIONS` value
now uses the key instead.

For backwards compatibility, a migration will back-populate the alias
into `Query` instances (and fail if the mapping no longer exists),
`EXPLORER_DEFAULT_CONNECTION` is re-written on start-up to use the
alias in case it still uses the Django Connection name and
`ExplorerConnections` will still accept a Django Connection name as
long as that name is exposed by some alias in `EXPLORER_CONNECTIONS`.
@marksweb marksweb self-requested a review August 31, 2021 06:59
marksweb
marksweb previously approved these changes Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants