chore: verify validity of built in rbac roles (#13296)

Verifies our built in roles are valid according to our policy.go. Working on custom roles requires the dynamic roles to adhere to these rules. Feels fair the built in ones do too.
This commit is contained in:
Steven Masley
2024-05-16 12:07:44 -05:00
committed by GitHub
parent a0fce363cd
commit 194be12133
4 changed files with 84 additions and 9 deletions
+3 -4
View File
@@ -1,9 +1,8 @@
package rbac
import (
"fmt"
"github.com/google/uuid"
"golang.org/x/xerrors"
"github.com/coder/coder/v2/coderd/rbac/policy"
)
@@ -36,10 +35,10 @@ type Object struct {
func (z Object) ValidAction(action policy.Action) error {
perms, ok := policy.RBACPermissions[z.Type]
if !ok {
return fmt.Errorf("invalid type %q", z.Type)
return xerrors.Errorf("invalid type %q", z.Type)
}
if _, ok := perms.Actions[action]; !ok {
return fmt.Errorf("invalid action %q for type %q", action, z.Type)
return xerrors.Errorf("invalid action %q for type %q", action, z.Type)
}
return nil