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: Restrict certain users from production environments #2530

Merged
merged 5 commits into from
Dec 6, 2023

Conversation

DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Dec 4, 2023

What does this PR do?

  • Adds an additional check on login, to ensure users can access production environment

Why?

As we sync the users table across environments, this means all users can access production. Generally this is what we want as "real" users live on production and this allows them to access test and staging environments - all good.

The catch is that occasionally we have a set of users who we do not wish to grant access to production - for example the user accounts associated with the recent pen test, or certain sets of users with "demo" access (until we have these roles set up). This is not a common occurrence or user type, but it feels like a sensible restriction to put in place restrictions here as a bit of a guard rail.

TODO

email: string,
env?: string,
): Promise<boolean> => {
const isStagingOnlyUser = await $api.user.isStagingOnly(email);
Copy link
Contributor Author

@DafyddLlyr DafyddLlyr Dec 4, 2023

Choose a reason for hiding this comment

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

Why is this it it's own function and not a field added to user.getByEmail()?

I appreciate that this does mean an additional query but the user.isStagingOnly property is only ever needed here once on login.

If we added this to the more general query, we'd be polluting our User type with a meaningless property that has no value outside of this context.

This is one of those cases where the full database model will not match the model we want in-application.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sesne to me, thanks for explanation!

@DafyddLlyr DafyddLlyr force-pushed the dp/staging-only-users branch from acee5a5 to 2ca9f1c Compare December 4, 2023 11:02
@DafyddLlyr DafyddLlyr marked this pull request as ready for review December 4, 2023 11:29
@DafyddLlyr DafyddLlyr requested a review from a team December 4, 2023 11:29
Copy link

github-actions bot commented Dec 4, 2023

Removed vultr server and associated DNS entries

DafyddLlyr added a commit to theopensystemslab/planx-core that referenced this pull request Dec 4, 2023
@@ -7,6 +7,8 @@ CREATE TEMPORARY TABLE sync_users (
created_at timestamptz,
updated_at timestamptz,
is_platform_admin boolean
-- ,
-- is_staging_only boolean
Copy link
Member

Choose a reason for hiding this comment

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

are these lines intended to be comment-out in sync script?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep - it's a bit of chicken and egg situation - we can't sync from the new column until it exists on prod.

Once this is across there'll be a quick PR uncommenting these lines (plus any potential sync script fixes as it's currently untestable).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(And the catch here is that pizzas will fail unless it's commented out as they can't sync)

email: string,
env?: string,
): Promise<boolean> => {
const isStagingOnlyUser = await $api.user.isStagingOnly(email);
Copy link
Member

Choose a reason for hiding this comment

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

Makes sesne to me, thanks for explanation!

@DafyddLlyr DafyddLlyr merged commit 1c3fc32 into main Dec 6, 2023
12 checks passed
@DafyddLlyr DafyddLlyr deleted the dp/staging-only-users branch December 6, 2023 09:47
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