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

Commitc61b64b

Browse files
authored
feat: add hidden enterprise cmd command to list roles (#13303)
* feat: add hidden enterprise cmd command to list rolesThis includes custom roles, and has a json ouput option formore granular permissions
1 parent8e78b94 commitc61b64b

File tree

28 files changed

+662
-86
lines changed

28 files changed

+662
-86
lines changed

‎coderd/apidoc/docs.go

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

‎coderd/apidoc/swagger.json

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

‎coderd/database/dbauthz/dbauthz.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,11 +835,12 @@ func (q *querier) CleanTailnetTunnels(ctx context.Context) error {
835835
returnq.db.CleanTailnetTunnels(ctx)
836836
}
837837

838-
func (q*querier)CustomRolesByName(ctx context.Context,lookupRoles []string) ([]database.CustomRole,error) {
838+
// TODO: Handle org scoped lookups
839+
func (q*querier)CustomRoles(ctx context.Context,arg database.CustomRolesParams) ([]database.CustomRole,error) {
839840
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceAssignRole);err!=nil {
840841
returnnil,err
841842
}
842-
returnq.db.CustomRolesByName(ctx,lookupRoles)
843+
returnq.db.CustomRoles(ctx,arg)
843844
}
844845

845846
func (q*querier)DeleteAPIKeyByID(ctx context.Context,idstring)error {

‎coderd/database/dbauthz/dbauthz_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,8 @@ func (s *MethodTestSuite) TestUser() {
11771177
b:=dbgen.User(s.T(),db, database.User{})
11781178
check.Args().Asserts(rbac.ResourceSystem,policy.ActionRead).Returns(slice.New(a.ID,b.ID))
11791179
}))
1180-
s.Run("CustomRolesByName",s.Subtest(func(db database.Store,check*expects) {
1181-
check.Args([]string{}).Asserts(rbac.ResourceAssignRole,policy.ActionRead).Returns([]database.CustomRole{})
1180+
s.Run("CustomRoles",s.Subtest(func(db database.Store,check*expects) {
1181+
check.Args(database.CustomRolesParams{}).Asserts(rbac.ResourceAssignRole,policy.ActionRead).Returns([]database.CustomRole{})
11821182
}))
11831183
s.Run("Blank/UpsertCustomRole",s.Subtest(func(db database.Store,check*expects) {
11841184
// Blank is no perms in the role

‎coderd/database/dbmem/dbmem.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,18 +1175,26 @@ func (*FakeQuerier) CleanTailnetTunnels(context.Context) error {
11751175
returnErrUnimplemented
11761176
}
11771177

1178-
func (q*FakeQuerier)CustomRolesByName(_ context.Context,lookupRoles []string) ([]database.CustomRole,error) {
1178+
func (q*FakeQuerier)CustomRoles(_ context.Context,arg database.CustomRolesParams) ([]database.CustomRole,error) {
11791179
q.mutex.Lock()
11801180
deferq.mutex.Unlock()
11811181

11821182
found:=make([]database.CustomRole,0)
11831183
for_,role:=rangeq.data.customRoles {
1184-
ifslices.ContainsFunc(lookupRoles,func(sstring)bool {
1185-
returnstrings.EqualFold(s,role.Name)
1186-
}) {
1187-
role:=role
1188-
found=append(found,role)
1184+
role:=role
1185+
iflen(arg.LookupRoles)>0 {
1186+
if!slices.ContainsFunc(arg.LookupRoles,func(sstring)bool {
1187+
returnstrings.EqualFold(s,role.Name)
1188+
}) {
1189+
continue
1190+
}
11891191
}
1192+
1193+
ifarg.ExcludeOrgRoles&&role.OrganizationID.Valid {
1194+
continue
1195+
}
1196+
1197+
found=append(found,role)
11901198
}
11911199

11921200
returnfound,nil

‎coderd/database/dbmetrics/dbmetrics.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dbmock/dbmock.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dump.sql

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTERTABLE custom_roles
2+
-- This column is nullable, meaning no organization scope
3+
DROP COLUMN organization_id;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ALTERTABLE custom_roles
2+
-- This column is nullable, meaning no organization scope
3+
ADD COLUMN organization_id uuid;
4+
5+
COMMENT ON COLUMN custom_roles.organization_id IS'Roles can optionally be scoped to an organization'

‎coderd/database/models.go

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

‎coderd/database/querier.go

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

‎coderd/database/queries.sql.go

Lines changed: 22 additions & 5 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/roles.sql

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
-- name:CustomRolesByName :many
1+
-- name:CustomRoles :many
22
SELECT
33
*
44
FROM
55
custom_roles
66
WHERE
7+
true
8+
-- Lookup roles filter
9+
AND CASE WHEN array_length(@lookup_roles ::text[],1)>0 THEN
710
-- Case insensitive
811
name ILIKE ANY(@lookup_roles ::text [])
12+
ELSE true
13+
END
14+
-- Org scoping filter, to only fetch site wide roles
15+
AND CASE WHEN @exclude_org_roles ::boolean THEN
16+
organization_id ISnull
17+
ELSE true
18+
END
919
;
1020

11-
1221
-- name: UpsertCustomRole :one
1322
INSERT INTO
1423
custom_roles (

‎coderd/httpapi/name.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func UsernameFrom(str string) string {
3838
}
3939

4040
// NameValid returns whether the input string is a valid name.
41-
// It is a generic validator for any name (user, workspace, template, etc.).
41+
// It is a generic validator for any name (user, workspace, template,role name,etc.).
4242
funcNameValid(strstring)error {
4343
iflen(str)>32 {
4444
returnxerrors.New("must be <= 32 characters")

‎coderd/rbac/rolestore/rolestore.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ func Expand(ctx context.Context, db database.Store, names []string) (rbac.Roles,
7272
// If some roles are missing from the database, they are omitted from
7373
// the expansion. These roles are no-ops. Should we raise some kind of
7474
// warning when this happens?
75-
dbroles,err:=db.CustomRolesByName(ctx,lookup)
75+
dbroles,err:=db.CustomRoles(ctx, database.CustomRolesParams{
76+
LookupRoles:lookup,
77+
ExcludeOrgRoles:false,
78+
})
7679
iferr!=nil {
7780
returnnil,xerrors.Errorf("fetch custom roles: %w",err)
7881
}
@@ -81,7 +84,7 @@ func Expand(ctx context.Context, db database.Store, names []string) (rbac.Roles,
8184
for_,dbrole:=rangedbroles {
8285
converted,err:=ConvertDBRole(dbrole)
8386
iferr!=nil {
84-
returnnil,xerrors.Errorf("convert db role %q: %w",dbrole,err)
87+
returnnil,xerrors.Errorf("convert db role %q: %w",dbrole.Name,err)
8588
}
8689
roles=append(roles,converted)
8790
cache.Store(dbrole.Name,converted)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp