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

Feature/manage databases #250

Merged
merged 34 commits into from
Sep 5, 2024
Merged

Feature/manage databases #250

merged 34 commits into from
Sep 5, 2024

Conversation

michaeljcollinsuk
Copy link
Contributor

@michaeljcollinsuk michaeljcollinsuk commented Aug 22, 2024

Adds ability for users to grant access to databases. This initial implementation allows:

  • Superuser to grant access to any table
  • Users with grantable access to grant access to the table

To run locally:

  • Reinstall dependencies
  • Run python manage.py migrate
  • Ensure .env file is up to date. If there are errors related to missing values, let me know and I will check my file and update the stored env file in 1Password
  • Run the server with make serve-sso or use the debugger in VS code
  • Login, attempt to grant your user access to some tables
  • With the correct access, you should then be able to query the table within the embedded Quicksight
  • You can also revoke access to a user, or update access

Limitations:

  • Grantable permissions are not sent - I am working on this now

TODO/next steps:

  • Add unit tests. I will do these in a separate PR in order to get this to the development environment first for testing, in case there are wholesale changes required
  • Documentation - same as above
  • UI improvements - e.g. things like breadcrumbs/back button to help with navigation, hiding the management access button if user has no grant permissions
  • Additional views to allow filtering tables/database by what the user has access
  • Add production settings - we will need this before deploying to prod
  • Refactoring - not a priority but there are changes that I have in mind when possible

Copy link
Contributor

@jamesstottmoj jamesstottmoj left a comment

Choose a reason for hiding this comment

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

Have tested locally. Assigned myself as a super user and could assign permissions, then see the data in quicksight. Then revoked permissions and could no longer see table.

A couple of questions.

Will a user who doesn't have grantable permissions be able to see the database access tab? If not, I could see the tab as a non-superuser.

If they should be able to see it, you may want to hide the grant permissions button from those who shouldn't be able to grant permissions.

For granting/revoking lf opt in permissions, for safety, it may be worth implementing something similar to what's in the following PR. You can list the opt ins of a principal and use the database name to decide what can be revoked or added. There may be a better way to code it but it at least gives us a bit of security when performing opt in changes.

Other than that, fantastic work!

@michaeljcollinsuk
Copy link
Contributor Author

Will a user who doesn't have grantable permissions be able to see the database access tab? If not, I could see the tab as a non-superuser.

Yes, currently they will be able to see the tab and also see all the databases - is this what you saw. I was thinking of adding a tab so you can switch between dbs/tables you have access to and all dbs. But didnt get round to it.

If they should be able to see it, you may want to hide the grant permissions button from those who shouldn't be able to grant permissions.

Agreed - another thing I wanted to add but didnt get round to/forgot to do

For granting/revoking lf opt in permissions, for safety, it may be worth implementing something similar to what's in the following PR. You can list the opt ins of a principal and use the database name to decide what can be revoked or added. There may be a better way to code it but it at least gives us a bit of security when performing opt in changes.

Is this specifically about removing the hybrid mode opt-in? I'm a little unsure about this so might be better to discuss. But my thinking is that it shouldnt be necessary as when updating permissions, the opt in is deleted, and then reapplied. And when the access is revoked we always know that we need to revoke the opt-in also.

Methods to grant access to databases and tables.
Also update glue service to add method to return target table data.
A user should only be able to grant access to another user that they
themselves have. If the user is a superuser, they can grant any access.
Dont save the model if the API call fails. Also
use the values from the selected accesslevel model
when making API call.
Move logic away from model save methods, and on
to methods on the model that are called by the
access forms.
Use DB transactions to keep the database state in
sync with lake formation permissions.
Add validation to check that selected grantable
are valid based on standard permissions.
Refactors code to remove need for duplicate access levels with
grantable flag.
Remove the grantable field as no longer necessary
When a user is granted access to a table, grant the user DESCRIBE access
to the database with grantable permission. This is because having access
to describe the database only allows you to see the name of the DB.
Only show the actions column to manage/revoke table access if the user
is either a superuser, or has grantable permissions on the table.
Copy link
Contributor

@jamesstottmoj jamesstottmoj left a comment

Choose a reason for hiding this comment

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

Fantastic work!

@michaeljcollinsuk
Copy link
Contributor Author

Merging despite the failed scan. See bug ticket ministryofjustice/analytical-platform#5251

@michaeljcollinsuk michaeljcollinsuk merged commit eeec73c into main Sep 5, 2024
20 of 21 checks passed
@michaeljcollinsuk michaeljcollinsuk deleted the feature/manage-databases branch September 5, 2024 15:41
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