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: Setup metabase_read_only role #2856

Merged
merged 6 commits into from
Mar 13, 2024
Merged

Conversation

DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Mar 4, 2024

What does this PR do?

  • Sets up the metabase_read_only database role
  • Ensures that Metabase can only read a small subset of tables and views, and has no write permissions
  • Please see included doc file for more context and detail

Testing

I've gone ahead and set up the user and permissions outlined here on staging Metabase so that we can test a little (I'll revoke the changes before merging this PR).

It works as expected - for example, I can read sessions_summary, but running SQL to select from lowcal_sessions gives a permissions error.

image image

Copy link

github-actions bot commented Mar 4, 2024

Removed vultr server and associated DNS entries

Comment on lines 16 to 23
The `metabase_read_only` role is granted to the `metabase_user` database user, which is manually set up on both staging and production with the following SQL -

```sql
CREATE USER metabase_user WITH PASSWORD <$PASSWORD>;
GRANT metabase_read_only TO metabase_user;
```

The password for Staging and Production databases can be found the OSL 1Password account.
Copy link
Contributor Author

@DafyddLlyr DafyddLlyr Mar 4, 2024

Choose a reason for hiding this comment

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

This is the solution I'm proposing for setting up the metabase_user user. Not perfect but hopefully workable?

Once this PR is merged I'll manually run the above SQL on staging and prod and save passwords to 1Password. We could put them in Pulumi secrets, but my concern would be that as there's no code-reference to them they would be sensible candidates to "tidy up" accidentally.

Chances are it will exist on staging and production and we'll never really need to deal with it locally.

Copy link
Member

Choose a reason for hiding this comment

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

This seems like a good thoughtful approach and will make for less-hassle rotation if necesary in future, but not entirely following based on this doc how this user relates to existing metabase user role provisioned/managed by Pulumi - eg https://github.com/theopensystemslab/planx-new/blob/main/infrastructure/application/index.ts#L100

At minimum, do we need to think about more distinctive naming? At most, is there a way to consolidate responsibilities of each into a single user role?

Copy link
Contributor Author

@DafyddLlyr DafyddLlyr Mar 5, 2024

Choose a reason for hiding this comment

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

Yeah this caught me out initially also.

This section of code is generating a role and user to be used for the MB_DB_CONNECTION_URI env var (docs), which is responsible for the schema and role of the internal metabase db, where dashboards etc are stored - not the PlanX schema where data is accessed via Hasura / ShareDB.

image

I'll add a code comment to Pulumi to make this explicit, as well as document this in the "how to" in this PR.

Do you think this would be enough?

Copy link
Member

Choose a reason for hiding this comment

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

Yep happy with extra docs here !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see 4dd9b14

@DafyddLlyr DafyddLlyr force-pushed the dp/metabase-read-only-user branch from 047e9ee to b27deee Compare March 4, 2024 17:37
@DafyddLlyr DafyddLlyr requested a review from a team March 4, 2024 17:44
@DafyddLlyr DafyddLlyr marked this pull request as ready for review March 4, 2024 17:44
@DafyddLlyr
Copy link
Contributor Author

Comment on lines 8 to 10
GRANT SELECT ON public.flows TO metabase_read_only;
GRANT SELECT ON public.published_flows TO metabase_read_only;
GRANT SELECT ON public.teams TO metabase_read_only;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might actually be redundant - I think there might be enough information in the views? If it's simpler to remove this I'm all for it 👍

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'll contact Ollie today, or manually check Metabase, to see if this is required 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed - these aren't currently used. See https://opensystemslab.slack.com/archives/C5Q59R3HB/p1709720214019159 (OSL Slack)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update - in order to move this forward I've granted access to the tables analytics and analytics_logs. They are safe to read, and currently used by SQL questions. The aim would be that once we migrate to GUI questions, we can rely on summary tables and tidy this up.

@zz-hh-aa Indicated that lowcal_sessions is used, which we do not want, so I've intentionally left this out to force a transition to submission_services_summary.

If this breaking change it too harsh, we can toggle the PG username/password used in Metabase until this is resolved.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I've removed lowcal_sessions as a source from all the questions now anyway, and am only using summary tables + analytics or analytics_logs, so don't think anything should break! All good on my end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah that's perfect @zz-hh-aa thanks very much!

Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

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

All looks good to me - thanks for extra docs!

Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

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

Newest changes look good - all for not exposing lowcal_sessions and just toggling at Metabase level until all migrated to new view 👍

@DafyddLlyr
Copy link
Contributor Author

Perfect - thanks very much @jessicamcinchak for the speedy re-review here ✅

@DafyddLlyr DafyddLlyr merged commit 85551d7 into main Mar 13, 2024
12 checks passed
@DafyddLlyr DafyddLlyr deleted the dp/metabase-read-only-user branch March 13, 2024 11:26
@DafyddLlyr DafyddLlyr mentioned this pull request Mar 13, 2024
8 tasks
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.

3 participants