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

maintain: track provider groups separate from users #3211

Closed
wants to merge 1 commit into from

Conversation

BruceMacD
Copy link
Collaborator

@BruceMacD BruceMacD commented Sep 15, 2022

  • add provider information to trace identity group membership relations
  • migrate provider user groups to provider groups

Summary

In order to track where users had their groups assigned to them more accurately updating the database schema to track and resolve group membership. This means tracking the state of external identity provider groups with relations to their provider users, and adding provider information to identities_groups relations.

identities_groups relations now have the form (identity_id, group_id, provider_id, provider_group_name) to allow mapping external groups from identity providers to groups within Infra. This behavior will be a later change, this PR keeps the same behavior of automatically mapping groups from identity providers to groups within Infra that have the same name.

Checklist

  • Wrote appropriate unit tests
  • Considered security implications of the change
  • Updated associated docs where necessary
  • Updated associated configuration where necessary
  • Change is backwards compatible if it needs to be (user can upgrade without manual steps?)
  • Nothing sensitive logged
  • Considered data migrations for smooth upgrades

Related Issues

Resolves #3138
Resolves #2982

@@ -170,10 +170,6 @@ func UpdateIdentityInfoFromProvider(c RequestContext, oidc providers.OIDCClient)
logging.Errorf("failed to revoke invalid user session: %s", nestedErr)
}

if nestedErr := data.DeleteProviderUsers(db, data.ByIdentityID(identity.ID), data.ByProviderID(provider.ID)); nestedErr != nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed this, on a failure the access is revoked, but we don't know that the user no longer exists. Its confusing when their group membership changes based on a failed login.

@@ -45,7 +45,7 @@ func (a *oidcAuthn) Authenticate(ctx context.Context, db data.GormTxn, requested
return AuthenticatedIdentity{}, fmt.Errorf("exhange code for tokens: %w", err)
}

identity, err := data.GetIdentity(db, data.Preload("Groups"), data.ByName(email))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The identity groups loaded here weren't used

internal/server/data/schema.sql Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview September 15, 2022 14:03 Inactive
Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

Nice! I haven't looked over all of it yet, but left a couple suggestions/questions on the model and diagram

docs/dev/identity-provider-tracking.md Outdated Show resolved Hide resolved
internal/server/models/providergroup.go Outdated Show resolved Hide resolved
docs/dev/identity-provider-tracking.md Show resolved Hide resolved
Copy link
Contributor

@ssoroka ssoroka left a comment

Choose a reason for hiding this comment

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

I think we've really complicated things here and the complication isn't worth it. I really hate that the queries now have to query provider tables to build the picture of what our memberships are.

internal/server/data/identity.go Outdated Show resolved Hide resolved
internal/server/data/providergroup.go Show resolved Hide resolved
internal/server/data/schema.sql Outdated Show resolved Hide resolved
@BruceMacD BruceMacD marked this pull request as draft September 20, 2022 17:32
@vercel vercel bot temporarily deployed to Preview September 21, 2022 20:49 Inactive
@BruceMacD BruceMacD marked this pull request as ready for review September 22, 2022 14:18
Copy link
Contributor

@ssoroka ssoroka left a comment

Choose a reason for hiding this comment

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

I think we can do more to simplify this. There's no reason to keep two active join tables for membership; the provider memberships should update our memberships which simplifies querying and joining a ton; it's a lot easier if our core application knows nothing about providers and provider groups

internal/server/data/migrations.go Show resolved Hide resolved
internal/server/data/migrations.go Outdated Show resolved Hide resolved
internal/server/data/migrations.go Outdated Show resolved Hide resolved
internal/server/data/migrations.go Show resolved Hide resolved
internal/server/data/migrations.go Outdated Show resolved Hide resolved
internal/server/data/providergroup.go Outdated Show resolved Hide resolved
internal/server/data/providergroup.go Outdated Show resolved Hide resolved
internal/server/data/providergroup.go Outdated Show resolved Hide resolved
internal/server/data/providergroup.go Show resolved Hide resolved
internal/server/data/providergroup.go Show resolved Hide resolved
Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

I think this is looking good! I was surprised that identities_groups was still around after these changes. I left a question about that below.

I'll continue to review tomorrow.

internal/server/data/providergroup_test.go Show resolved Hide resolved
internal/server/data/providergroup.go Outdated Show resolved Hide resolved
internal/server/models/providergroup.go Show resolved Hide resolved
internal/server/data/providergroup.go Outdated Show resolved Hide resolved
internal/server/data/migrations.go Outdated Show resolved Hide resolved
internal/server/data/migrations.go Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview September 26, 2022 18:18 Inactive
@BruceMacD BruceMacD marked this pull request as draft September 27, 2022 20:54
@BruceMacD BruceMacD marked this pull request as ready for review September 27, 2022 20:54
@BruceMacD BruceMacD force-pushed the brucemacd/provider_groups branch 2 times, most recently from 142c922 to ddf3318 Compare September 29, 2022 20:07
internal/server/data/group.go Outdated Show resolved Hide resolved
@@ -101,7 +102,7 @@ func DeleteGroup(tx WriteTxn, id uid.ID) error {

_, err = tx.Exec(`DELETE from identities_groups WHERE group_id = ?`, id)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this has a similar problem to users; If you're deleting a group that was both created by infra and also the result of a mapping, what happens to that mapping? do you leave the group and only remove the identities_groups record for the infra provider?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this would result in the group being deleted, and then just re-created next time a user in a provider with that group is synchronized. That's what would happen at the moment too, so I think the fix for this is in our group mapping UI which will come after this.

internal/server/data/group.go Show resolved Hide resolved
internal/server/data/group.go Show resolved Hide resolved
internal/server/data/migrations.go Show resolved Hide resolved
if opts.ByMemberIdentityID != 0 {
query.B(`
JOIN provider_groups_provider_users
ON provider_groups.name = provider_groups_provider_users.provider_group_name
Copy link
Contributor

Choose a reason for hiding this comment

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

should it join on id instead? names could be problematic if they're not indexed

@BruceMacD BruceMacD force-pushed the brucemacd/provider_groups branch 2 times, most recently from 399963b to 56386e2 Compare October 7, 2022 13:31
- join group membership from provider group relation
- unlink provider groups from groups on deletion
- migrate provider user groups to provider groups
@vercel vercel bot temporarily deployed to Preview October 20, 2022 15:03 Inactive
@BruceMacD BruceMacD closed this Nov 1, 2022
@mxyng mxyng deleted the brucemacd/provider_groups branch February 13, 2023 19:01
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.

Keep track of where groups were syncronized from Cannot use comma in group names
3 participants