[Security Solution] Render user profile avatars on notes#280902
Open
orangecola wants to merge 3 commits into
Open
[Security Solution] Render user profile avatars on notes#280902orangecola wants to merge 3 commits into
orangecola wants to merge 3 commits into
Conversation
…stions `userProfiles.suggest` defaults to 10 results when no size is given, which is too few for consumers that match a stored display name against the full set of profiles rather than searching interactively - note avatars being the case that surfaced this. Request 100, the maximum the security plugin accepts.
`EuiAvatar` renders `imageUrl` as a CSS background-image rather than an `<img>` element, so both profile-image assertions were querying for an element that is never rendered and failing. Assert on the background image instead, matching how kbn-user-profile-components tests the same component.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses #280901.
Note author avatars in the Security Solution were rendered with a bare
<EuiAvatar name={displayName} />, so they showed auto-generated initials in an auto-assigned color and ignored the avatar the user had configured in their Kibana user profile. The same person appeared with their real profile image in Cases and the user menu, but with generated initials on their notes.This PR adds a shared
NoteAvatarcomponent that resolves the note's stored display name back to a user profile and rendersUserAvatarfrom@kbn/user-profile-components(image if set, otherwise the profile's own initials and color), falling back to the previous generated avatar when no profile matches — deleted users, imported notes, unauthenticated writes.Call sites switched over:
public/notes/components/notes_list.tsxpublic/notes/pages/note_management_page.tsxpublic/timelines/components/notes/participants.tsxpublic/timelines/components/open_timeline/note_previews/index.tsxpublic/timelines/components/timeline/tabs/notes/index.tsxWhy matching is done on the display name
Notes do not persist a user profile identifier. The server stores only a display string:
With no
uidon the note, the client has nothing to look up by, soNoteAvatarmatchesgetUserDisplayName(profile.user) === note.updatedByagainst the profiles returned by the existinguseSuggestUsershook.Second commit: raising the suggestion cap
While verifying the first commit against a real stack I found it only worked for very small deployments.
useSuggestUsers({ searchTerm: '' })callsGET /internal/detection_engine/users/_find, and that route calledsecurity.userProfiles.suggest()without asize— which defaults toDEFAULT_SUGGESTIONS_COUNT = 10. Measured on a 9.4.4 stack with two users holding profile images and three notes between them:suggestUsers('')At 16 users the author of two of the three notes fell outside the 10 returned profiles and kept the buggy fallback. The second commit passes an explicit
size: 100(MAX_SUGGESTIONS_COUNT, the ceiling the security plugin enforces — above itsuggestthrows).Reviewers please note this is a mitigation, not a cure, and it has two consequences worth weighing:
/internal/detection_engine/users/_findis shared with alert assignee suggestions. Because the route passesrequiredPrivileges, the security plugin fetchesmax(size * 2, …)profiles and then privilege-filters them, so this raises that request from 20 to 200 profiles per call. The result is cached client-side withstaleTime: Infinity, but it is a real increase per fresh fetch.Two further limits are inherent to name matching and not fixed here: users sharing a display name are indistinguishable, and because the note stores whatever
getUserDisplayNamereturned at write time, later changing a user'sfull_namesilently breaks the match for their existing notes.The durable fix is to persist the author's profile
uidon the note saved object and resolve it withbulkGetUserProfiles, keeping name matching only as a fallback for notes written before that change. That needs a saved-object model version and server-side work, so it is left for a follow-up — happy to take direction on whether this should wait for it.Third commit: fixing two assertions that could never pass
The
NoteAvatarandNotesListtests added in the first commit both asserted the profile image like this:EuiAvatarrendersimageUrlas a CSSbackground-imageand never emits an<img>element, soquerySelector('img')is alwaysnulland both tests fail. They now assert on the background image, matching howkbn-user-profile-componentstests the same component. The component code was correct — only the assertions were wrong.Testing
NoteAvatar: profile image, profile initials + color, fallback when no profile matches, and?when the display name is missing.sizeis passed touserProfiles.suggest.Run locally against this branch:
public/notes(incl.note_avatar,notes_list)public/timelines(participants, note previews, notes tab)suggest_user_profiles_routetype_check --project .../security_solutiontscexited 0End-to-end verification: built Kibana 9.6.0 from this branch against a version-matched ES 9.6.0-SNAPSHOT on a trial license, with two users holding uploaded profile images and three notes between them. The notes management page "Created by" column, the timeline Notes tab, and the "Created by" / "Participants" panels all render the real profile images; on 9.4.4 the same scenario renders generated letter avatars (
E,SC). Screenshots below.Checklist