Skip to content

Commit 411c7d9

Browse files
committed
handle legacy params
1 parent c343f86 commit 411c7d9

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

coderd/database/queries.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/groups.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ WHERE
5353
ELSE true
5454
END
5555
AND CASE WHEN array_length(@group_names :: text[], 1) > 0 THEN
56-
name = ANY(@group_names)
56+
groups.name = ANY(@group_names)
5757
ELSE true
5858
END
5959
;

coderd/idpsync/group.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user dat
3939
return nil
4040
}
4141

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+
4254
// nolint:gocritic // all syncing is done as a system user
4355
ctx = dbauthz.AsSystemRestricted(ctx)
4456

@@ -66,6 +78,16 @@ func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user dat
6678
return xerrors.Errorf("resolve group sync settings: %w", err)
6779
}
6880
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+
}
6991
}
7092

7193
// collect all diffs to do 1 sql update for all orgs
@@ -175,6 +197,12 @@ type GroupSyncSettings struct {
175197
GroupMapping map[string][]uuid.UUID `json:"mapping"`
176198
RegexFilter *regexp.Regexp `json:"regex_filter"`
177199
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
178206
}
179207

180208
func (s *GroupSyncSettings) Set(v string) error {
@@ -232,6 +260,12 @@ func (s GroupSyncSettings) ParseClaims(mergedClaims jwt.MapClaims) ([]ExpectedGr
232260
}
233261
continue
234262
}
263+
264+
mappedGroupName, ok := s.LegacyGroupNameMapping[group]
265+
if ok {
266+
groups = append(groups, ExpectedGroup{GroupName: &mappedGroupName})
267+
continue
268+
}
235269
group := group
236270
groups = append(groups, ExpectedGroup{GroupName: &group})
237271
}

coderd/idpsync/idpsync.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package idpsync
33
import (
44
"context"
55
"net/http"
6+
"regexp"
67
"strings"
78

89
"github.com/golang-jwt/jwt/v4"
@@ -69,6 +70,15 @@ type DeploymentSyncSettings struct {
6970
// have at least one group in this list.
7071
// A map representation is used for easier lookup.
7172
GroupAllowList map[string]struct{}
73+
// Legacy deployment settings that only apply to the default org.
74+
Legacy DefaultOrgLegacySettings
75+
}
76+
77+
type DefaultOrgLegacySettings struct {
78+
GroupField string
79+
GroupMapping map[string]string
80+
GroupFilter *regexp.Regexp
81+
CreateMissingGroups bool
7282
}
7383

7484
func FromDeploymentValues(dv *codersdk.DeploymentValues) DeploymentSyncSettings {
@@ -80,8 +90,15 @@ func FromDeploymentValues(dv *codersdk.DeploymentValues) DeploymentSyncSettings
8090
OrganizationMapping: dv.OIDC.OrganizationMapping.Value,
8191
OrganizationAssignDefault: dv.OIDC.OrganizationAssignDefault.Value(),
8292

93+
// TODO: Separate group field for allow list from default org
8394
GroupField: dv.OIDC.GroupField.Value(),
8495
GroupAllowList: ConvertAllowList(dv.OIDC.GroupAllowList.Value()),
96+
Legacy: DefaultOrgLegacySettings{
97+
GroupField: dv.OIDC.GroupField.Value(),
98+
GroupMapping: dv.OIDC.GroupMapping.Value,
99+
GroupFilter: dv.OIDC.GroupRegexFilter.Value(),
100+
CreateMissingGroups: dv.OIDC.GroupAutoCreate.Value(),
101+
},
85102
}
86103

87104
}
@@ -90,13 +107,6 @@ type SyncSettings struct {
90107
DeploymentSyncSettings
91108

92109
Group runtimeconfig.RuntimeEntry[*GroupSyncSettings]
93-
94-
//// Group options here are set by the deployment config and only apply to
95-
//// the default organization.
96-
//GroupField string
97-
//CreateMissingGroups bool
98-
//GroupMapping map[string]string
99-
//GroupFilter *regexp.Regexp
100110
}
101111

102112
func NewAGPLSync(logger slog.Logger, manager runtimeconfig.Manager, settings DeploymentSyncSettings) *AGPLIDPSync {

0 commit comments

Comments
 (0)