Skip to content

Commit 655e8db

Browse files
committed
Fix rbac benchmark
1 parent 212ebce commit 655e8db

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

coderd/rbac/authz.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ func NewAuthorizer(registry prometheus.Registerer) *RegoAuthorizer {
170170
}
171171

172172
type authSubject struct {
173-
ID string `json:"id"`
174-
Roles []Role `json:"roles"`
175-
Groups []string `json:"groups"`
176-
Scope Role `json:"scope"`
173+
ID string `json:"id"`
174+
Roles []Role `json:"roles"`
175+
Groups []string `json:"groups"`
176+
Scope ScopeRole `json:"scope"`
177177
}
178178

179179
// ByRoleName will expand all roleNames into roles before calling Authorize().
@@ -216,7 +216,7 @@ func (a RegoAuthorizer) ByRoleName(ctx context.Context, subjectID string, roleNa
216216

217217
// Authorize allows passing in custom Roles.
218218
// This is really helpful for unit testing, as we can create custom roles to exercise edge cases.
219-
func (a RegoAuthorizer) Authorize(ctx context.Context, subjectID string, roles []Role, scope Role, groups []string, action Action, object Object) error {
219+
func (a RegoAuthorizer) Authorize(ctx context.Context, subjectID string, roles []Role, scope ScopeRole, groups []string, action Action, object Object) error {
220220
input := map[string]interface{}{
221221
"subject": authSubject{
222222
ID: subjectID,
@@ -275,7 +275,7 @@ func (a RegoAuthorizer) PrepareByRoleName(ctx context.Context, subjectID string,
275275

276276
// Prepare will partially execute the rego policy leaving the object fields unknown (except for the type).
277277
// This will vastly speed up performance if batch authorization on the same type of objects is needed.
278-
func (RegoAuthorizer) Prepare(ctx context.Context, subjectID string, roles []Role, scope Role, groups []string, action Action, objectType string) (*PartialAuthorizer, error) {
278+
func (RegoAuthorizer) Prepare(ctx context.Context, subjectID string, roles []Role, scope ScopeRole, groups []string, action Action, objectType string) (*PartialAuthorizer, error) {
279279
auth, err := newPartialAuthorizer(ctx, subjectID, roles, scope, groups, action, objectType)
280280
if err != nil {
281281
return nil, xerrors.Errorf("new partial authorizer: %w", err)

coderd/rbac/authz_internal_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ type subject struct {
2020
// For the unit test we want to pass in the roles directly, instead of just
2121
// by name. This allows us to test custom roles that do not exist in the product,
2222
// but test edge cases of the implementation.
23-
Roles []Role `json:"roles"`
24-
Groups []string `json:"groups"`
25-
Scope Role `json:"scope"`
23+
Roles []Role `json:"roles"`
24+
Groups []string `json:"groups"`
25+
Scope ScopeRole `json:"scope"`
2626
}
2727

2828
type fakeObject struct {

coderd/rbac/partial.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ EachQueryLoop:
121121
return ForbiddenWithInternal(xerrors.Errorf("policy disallows request"), pa.input, nil)
122122
}
123123

124-
func newPartialAuthorizer(ctx context.Context, subjectID string, roles []Role, scope Role, groups []string, action Action, objectType string) (*PartialAuthorizer, error) {
124+
func newPartialAuthorizer(ctx context.Context, subjectID string, roles []Role, scope ScopeRole, groups []string, action Action, objectType string) (*PartialAuthorizer, error) {
125125
input := map[string]interface{}{
126126
"subject": authSubject{
127127
ID: subjectID,

coderd/rbac/policy.rego

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ scope_allow_list {
156156

157157
scope_allow_list {
158158
# If the wildcard is listed in the allow_list, we do not care about the
159-
# object.id. This line is included to prevent partial compliations from
159+
# object.id. This line is included to prevent partial compilations from
160160
# ever needing to include the object.id.
161161
not "*" in input.subject.scope.allow_list
162162
input.object.id != ""

0 commit comments

Comments
 (0)