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
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
38 commits
Select commitHold shift + click to select a range
99c97c2
wip
EmyrkSep 3, 2024
bfddeb6
begin group sync main work
EmyrkSep 3, 2024
f2857c6
initial implementation of group sync
EmyrkSep 3, 2024
791a059
work on moving to the manager
EmyrkSep 4, 2024
4326e9d
fixup compile issues
EmyrkSep 4, 2024
6d3ed2e
fixup some tests
EmyrkSep 4, 2024
0803619
handle allow list
EmyrkSep 4, 2024
596e7b4
WIP unit test for group sync
EmyrkSep 4, 2024
b9476ac
fixup tests, account for existing groups
EmyrkSep 4, 2024
ee8e4e4
fix compile issues
EmyrkSep 5, 2024
d5ff0f7
add comment for test helper
EmyrkSep 5, 2024
86c0f6f
handle legacy params
EmyrkSep 5, 2024
2f03e18
make gen
EmyrkSep 5, 2024
ec8092d
cleanup
EmyrkSep 5, 2024
d63727d
add unit test for legacy behavior
EmyrkSep 5, 2024
2a1769c
work on batching removal by name or id
EmyrkSep 5, 2024
640e86e
group sync adjustments
EmyrkSep 5, 2024
c544a29
test legacy params
EmyrkSep 5, 2024
476be45
add unit test for ApplyGroupDifference
EmyrkSep 5, 2024
164aeac
chore: remove old group sync code
EmyrkSep 5, 2024
986498d
switch oidc test config to deployment values
EmyrkSep 5, 2024
290cfa5
fix err name
EmyrkSep 6, 2024
c563b10
some linting cleanup
EmyrkSep 6, 2024
d2c247f
dbauthz test for new query
EmyrkSep 6, 2024
12685bd
fixup comments
EmyrkSep 6, 2024
bf0d4ed
fixup compile issues from rebase
EmyrkSep 6, 2024
f95128e
add test for disabled sync
EmyrkSep 6, 2024
88b0ad9
linting
EmyrkSep 6, 2024
6491f6a
chore: handle db conflicts gracefully
EmyrkSep 6, 2024
bd23288
test expected group equality
EmyrkSep 6, 2024
a390ec4
cleanup comments
EmyrkSep 6, 2024
a0a1c53
spelling mistake
EmyrkSep 6, 2024
a86ba83
linting:
EmyrkSep 6, 2024
0df7f28
add interface method to allow api crud
EmyrkSep 9, 2024
7a802a9
Remove testable example
EmyrkSep 11, 2024
611f1e3
fix formatting of sql, add a comment
EmyrkSep 11, 2024
7f28a53
remove function only used in 1 place
EmyrkSep 11, 2024
41994d2
make fmt
EmyrkSep 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
WIP unit test for group sync
  • Loading branch information
@Emyrk
Emyrk committedSep 9, 2024
commit596e7b467feef913f10ff70768783bb6b5f826e5
21 changes: 21 additions & 0 deletionscoderd/coderdtest/uuids.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
package coderdtest

import "github.com/google/uuid"

type DeterministicUUIDGenerator struct {
Named map[string]uuid.UUID
}

func NewDeterministicUUIDGenerator() *DeterministicUUIDGenerator {
return &DeterministicUUIDGenerator{
Named: make(map[string]uuid.UUID),
}
}

func (d *DeterministicUUIDGenerator) ID(name string) uuid.UUID {
if v, ok := d.Named[name]; ok {
return v
}
d.Named[name] = uuid.New()
return d.Named[name]
}
17 changes: 16 additions & 1 deletioncoderd/database/dbmem/dbmem.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7643,7 +7643,22 @@ func (q *FakeQuerier) RemoveUserFromGroups(ctx context.Context, arg database.Rem
return nil, err
}

panic("not implemented")
q.mutex.Lock()
defer q.mutex.Unlock()

removed := make([]uuid.UUID, 0)
q.data.groupMembers = slices.DeleteFunc(q.data.groupMembers, func(groupMember database.GroupMemberTable) bool {
if groupMember.UserID != arg.UserID {
return false
}
if !slices.Contains(arg.GroupIds, groupMember.GroupID) {
return false
}
removed = append(removed, groupMember.GroupID)
return true
})

return removed, nil
}

func (q *FakeQuerier) RevokeDBCryptKey(_ context.Context, activeKeyDigest string) error {
Expand Down
23 changes: 20 additions & 3 deletionscoderd/idpsync/group.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@ package idpsync

import (
"context"
"encoding/json"
"regexp"

"github.com/golang-jwt/jwt/v4"
Expand All@@ -12,6 +13,7 @@ import (
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/db2sdk"
"github.com/coder/coder/v2/coderd/database/dbauthz"
"github.com/coder/coder/v2/coderd/runtimeconfig"
"github.com/coder/coder/v2/coderd/util/slice"
)

Expand All@@ -32,7 +34,6 @@ func (s AGPLIDPSync) ParseGroupClaims(_ context.Context, _ jwt.MapClaims) (Group
}, nil
}

// TODO: Group allowlist behavior should probably happen at this step.
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.

// Nothing happens if sync is not enabled
if !params.SyncEnabled {
Expand All@@ -43,6 +44,8 @@ func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user dat
ctx = dbauthz.AsSystemRestricted(ctx)

db.InTx(func(tx database.Store) error {
manager := runtimeconfig.NewStoreManager(tx)

userGroups, err := tx.GetGroups(ctx, database.GetGroupsParams{
HasMemberID: user.ID,
})
Expand All@@ -60,12 +63,12 @@ func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user dat
// For each org, we need to fetch the sync settings
orgSettings := make(map[uuid.UUID]GroupSyncSettings)
for orgID := range userOrgs {
orgResolver :=s.Manager.Scoped(orgID.String())
orgResolver :=manager.Scoped(orgID.String())
settings, err := s.SyncSettings.Group.Resolve(ctx, orgResolver)
if err != nil {
return xerrors.Errorf("resolve group sync settings: %w", err)
}
orgSettings[orgID] = settings.Value
orgSettings[orgID] =*settings
}

// collect all diffs to do 1 sql update for all orgs
Expand DownExpand Up@@ -177,6 +180,20 @@ type GroupSyncSettings struct {
AutoCreateMissingGroups bool `json:"auto_create_missing_groups"`
}

func (s *GroupSyncSettings) Set(v string) error {
return json.Unmarshal([]byte(v), s)
}
func (s *GroupSyncSettings) String() string {
v, err := json.Marshal(s)
if err != nil {
return "decode failed: " + err.Error()
}
return string(v)
}
func (s *GroupSyncSettings) Type() string {
return "GroupSyncSettings"
}

type ExpectedGroup struct {
GroupID *uuid.UUID
GroupName *string
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp