Skip to content

Commit ec6ac57

Browse files
committed
fixup! sync missing groups
1 parent f56113e commit ec6ac57

File tree

13 files changed

+155
-27
lines changed

13 files changed

+155
-27
lines changed

coderd/database/dbfake/dbfake.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,6 +3526,7 @@ func (q *FakeQuerier) InsertGroup(_ context.Context, arg database.InsertGroupPar
35263526
OrganizationID: arg.OrganizationID,
35273527
AvatarURL: arg.AvatarURL,
35283528
QuotaAllowance: arg.QuotaAllowance,
3529+
Source: database.GroupSourceUser,
35293530
}
35303531

35313532
q.groups = append(q.groups, group)
@@ -3608,6 +3609,7 @@ func (q *FakeQuerier) InsertMissingGroups(ctx context.Context, arg database.Inse
36083609
AvatarURL: "",
36093610
QuotaAllowance: 0,
36103611
DisplayName: "",
3612+
Source: arg.Source,
36113613
}
36123614
q.groups = append(q.groups, g)
36133615
newGroups = append(newGroups, g)

coderd/database/dump.sql

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
BEGIN;
2+
3+
ALTER TABLE groups
4+
DROP COLUMN source;
5+
6+
DROP TYPE group_source;
7+
8+
COMMIT;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
BEGIN;
2+
3+
CREATE TYPE group_source AS ENUM (
4+
-- User created groups
5+
'user',
6+
-- Groups created by the system through oidc sync
7+
'oidc'
8+
);
9+
10+
ALTER TABLE groups
11+
ADD COLUMN source group_source NOT NULL DEFAULT 'user';
12+
13+
COMMENT ON COLUMN groups.source IS 'Source indicates how the group was created. It can be created by a user manually, or through some system process like and OIDC group sync.';
14+
15+
COMMIT;

coderd/database/models.go

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 23 additions & 13 deletions
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ VALUES
4646
INSERT INTO groups (
4747
id,
4848
name,
49-
organization_id
49+
organization_id,
50+
source
5051
)
5152
SELECT
5253
gen_random_uuid(),
5354
group_name,
54-
@organization_id
55+
@organization_id,
56+
@source
5557
FROM
5658
UNNEST(@group_names :: text[]) AS group_name
5759
-- If the name conflicts, do nothing.

codersdk/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ when required by your organization's security policy.`,
10791079
},
10801080
{
10811081
Name: "OIDC Regex Group Filter",
1082-
Description: "If provided any group name not matching the regex is ignored. This allows for filtering out groups that are not needed.",
1082+
Description: "If provided any group name not matching the regex is ignored. This allows for filtering out groups that are not needed. This filter is applied after the group mapping.",
10831083
Flag: "oidc-group-regex-filter",
10841084
Env: "CODER_OIDC_GROUP_REGEX_FILTER",
10851085
Default: "",

codersdk/groups.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import (
1010
"golang.org/x/xerrors"
1111
)
1212

13+
type GroupSource string
14+
15+
const (
16+
GroupSourceUser GroupSource = "user"
17+
GroupSourceOIDC GroupSource = "oidc"
18+
)
19+
1320
type CreateGroupRequest struct {
1421
Name string `json:"name"`
1522
DisplayName string `json:"display_name"`
@@ -18,13 +25,14 @@ type CreateGroupRequest struct {
1825
}
1926

2027
type Group struct {
21-
ID uuid.UUID `json:"id" format:"uuid"`
22-
Name string `json:"name"`
23-
DisplayName string `json:"display_name"`
24-
OrganizationID uuid.UUID `json:"organization_id" format:"uuid"`
25-
Members []User `json:"members"`
26-
AvatarURL string `json:"avatar_url"`
27-
QuotaAllowance int `json:"quota_allowance"`
28+
ID uuid.UUID `json:"id" format:"uuid"`
29+
Name string `json:"name"`
30+
DisplayName string `json:"display_name"`
31+
OrganizationID uuid.UUID `json:"organization_id" format:"uuid"`
32+
Members []User `json:"members"`
33+
AvatarURL string `json:"avatar_url"`
34+
QuotaAllowance int `json:"quota_allowance"`
35+
Source GroupSource `json:"source"`
2836
}
2937

3038
func (c *Client) CreateGroup(ctx context.Context, orgID uuid.UUID, req CreateGroupRequest) (Group, error) {

enterprise/audit/table.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ var auditableResourcesTypes = map[any]map[string]Action{
156156
"avatar_url": ActionTrack,
157157
"quota_allowance": ActionTrack,
158158
"members": ActionTrack,
159+
"source": ActionIgnore,
159160
},
160161
&database.APIKey{}: {
161162
"id": ActionIgnore,

enterprise/coderd/groups.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ func convertGroup(g database.Group, users []database.User) codersdk.Group {
409409
AvatarURL: g.AvatarURL,
410410
QuotaAllowance: int(g.QuotaAllowance),
411411
Members: convertUsers(users, orgs),
412+
Source: codersdk.GroupSource(g.Source),
412413
}
413414
}
414415

enterprise/coderd/userauth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func (api *API) setUserGroups(ctx context.Context, logger slog.Logger, db databa
4646
created, err := tx.InsertMissingGroups(dbauthz.AsSystemRestricted(ctx), database.InsertMissingGroupsParams{
4747
OrganizationID: orgs[0].ID,
4848
GroupNames: groupNames,
49+
Source: database.GroupSourceOidc,
4950
})
5051
if err != nil {
5152
return xerrors.Errorf("insert missing groups: %w", err)

0 commit comments

Comments
 (0)