File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 5
5
6
6
"golang.org/x/xerrors"
7
7
8
+ "github.com/open-policy-agent/opa/ast"
8
9
"github.com/open-policy-agent/opa/rego"
9
10
10
11
"github.com/coder/coder/coderd/tracing"
@@ -32,6 +33,18 @@ func (pa *PartialAuthorizer) Authorize(ctx context.Context, object Object) error
32
33
return nil
33
34
}
34
35
36
+ // No queries means always false
37
+ if len (pa .preparedQueries ) == 0 {
38
+ return ForbiddenWithInternal (xerrors .Errorf ("policy disallows request" ), pa .input , nil )
39
+ }
40
+
41
+ parsed , err := ast .InterfaceToValue (map [string ]interface {}{
42
+ "object" : object ,
43
+ })
44
+ if err != nil {
45
+ return xerrors .Errorf ("parse object: %w" , err )
46
+ }
47
+
35
48
// How to interpret the results of the partial queries.
36
49
// We have a list of queries that are along the lines of:
37
50
// `input.object.org_owner = ""; "me" = input.object.owner`
@@ -45,9 +58,7 @@ func (pa *PartialAuthorizer) Authorize(ctx context.Context, object Object) error
45
58
EachQueryLoop:
46
59
for _ , q := range pa .preparedQueries {
47
60
// We need to eval each query with the newly known fields.
48
- results , err := q .Eval (ctx , rego .EvalInput (map [string ]interface {}{
49
- "object" : object ,
50
- }))
61
+ results , err := q .Eval (ctx , rego .EvalParsedInput (parsed ))
51
62
if err != nil {
52
63
continue EachQueryLoop
53
64
}
You can’t perform that action at this time.
0 commit comments