Skip to content

Commit 2969fc1

Browse files
committed
fixup! run golangci-lint and goimports
1 parent 8a16947 commit 2969fc1

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

coderd/rbac/authz.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@ func (a RegoAuthorizer) Authorize(ctx context.Context, subjectID string, roles [
5454

5555
results, err := a.query.Eval(ctx, rego.EvalInput(input))
5656
if err != nil {
57-
return ForbiddenWithInternal(xerrors.Errorf("eval rego: %w, err"), input)
57+
return ForbiddenWithInternal(xerrors.Errorf("eval rego: %w, err"), input, results)
5858
}
5959

6060
if len(results) != 1 {
61-
return ForbiddenWithInternal(xerrors.Errorf("expect only 1 result, got %d", len(results)), input)
61+
return ForbiddenWithInternal(xerrors.Errorf("expect only 1 result, got %d", len(results)), input, results)
6262
}
6363

6464
allowedResult, ok := (results[0].Bindings["allowed"]).(bool)
6565
if !ok {
66-
return ForbiddenWithInternal(xerrors.Errorf("expected allowed to be a bool but got %T", allowedResult), input)
66+
return ForbiddenWithInternal(xerrors.Errorf("expected allowed to be a bool but got %T", allowedResult), input, results)
6767
}
6868

69-
if allowedResult {
70-
return ForbiddenWithInternal(xerrors.Errorf("policy disallows request"), input)
69+
if !allowedResult {
70+
return ForbiddenWithInternal(xerrors.Errorf("policy disallows request"), input, results)
7171
}
7272

7373
return nil

coderd/rbac/authz_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ func testAuthorize(t *testing.T, name string, subject subject, sets ...[]authTes
606606
d, _ := json.Marshal(uerr.Input())
607607
t.Logf("input: %s", string(d))
608608
t.Logf("internal error: %+v", uerr.Internal().Error())
609+
t.Logf("output: %+v", uerr.Output())
609610
}
610611
require.NoError(t, err, "expected no error for testcase action %s", a)
611612
continue

coderd/rbac/error.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package rbac
22

3+
import "github.com/open-policy-agent/opa/rego"
4+
35
const (
46
// errUnauthorized is the error message that should be returned to
57
// clients when an action is forbidden. It is intentionally vague to prevent
@@ -13,18 +15,20 @@ type UnauthorizedError struct {
1315
// It is only for debugging purposes.
1416
internal error
1517
input map[string]interface{}
18+
output rego.ResultSet
1619
}
1720

1821
// ForbiddenWithInternal creates a new error that will return a simple
1922
// "forbidden" to the client, logging internally the more detailed message
2023
// provided.
21-
func ForbiddenWithInternal(internal error, input map[string]interface{}) *UnauthorizedError {
24+
func ForbiddenWithInternal(internal error, input map[string]interface{}, output rego.ResultSet) *UnauthorizedError {
2225
if input == nil {
2326
input = map[string]interface{}{}
2427
}
2528
return &UnauthorizedError{
2629
internal: internal,
2730
input: input,
31+
output: output,
2832
}
2933
}
3034

@@ -41,3 +45,8 @@ func (e *UnauthorizedError) Internal() error {
4145
func (e *UnauthorizedError) Input() map[string]interface{} {
4246
return e.input
4347
}
48+
49+
// Output contains the results of the Rego query for debugging.
50+
func (e *UnauthorizedError) Output() rego.ResultSet {
51+
return e.output
52+
}

0 commit comments

Comments
 (0)