Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: support multi-org group sync with runtime configuration#14578

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 38 commits intomainfromstevenmasley/org_group_sync
Sep 11, 2024

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedSep 5, 2024
edited
Loading

Closes#14202

What is this

Group sync implemented to supportmulti-organization runtime configuration (CRUD does not yet exist).

All previous logic existed inoidcGroups andoauthLogin. I disliked this approach, as the components were completely untestable. So testshad to be integration tests.

The goal of this package is to completely test the sync logic independent of the oidc or broader coderd code.

What is does

Enables group sync to work in multiple organizations, not just the default. There is no way to configure other organizations in this PR, the API and CRUD is not done yet.

Unit tests show how these values can be set.

Testing notes

This is a large refactor to a section of code that had very little testing of it's parts. It did however have good integration style tests for group syncin the default org. In the package tests, multi-org sync is tested, but only withdbmem as it inserts a lot of data. When CRUD api is added, more tests can be added similar to those below for multi-org.

@EmyrkEmyrkforce-pushed thestevenmasley/org_group_sync branch from07fa2b1 toc343f86CompareSeptember 5, 2024 19:26
Base automatically changed fromstevenmasley/runtime_refactor todk/runtime-configsSeptember 5, 2024 21:12
@EmyrkEmyrk changed the titlechore: organization group sync feature with runtime configurationchore: sync groups with runtime configuration, supports multi-orgSep 5, 2024
@EmyrkEmyrkforce-pushed thestevenmasley/org_group_sync branch fromde150b1 to2163eb7CompareSeptember 6, 2024 14:44
@EmyrkEmyrk changed the titlechore: sync groups with runtime configuration, supports multi-orgchore: support multi-org group sync with runtime configurationSep 6, 2024
@EmyrkEmyrkforce-pushed thestevenmasley/org_group_sync branch 2 times, most recently fromb22d62d toae5315fCompareSeptember 6, 2024 15:42
@EmyrkEmyrk marked this pull request as ready for reviewSeptember 6, 2024 18:31
}, nil
}

func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user database.User, params GroupParams) error {
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Enterprise license code just handles theParseGroupClaims. So AGPL will always be disabled.

I put the actualSyncGroups code in AGPL so that I can unit test and maintain the sync code all in 1 package. It is a convenience, while still making sure AGPL code cannot leverage this feature.

Comment on lines +47 to +60
// Only care about the default org for deployment settings if the
// legacy deployment settings exist.
defaultOrgID := uuid.Nil
// Default organization is configured via legacy deployment values
if s.DeploymentSyncSettings.Legacy.GroupField != "" {
defaultOrganization, err := db.GetDefaultOrganization(ctx)
if err != nil {
return xerrors.Errorf("get default organization: %w", err)
}
defaultOrgID = defaultOrganization.ID
}
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Startup group sync config has to be pulled for the default org 😢. Backwards compatibility.

Comment on lines +81 to +85
orgResolver := s.Manager.OrganizationResolver(tx, orgID)
settings, err := s.SyncSettings.Group.Resolve(ctx, orgResolver)
Copy link
MemberAuthor

@EmyrkEmyrkSep 6, 2024
edited
Loading

Choose a reason for hiding this comment

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

Currently this is a DB call.

#14586 will make it a cache lookup

So 100 org deployments would be a bit slow to login until we handle caching. Problem for another day

Comment on lines +68 to +75
GroupField string
// GroupAllowList (if set) will restrict authentication to only users who
// have at least one group in this list.
// A map representation is used for easier lookup.
GroupAllowList map[string]struct{}
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

At some point we should disconnect these from the default org. Might need to move the existing config env and flags, and deprecate the old.

@EmyrkEmyrkforce-pushed thestevenmasley/org_group_sync branch 3 times, most recently froma5b64dd to3263d99CompareSeptember 9, 2024 15:58
@EmyrkEmyrkforce-pushed thestevenmasley/org_group_sync branch from1995c13 to0df7f28CompareSeptember 9, 2024 21:33
Copy link
Contributor

@f0sself0ssel left a comment

Choose a reason for hiding this comment

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

Overall looks good, glad the runtime config only impacts this feature. Unfortunate about the sql tests being disabled, maybe we can add some sort of simple cache or debounce for just tests? Could be a followup.

Also it seems like all the frontend changes should be in a separate PR? Or maybe the branch just needs rebasing?

@EmyrkEmyrk changed the base branch fromdk/runtime-configs tomainSeptember 10, 2024 19:42
@Emyrk
Copy link
MemberAuthor

@f0ssel yea, I rebased it correctly, but forgot to change the base branch tomain 🤦. Should be correct now 👍

Copy link
Contributor

@coadlercoadler left a comment

Choose a reason for hiding this comment

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

still trying to catch up to speed but all lgtm!

Emyrk reacted with thumbs up emoji
Comment on lines 55 to 58
AND CASE WHEN array_length(@group_names :: text[], 1) > 0 THEN
groups.name = ANY(@group_names)
ELSE true
END
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
AND CASE WHEN array_length(@group_names ::text[],1)>0 THEN
groups.name= ANY(@group_names)
ELSE true
END
AND CASE WHEN array_length(@group_names ::text[],1)>0 THEN
groups.name= ANY(@group_names)
ELSE true
END

nit; indentation is a little weird

Emyrk reacted with thumbs up emoji
Comment on lines 685 to 694
func (q *FakeQuerier) getGroupByNameNoLock(arg database.NameOrganizationPair) (database.Group, error) {
for _, group := range q.groups {
if group.OrganizationID == arg.OrganizationID &&
group.Name == arg.Name {
return group, nil
}
}

return database.Group{}, sql.ErrNoRows
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm very curious what this is necessary for

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Oh, I originally was using it in another query. Wanted to reuse the same code. Now it's not necessary to extract to it's own function 🤷‍♂️. I'll put it back.

@aslilacaslilac mentioned this pull requestSep 11, 2024
@EmyrkEmyrk merged commit6a846cd intomainSep 11, 2024
26 checks passed
@EmyrkEmyrk deleted the stevenmasley/org_group_sync branchSeptember 11, 2024 18:43
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsSep 11, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@aslilacaslilacaslilac left review comments

@coadlercoadlercoadler approved these changes

@f0sself0sself0ssel approved these changes

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Multi-Organization Group Sync compatibility upgrade
4 participants
@Emyrk@aslilac@coadler@f0ssel

[8]ページ先頭

©2009-2025 Movatter.jp