Skip to content

Commit 9113b16

Browse files
committedApr 7, 2023
Owners cannot do workspace exec site wide
1 parent 8a8c895 commit 9113b16

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed
 

‎coderd/rbac/object_gen.go

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

‎coderd/rbac/object_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55

66
"github.com/coder/coder/coderd/rbac"
7+
"github.com/coder/coder/coderd/util/slice"
78
)
89

910
func TestObjectEqual(t *testing.T) {
@@ -174,3 +175,20 @@ func TestObjectEqual(t *testing.T) {
174175
})
175176
}
176177
}
178+
179+
// TestAllResources ensures that all resources have a unique type name.
180+
func TestAllResources(t *testing.T) {
181+
var typeNames []string
182+
resources := rbac.AllResources()
183+
for _, r := range resources {
184+
if r.Type == "" {
185+
t.Errorf("empty type name: %s", r.Type)
186+
continue
187+
}
188+
if slice.Contains(typeNames, r.Type) {
189+
t.Errorf("duplicate type name: %s", r.Type)
190+
continue
191+
}
192+
typeNames = append(typeNames, r.Type)
193+
}
194+
}

‎coderd/rbac/roles.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,26 @@ var builtInRoles = map[string]func(orgID string) Role{
7676
return Role{
7777
Name: owner,
7878
DisplayName: "Owner",
79-
Site: Permissions(map[string][]Action{
80-
ResourceWildcard.Type: {WildcardSymbol},
81-
}),
79+
Site: func() []Permission {
80+
// Owner can do all actions on all resources, minus some exceptions.
81+
resources := AllResources()
82+
var perms []Permission
83+
84+
for _, r := range resources {
85+
// Exceptions
86+
if r.Equal(ResourceWildcard) ||
87+
r.Equal(ResourceWorkspaceExecution) {
88+
continue
89+
}
90+
// Owners can do everything else
91+
perms = append(perms, Permission{
92+
Negate: false,
93+
ResourceType: r.Type,
94+
Action: WildcardSymbol,
95+
})
96+
}
97+
return perms
98+
}(),
8299
Org: map[string][]Permission{},
83100
User: []Permission{},
84101
}

0 commit comments

Comments
 (0)