Skip to content

feat: implement acl for workspaces #19094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add database.WorkspaceACL type
  • Loading branch information
aslilac committed Jul 30, 2025
commit a20cd4f78de5d502fbf12f1aaf6d8bd66feb6e2f
2 changes: 2 additions & 0 deletions coderd/database/dbgen/dbgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ func TestGenerator(t *testing.T) {
DeletingAt: w.DeletingAt,
AutomaticUpdates: w.AutomaticUpdates,
Favorite: w.Favorite,
GroupACL: database.WorkspaceACL{},
UserACL: database.WorkspaceACL{},
}
require.Equal(t, exp, table)
})
Expand Down
12 changes: 6 additions & 6 deletions coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions coderd/database/sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ sql:
- column: "template_usage_stats.app_usage_mins"
go_type:
type: "StringMapOfInt"
- column: "workspaces.user_acl"
go_type:
type: "WorkspaceACL"
- column: "workspaces.group_acl"
go_type:
type: "WorkspaceACL"
- column: "workspaces_expanded.user_acl"
go_type:
type: "WorkspaceACL"
- column: "workspaces_expanded.group_acl"
go_type:
type: "WorkspaceACL"
- column: "notification_templates.actions"
go_type:
type: "[]byte"
Expand Down
22 changes: 22 additions & 0 deletions coderd/database/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ func (t TemplateACL) Value() (driver.Value, error) {
return json.Marshal(t)
}

type WorkspaceACL map[string]WorkspaceACLEntry

func (t *WorkspaceACL) Scan(src interface{}) error {
switch v := src.(type) {
case string:
return json.Unmarshal([]byte(v), &t)
case []byte, json.RawMessage:
//nolint
return json.Unmarshal(v.([]byte), &t)
}

return xerrors.Errorf("unexpected type %T", src)
}

func (t WorkspaceACL) Value() (driver.Value, error) {
return json.Marshal(t)
}

type WorkspaceACLEntry struct {
Permissions []policy.Action `json:"permissions"`
}

type ExternalAuthProvider struct {
ID string `json:"id"`
Optional bool `json:"optional,omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions coderd/rbac/regosql/acl_mapping_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func (ACLMappingVar) UseAs() sqltypes.Node { return ACLMappingVar{} }

func (g ACLMappingVar) ConvertVariable(rego ast.Ref) (sqltypes.Node, bool) {
// "left" will be a map of group names to actions in rego.
// {
// "all_users": ["read"]
// }
// {
// "all_users": ["read"]
// }
left, err := sqltypes.RegoVarPath(g.StructPath, rego)
if err != nil {
return nil, false
Expand Down