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

Fix user ingestion for GitlabOrgDiscoveryEntityProvider for GitLab.com #18889

Merged
merged 37 commits into from Sep 12, 2023

Conversation

sbarrypoppulo
Copy link
Contributor

@sbarrypoppulo sbarrypoppulo commented Aug 1, 2023

Hey, I just made a Pull Request!

Fixes an issue with user ingestion for GitLab.com by making the entity provider aware of the group config parameter and scoping the provider to this group. Previously, the Gitlab Org data entity provider attempted to fetch all users from Gitlab.com via the /users REST endpoint, which was undesirable.

Switched the user fetching for Gitlab.com to GraphQL API, scoped to the root Gitlab group for the Org, or via existing /users REST API for Gitlab Self-Managed.

Groups are fetched via GraphQL API for Gitlab.com and via existing /groups REST API for Gitlab Self-Managed.

Group members are fetched via existing GraphQL API for both instance types

Example provider configuration used to test with:

catalog:
  providers:
    gitlab:
      gitlabSaasOrgData:
        host: gitlab.com
        orgEnabled: true
        group: org/teams
        rules:
          - allow: [Group, User]

Relates to:

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

angom1 and others added 17 commits July 14, 2023 11:43
Signed-off-by: angom1 <angom@poppulo.com>
Signed-off-by: angom1 <angom@poppulo.com>
Signed-off-by: angom1 <angom@poppulo.com>
Signed-off-by: angom1 <angom@poppulo.com>
Signed-off-by: angom1 <angom@poppulo.com>
Signed-off-by: angom1 <angom@poppulo.com>
Signed-off-by: angom1 <angom@poppulo.com>
Signed-off-by: angom1 <angom@poppulo.com>
Signed-off-by: angom1 <angom@poppulo.com>
Signed-off-by: angom1 <angom@poppulo.com>
Signed-off-by: angom1 <angom@poppulo.com>
Signed-off-by: Stephen Barry <sbarry@poppulo.com>
… to SaaS full mutation test

Signed-off-by: Stephen Barry <sbarry@poppulo.com>
Signed-off-by: Stephen Barry <sbarry@poppulo.com>
Signed-off-by: Stephen Barry <sbarry@poppulo.com>
Signed-off-by: Stephen Barry <sbarry@poppulo.com>
@sbarrypoppulo sbarrypoppulo requested review from a team as code owners August 1, 2023 14:42
@github-actions github-actions bot added documentation Improvements or additions to documentation area:catalog Related to the Catalog Project Area labels Aug 1, 2023
@backstage-goalie
Copy link
Contributor

backstage-goalie bot commented Aug 1, 2023

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/plugin-catalog-backend-module-gitlab plugins/catalog-backend-module-gitlab minor v0.2.7-next.2

@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2023

Uffizzi Preview deployment-33585 was deleted.

@sbarrypoppulo
Copy link
Contributor Author

Tested on GitLab Self-Managed (16.1.1) without group parameter:

  • All User entities ingested from GitLab instance (all users have email on profile)
  • All Group entities ingested from GitLab instance

Tested on GitLab.com w/ group parameter configured

  • User entities ingested for users who are direct members of descendant GitLab groups of the configured group
  • Group entities ingested for descendant GitLab groups of the configured group

@github-actions
Copy link
Contributor

github-actions bot commented Aug 9, 2023

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!

@github-actions github-actions bot added the stale label Aug 9, 2023
@sbarrypoppulo
Copy link
Contributor Author

sbarrypoppulo commented Aug 10, 2023

@freben @alde Would appreciate some reviews here, and if you can remove the stale label 🙏

I'm not 100% sure on the changeset version for this change. My gut feeling is minor, but will await your feedback. Thanks!

@github-actions github-actions bot removed the stale label Aug 10, 2023
sbarrypoppulo and others added 3 commits August 22, 2023 08:26
Co-authored-by: Jamie Klassen <jklassen@vmware.com>
Signed-off-by: sbarrypoppulo <101636916+sbarrypoppulo@users.noreply.github.com>
…endantGroupsResponse

Signed-off-by: Stephen Barry <sbarry@poppulo.com>
@sbarrypoppulo
Copy link
Contributor Author

Thanks once again for the review @jamieklassen and the very helpful suggesstions 💪

I think we're very close here now, if you can take another look and hopefully over to @alde / @freben

We're hoping we can get this in for 1.18 release, as it's preventing us from enabling sign-in resolvers for user identity, which is blocking various options and plugins on out adoption journey 🤞

Copy link
Member

@jamieklassen jamieklassen left a comment

Choose a reason for hiding this comment

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

awesome

@cthtrifork
Copy link
Contributor

Very nice work! Also hoping for a 1.18.x release!

@mickfeech
Copy link

Great work! Anxiously waiting for the merge to use it!

@sbarrypoppulo
Copy link
Contributor Author

sbarrypoppulo commented Aug 28, 2023

@freben Any chance of a review here? Seems a few folks are awaiting this fix 😄

order to limit the ingestion to a group within your organisation. `Group`
entities will only be ingested for the configured group, or it's descendant groups,
but not any ancestor groups higher than the configured group path. Only groups
which contain members will be ingested.
Copy link
Member

Choose a reason for hiding this comment

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

Was this a conscious choice or "for technical reasons"? Seems like an unnecessary limitation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As for the level within the hierarchy, it made sense that if you configure a group path, then the only groups ingested would be at that group level, or lower. Rather than in the other direction, higher up the hierarchy. Regarding ingestion of only groups with members, this was my understanding of how this always worked, but let me double check on that assumption.


For gitlab.com, when `orgEnabled: true`, the `group` parameter is required in
order to limit the ingestion to a group within your organisation. `Group`
entities will only be ingested for the configured group, or it's descendant groups,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
entities will only be ingested for the configured group, or it's descendant groups,
entities will only be ingested for the configured group, or its descendant groups,

plugins/catalog-backend-module-gitlab/src/lib/client.ts Outdated Show resolved Hide resolved
@@ -136,16 +236,26 @@ export class GitLabClient {
continue;
}

memberIds.push(
...response.data.group.groupMembers.nodes
.filter(n => n.user)
Copy link
Member

Choose a reason for hiding this comment

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

I want to call out the deletion of this one. I vaguely remember it being added for very good reason - it could be the case that the user was null sometimes in the response, for some corner cases. You may want to retain that check, right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me take another look here. This rings a bell, think I brought up this issue in #17735 and it slipped my mind

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @freben, would adding this check here work ?739b927

Copy link
Member

Choose a reason for hiding this comment

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

Almost. I think it needs to be group?.id and user.user?.id or so to not throw an error

plugins/catalog-backend-module-gitlab/src/lib/client.ts Outdated Show resolved Hide resolved
sbarrypoppulo and others added 2 commits August 29, 2023 10:53
Apply suggestion

Co-authored-by: Fredrik Adelöw <freben@gmail.com>
Signed-off-by: sbarrypoppulo <101636916+sbarrypoppulo@users.noreply.github.com>
Signed-off-by: angom1 <angom@poppulo.com>
@angom1 angom1 requested a review from a team as a code owner August 31, 2023 11:29
@angom1 angom1 requested a review from tudi2d August 31, 2023 11:29
@freben
Copy link
Member

freben commented Aug 31, 2023

Should we hold off waiting for the publicEmail question, or is this ready to go from your POV?

Signed-off-by: angom1 <angom@poppulo.com>
@sbarrypoppulo
Copy link
Contributor Author

Should we hold off waiting for the publicEmail question, or is this ready to go from your POV?

We've switched to commitEmail it's is similarly not guaranteed to be populated or returned from the GraphQL API, but seems like a more sane default attribute in hindsight

Further details in the comment here - #18889 (comment)

Signed-off-by: angom1 <angom@poppulo.com>
Signed-off-by: angom1 <angom@poppulo.com>
@freben
Copy link
Member

freben commented Sep 12, 2023

See above about group?.id and user.user?.id - besides that I think we are ready to 🚢

Signed-off-by: angom1 <angom@poppulo.com>
@freben freben merged commit 6b1a6e7 into backstage:master Sep 12, 2023
28 checks passed
@github-actions
Copy link
Contributor

Thank you for contributing to Backstage! The changes in this pull request will be part of the 1.18.0 release, scheduled for Tue, 19 Sep 2023.

@matteosilv
Copy link
Contributor

Greate work guys!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:catalog Related to the Catalog Project Area documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants