@@ -39,6 +39,18 @@ func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user dat
39
39
return nil
40
40
}
41
41
42
+ // Only care about the default org for deployment settings if the
43
+ // legacy deployment settings exist.
44
+ defaultOrgID := uuid .Nil
45
+ // Default organization is configured via legacy deployment values
46
+ if s .DeploymentSyncSettings .Legacy .GroupField != "" {
47
+ defaultOrganization , err := db .GetDefaultOrganization (ctx )
48
+ if err != nil {
49
+ return xerrors .Errorf ("get default organization: %w" , err )
50
+ }
51
+ defaultOrgID = defaultOrganization .ID
52
+ }
53
+
42
54
// nolint:gocritic // all syncing is done as a system user
43
55
ctx = dbauthz .AsSystemRestricted (ctx )
44
56
@@ -66,6 +78,16 @@ func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user dat
66
78
return xerrors .Errorf ("resolve group sync settings: %w" , err )
67
79
}
68
80
orgSettings [orgID ] = * settings
81
+
82
+ // Legacy deployment settings will override empty settings.
83
+ if orgID == defaultOrgID && settings .GroupField == "" {
84
+ settings = & GroupSyncSettings {
85
+ GroupField : s .Legacy .GroupField ,
86
+ LegacyGroupNameMapping : s .Legacy .GroupMapping ,
87
+ RegexFilter : s .Legacy .GroupFilter ,
88
+ AutoCreateMissingGroups : s .Legacy .CreateMissingGroups ,
89
+ }
90
+ }
69
91
}
70
92
71
93
// collect all diffs to do 1 sql update for all orgs
@@ -175,6 +197,12 @@ type GroupSyncSettings struct {
175
197
GroupMapping map [string ][]uuid.UUID `json:"mapping"`
176
198
RegexFilter * regexp.Regexp `json:"regex_filter"`
177
199
AutoCreateMissingGroups bool `json:"auto_create_missing_groups"`
200
+ // LegacyGroupNameMapping is deprecated. It remaps an IDP group name to
201
+ // a Coder group name. Since configuration is now done at runtime,
202
+ // group IDs are used to account for group renames.
203
+ // For legacy configurations, this config option has to remain.
204
+ // Deprecated: Use GroupMapping instead.
205
+ LegacyGroupNameMapping map [string ]string
178
206
}
179
207
180
208
func (s * GroupSyncSettings ) Set (v string ) error {
@@ -232,6 +260,12 @@ func (s GroupSyncSettings) ParseClaims(mergedClaims jwt.MapClaims) ([]ExpectedGr
232
260
}
233
261
continue
234
262
}
263
+
264
+ mappedGroupName , ok := s .LegacyGroupNameMapping [group ]
265
+ if ok {
266
+ groups = append (groups , ExpectedGroup {GroupName : & mappedGroupName })
267
+ continue
268
+ }
235
269
group := group
236
270
groups = append (groups , ExpectedGroup {GroupName : & group })
237
271
}
0 commit comments