Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

SCIM: Restrict user fields on the UI#48816

Merged
vdavid merged 2 commits intomainfrom
dv/scim-restrict-user-fields-on-ui
Mar 8, 2023
Merged

SCIM: Restrict user fields on the UI#48816
vdavid merged 2 commits intomainfrom
dv/scim-restrict-user-fields-on-ui

Conversation

@vdavid
Copy link
Contributor

@vdavid vdavid commented Mar 7, 2023

There are three user attributes on the profile and emails pages that SCIM interferes with:

  • username
  • display name
  • email addresses

These fields are currently editable. But for SCIM-controlled users, the identity provider is the source of truth, and these fields shouldn't be editable on the UI.
This PR disables these fields for SCIM-controlled users and adds a note that that attributes are SCIM-controlled.

For the design reviewer: check out the screenshots below. I want to make sure that I'd using the right style of a notification (blue/info, rather than yellow/warning or other), that the text sounds right, and that the disabled fields are fine. I can include more screenshots or a short vid to show the cursors, etc.

Profile page for a non-SCIM-controlled vs. SCIM-controlled user—left side: (unchanged) enabled controls, right side: disabled controls:

CleanShot 2023-03-07 at 14 10 22@2x CleanShot 2023-03-07 at 14 10 47@2x

Emails page for a non-SCIM-controlled vs. SCIM-controlled user—left side: (unchanged) enabled controls, right side: disabled controls:

CleanShot 2023-03-07 at 14 51 59@2x CleanShot 2023-03-07 at 14 51 29@2x

The changes:

  • Added a SCIMControlled (bool) field on the user model
  • Populating the field based on the user_external_accounts content
  • Added new field to the GraphQL query
  • Requesting the new field in the user admin page query
  • Disabling the UI based on the value

Test plan

  • Design review
  • CI should pass

@cla-bot cla-bot bot added the cla-signed label Mar 7, 2023
@vdavid vdavid force-pushed the dv/scim-restrict-user-fields-on-ui branch from f038088 to 545aaed Compare March 7, 2023 14:00
@sg-e2e-regression-test-bob
Copy link

sg-e2e-regression-test-bob commented Mar 7, 2023

Bundle size report 📦

Initial size Total size Async size Modules
0.00% (0.00 kb) 0.01% (+1.73 kb) 0.02% (+1.73 kb) 0.00% (0)

Look at the Statoscope report for a full comparison between the commits 34600cb and 012d347 or learn more.

Open explanation
  • Initial size is the size of the initial bundle (the one that is loaded when you open the page)
  • Total size is the size of the initial bundle + all the async loaded chunks
  • Async size is the size of all the async loaded chunks
  • Modules is the number of modules in the initial bundle

@vdavid vdavid requested a review from a team March 7, 2023 14:02
@vdavid vdavid force-pushed the dv/scim-restrict-user-fields-on-ui branch from 245f2bc to d48240f Compare March 7, 2023 14:19
@vdavid vdavid force-pushed the dv/scim-restrict-user-fields-on-ui branch from d48240f to 3acdb5a Compare March 7, 2023 14:22
InvalidatedSessionsAt time.Time
TosAccepted bool
Searchable bool
SCIMControlled bool
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 is similarly controversial to https://github.com/sourcegraph/sourcegraph/pull/48727 (see PR desc.), but I think this is the right way to do it. Being SCIM-controlled is an inherent-enough property of a user to justify having a boolean about it on its model. Besides, this is a decision that's easy to change later, so I'd rather move fast with it.

@vdavid vdavid force-pushed the dv/scim-restrict-user-fields-on-ui branch from fd5fb71 to 34600cb Compare March 7, 2023 15:02
@vdavid vdavid marked this pull request as ready for review March 7, 2023 15:02
@vdavid vdavid requested review from a team and chwarwick March 7, 2023 15:02
Copy link
Contributor

@chwarwick chwarwick left a comment

Choose a reason for hiding this comment

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

Is there a follow up item/PR to disallow these edits server side? While disabling them via the UI is good, the mutations are still able to be directly called and are easily discoverable and documented.

@vdavid
Copy link
Contributor Author

vdavid commented Mar 7, 2023

@chwarwick

Is there a follow up item/PR to disallow these edits server side? While disabling them via the UI is good, the mutations are still able to be directly called and are easily discoverable and documented.

I see no huge harm done if that happens. I mean, practically, users with the right privileges can already make whatever changes they want to users (though updateUser, addUserEmail, setUserEmailVerified, and so on). I see no huge harm done if this is also allowed for SCIM-controlled users.

Copy link
Contributor

@chwarwick chwarwick left a comment

Choose a reason for hiding this comment

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

I do not see any issues with these code changes. I do continue to believe that only applying these restrictions via UI is problematic, and that they should be enforced server side as well.

Copy link
Contributor

@kopancek kopancek left a comment

Choose a reason for hiding this comment

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

Added a comment with a suggestion for different approach, let me know what you think

organizations: { nodes: [] },
permissionsInfo: null,
tags: [],
scimControlled: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we could use the user tags for this? E.g. if the user is scim controlled, we can add a tag named scim to the user in the database. Every time we read the user object, the tags will be populated. It would make the blast radius much smaller as well and we already did conditional treatment of users with different tags in the past. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I like that it decreases the interface of the User model, but my problem with it is that it denormalizes data (source of truth for "is scim-controlled" becomes ambiguous). Maybe if we just add the additional, fake "scim" tag to the user model when loading it based on the status of user_external_accounts, but then it's rather hacky. :/ I think from these options, I prefer the current one (honestly, without status quo bias).

@vdavid
Copy link
Contributor Author

vdavid commented Mar 8, 2023

@chwarwick, I've added it to the nice-to-haves to restrict user field editing on the back end from SCIM-controlled users.

@vdavid vdavid merged commit 6ed8333 into main Mar 8, 2023
@vdavid vdavid deleted the dv/scim-restrict-user-fields-on-ui branch March 8, 2023 09:34
Comment on lines +1195 to +1208
SELECT u.id,
u.username,
u.display_name,
u.avatar_url,
u.created_at,
u.updated_at,
u.site_admin,
u.passwd IS NOT NULL,
u.tags,
u.invalidated_sessions_at,
u.tos_accepted,
u.searchable,
(SELECT COUNT(user_id) FROM user_external_accounts WHERE user_id=u.id AND service_type = 'scim') >= 1 AS scim_controlled
FROM users u %s`, query)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if you can simplify this to not do a SQL query on every row, something like:

Suggested change
SELECT u.id,
u.username,
u.display_name,
u.avatar_url,
u.created_at,
u.updated_at,
u.site_admin,
u.passwd IS NOT NULL,
u.tags,
u.invalidated_sessions_at,
u.tos_accepted,
u.searchable,
(SELECT COUNT(user_id) FROM user_external_accounts WHERE user_id=u.id AND service_type = 'scim') >= 1 AS scim_controlled
FROM users u %s`, query)
SELECT u.id,
u.username,
u.display_name,
u.avatar_url,
u.created_at,
u.updated_at,
u.site_admin,
u.passwd IS NOT NULL,
u.tags,
u.invalidated_sessions_at,
u.tos_accepted,
u.searchable,
COUNT(uea.service_type) > 0 AS scim_controlled
FROM users u
LEFT JOIN user_external_accounts uea
ON u.id = uea.user_id
AND uea.service_type = 'scim'
%s`, query)

Copy link
Contributor Author

@vdavid vdavid Mar 8, 2023

Choose a reason for hiding this comment

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

Fair point, I’ll take care of it in a follow-up PR!

@almeidapaulooliveira
Copy link
Contributor

Some insights for the design:

  • I'm unsure if the 'site-admin' Alert is part of this scope, but I didn't see that message as a warning. We also can use a simple component than an Alert. I quickly sketched here:
    sScreen Shot 2023-03-08 at 1 09 31 PM

@almeidapaulooliveira
Copy link
Contributor

almeidapaulooliveira commented Mar 8, 2023

I want to make sure that I'd using the right style of a notification (blue/info, rather than yellow/warning or other), that the text sounds right, and that the disabled fields are fine.

All looks fine.

@vdavid
Copy link
Contributor Author

vdavid commented Mar 8, 2023

No, the site admin alert is not part of the scope. Please create a separate front-end issue about it if you think someone should fix it later.

Thanks for the review @almeidapaulooliveira!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restrict user management for SCIM-controlled users

6 participants