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

Connection write mode option #535

Conversation

fabscav
Copy link
Contributor

@fabscav fabscav commented Jan 31, 2021

This PR adds a new option to connections: write mode, It can have one of three values:

  • Enabled (default): Current behavior, full write access.
  • Confirm: All queries that change data or structure have to be confirmed.
  • Read-only: Queries that change data or structure are not allowed.

connection_writemode

@@ -121,6 +145,7 @@
import QueryEditorStatusBar from './editor/QueryEditorStatusBar.vue'
import rawlog from 'electron-log'
const log = rawlog.scope('query-editor')
const writeVerbs = ["alter", "create", "delete", "drop", "insert", "rename", "truncate", "update", "upsert"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

My concern is that there could be select statements containing some of these words legitimately. We already have a dependency on sql-query-identifier, we should probably rely on that.

I think I'd also be uncomfortable (right now) saying that beekeeper can prevent write operations, I think warning is fine, but sql-query-identifier would probably need some new features.

read-only mode should probably be implemented database-by-database, for example in postgres - brianc/node-postgres#569

To do that we'd need to run a statement before each query is executed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the component to utilize the sql-query-identifier instead of the verb array. However I did notice it doesn't mark alter table queries as modifications.

Implementing write-protection on a connection-level should be possible. SQLite and SQL Server support this as a connection param afaik. Others such as MySQL would probably require the query to be wrapped in a read only transaction.

I could look into implementing it, but if you're reluctant with implementing a read-only mode in general I'd be fine with dropping this PR as well. Tbh I only need this functionality to be present in my fork in order to start using beekeeper in production environments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm 100% open to this feature. I think it would be a great feature.

Yes, if we can do read-only mode at the connection-level that would be fantastic, although I know that's a lot of work.

We could use the following:

  • user selects read-only
  • if connection support it, works as expected
  • If not, we provide a warning that it might not be 100%, and implement at the app level

For 'warn me' mode:

  • provide a warning on the connection screen that the feature is in beta and might not be 100%.

If we do those things, I'm good with it.

With alter table -- ideally we can add basic detection to sql-query-identifier

@rathboma
Copy link
Collaborator

Hey! I think this is a good draft, but it's been a while since you've been working on it. I think it best I close it for now, eventually we'll come back to this as part of a real permissions system.

@rathboma rathboma closed this Jul 23, 2021
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.

None yet

2 participants