Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb1d073

Browse files
committed
trying to figure out how to initialize both AGPL and enterprise
1 parent f5793f6 commit eb1d073

File tree

5 files changed

+33
-11
lines changed

5 files changed

+33
-11
lines changed

cli/server.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ func createOIDCConfig(ctx context.Context, logger slog.Logger, vals *codersdk.De
170170
groupAllowList[group] = true
171171
}
172172

173+
idpSyncSetting := idpsync.SyncSettings{
174+
OrganizationField: vals.OIDC.OrganizationField.Value(),
175+
OrganizationMapping: vals.OIDC.OrganizationMapping.Value,
176+
OrganizationAssignDefault: vals.OIDC.OrganizationAssignDefault.Value(),
177+
}
178+
syncer.Configure(idpSyncSetting)
179+
173180
return &coderd.OIDCConfig{
174181
OAuth2Config: useCfg,
175182
Provider: oidcProvider,
@@ -198,11 +205,7 @@ func createOIDCConfig(ctx context.Context, logger slog.Logger, vals *codersdk.De
198205
SignupsDisabledText: vals.OIDC.SignupsDisabledText.String(),
199206
IconURL: vals.OIDC.IconURL.String(),
200207
IgnoreEmailVerified: vals.OIDC.IgnoreEmailVerified.Value(),
201-
IDPSync: idpsync.NewSync(logger, idpsync.SyncSettings{
202-
OrganizationField: vals.OIDC.OrganizationField.Value(),
203-
OrganizationMapping: vals.OIDC.OrganizationMapping.Value,
204-
OrganizationAssignDefault: vals.OIDC.OrganizationAssignDefault.Value(),
205-
}),
208+
IDPSync: syncer,
206209
}, nil
207210
}
208211

coderd/idpsync/idpsync.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import (
1616
)
1717

1818
type IDPSync interface {
19+
// Configure is a method on the struct only because it is easier to configure
20+
// from the AGPL initialization. For the enterprise code to get these settings,
21+
// it makes sense to have the AGPL call 'Configure' rather than duplicate
22+
// the code to create these settings.
23+
Configure(settings SyncSettings)
1924
// ParseOrganizationClaims takes claims from an OIDC provider, and returns the
2025
// organization sync params for assigning users into organizations.
2126
ParseOrganizationClaims(ctx context.Context, _ map[string]interface{}) (OrganizationParams, *HttpError)
@@ -45,13 +50,20 @@ type SyncSettings struct {
4550
OrganizationAssignDefault bool
4651
}
4752

48-
func NewSync(logger slog.Logger, settings SyncSettings) *AGPLIDPSync {
53+
func NewSync(logger slog.Logger) *AGPLIDPSync {
4954
return &AGPLIDPSync{
50-
Logger: logger.Named("idp-sync"),
51-
SyncSettings: settings,
55+
Logger: logger.Named("idp-sync"),
56+
SyncSettings: SyncSettings{
57+
// A sane default
58+
OrganizationAssignDefault: true,
59+
},
5260
}
5361
}
5462

63+
func (s *AGPLIDPSync) Configure(settings SyncSettings) {
64+
s.SyncSettings = settings
65+
}
66+
5567
// ParseStringSliceClaim parses the claim for groups and roles, expected []string.
5668
//
5769
// Some providers like ADFS return a single string instead of an array if there

coderd/idpsync/organization.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (s AGPLIDPSync) ParseOrganizationClaims(ctx context.Context, _ map[string]i
1919
// nolint:gocritic // all syncing is done as a system user
2020
ctx = dbauthz.AsSystemRestricted(ctx)
2121

22-
// For AGPL we only rely on 'OrganizationAlwaysAssign'
22+
// For AGPL we only sync the default organization.
2323
return OrganizationParams{
2424
SyncEnabled: false,
2525
IncludeDefault: s.OrganizationAssignDefault,

coderd/userauth.go

+7
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,12 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
10261026
return
10271027
}
10281028

1029+
orgSync, orgSyncErr := api.OIDCConfig.IDPSync.ParseOrganizationClaims(ctx, mergedClaims)
1030+
if orgSyncErr != nil {
1031+
orgSyncErr.Write(rw, r)
1032+
return
1033+
}
1034+
10291035
// If a new user is authenticating for the first time
10301036
// the audit action is 'register', not 'login'
10311037
if user.ID == uuid.Nil {
@@ -1047,6 +1053,7 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
10471053
Roles: roles,
10481054
UsingGroups: usingGroups,
10491055
Groups: groups,
1056+
OrganizationSync: orgSync,
10501057
CreateMissingGroups: api.OIDCConfig.CreateMissingGroups,
10511058
GroupFilter: api.OIDCConfig.GroupFilter,
10521059
DebugContext: OauthDebugContext{

enterprise/coderd/enidpsync/enidpsync.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ type EnterpriseIDPSync struct {
1212
agpl *idpsync.AGPLIDPSync
1313
}
1414

15-
func NewSync(logger slog.Logger, entitlements *entitlements.Set, settings idpsync.SyncSettings) *EnterpriseIDPSync {
15+
func NewSync(logger slog.Logger, entitlements *entitlements.Set) *EnterpriseIDPSync {
1616
return &EnterpriseIDPSync{
1717
entitlements: entitlements,
18-
agpl: idpsync.NewSync(logger, settings),
18+
agpl: idpsync.NewSync(logger),
1919
}
2020
}

0 commit comments

Comments
 (0)