Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -2305,13 +2305,11 @@ func (api *API) workspaceACL(rw http.ResponseWriter, r *http.Request) {
return
}

// This is largely based on the template ACL implementation, and is far from
// ideal. Usually, when we use the System context it's because we need to
// run some query that won't actually be exposed to the user. That is not
// the case here. This data goes directly to an unauthorized user. We are
// just straight up breaking security promises.
//
// TODO: This needs to be fixed before GA. Currently in beta.
// Shared user and group principal lookups use system context because
// workspace ACL readers should see principals shared on the workspace
// even if they cannot otherwise read those users or groups. Group
// members and counts use the caller context so normal group member
// RBAC still applies.

// Fetch all of the users and their organization memberships
userIDs := make([]uuid.UUID, 0, len(workspaceACL.Users))
Expand Down Expand Up @@ -2366,10 +2364,7 @@ func (api *API) workspaceACL(rw http.ResponseWriter, r *http.Request) {

groups := make([]codersdk.WorkspaceGroup, 0, len(dbGroups))
for _, it := range dbGroups {
var members []database.GroupMember
// For context see https://github.com/coder/coder/pull/19375
// nolint:gocritic
members, err = api.Database.GetGroupMembersByGroupID(dbauthz.AsSystemRestricted(ctx), database.GetGroupMembersByGroupIDParams{
members, err := api.Database.GetGroupMembersByGroupID(ctx, database.GetGroupMembersByGroupIDParams{
GroupID: it.Group.ID,
IncludeSystem: false,
})
Expand Down
12 changes: 12 additions & 0 deletions coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5672,6 +5672,7 @@ func TestWorkspaceReadCanListACL(t *testing.T) {
workspaceOwnerClient, workspaceOwner = coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
sharedUserClientA, sharedUserA = coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
_, sharedUserB = coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
_, groupMember = coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
sharedGroup = dbgen.Group(t, db, database.Group{OrganizationID: admin.OrganizationID})
workspace = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
OwnerID: workspaceOwner.ID,
Expand All @@ -5681,6 +5682,8 @@ func TestWorkspaceReadCanListACL(t *testing.T) {

ctx := testutil.Context(t, testutil.WaitMedium)

dbgen.GroupMember(t, db, database.GroupMemberTable{GroupID: sharedGroup.ID, UserID: groupMember.ID})

err := workspaceOwnerClient.UpdateWorkspaceACL(ctx, workspace.ID, codersdk.UpdateWorkspaceACL{
UserRoles: map[string]codersdk.WorkspaceRole{
sharedUserA.ID.String(): codersdk.WorkspaceRoleUse,
Expand Down Expand Up @@ -5709,6 +5712,15 @@ func TestWorkspaceReadCanListACL(t *testing.T) {
gotGroupRoles[g.ID] = g.Role
}
require.Equal(t, codersdk.WorkspaceRoleUse, gotGroupRoles[sharedGroup.ID])
require.Empty(t, acl.Groups[0].Members)
require.Equal(t, 0, acl.Groups[0].TotalMemberCount)

adminACL, err := client.WorkspaceACL(ctx, workspace.ID)
require.NoError(t, err)
require.Len(t, adminACL.Groups, 1)
require.Len(t, adminACL.Groups[0].Members, 1)
require.Equal(t, groupMember.ID, adminACL.Groups[0].Members[0].ID)
require.Equal(t, 1, adminACL.Groups[0].TotalMemberCount)
}

// nolint:tparallel,paralleltest // Subtests modify a package global (rbac.workspaceACLDisabled).
Expand Down
Loading