Skip to content

chore: Rewrite rbac rego -> SQL clause #5138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Begin removing all old code
  • Loading branch information
Emyrk committed Nov 20, 2022
commit 4b2e99f53c0022237de1f93cf5742fb6f1133fbe
3 changes: 2 additions & 1 deletion coderd/rbac/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rbac
import (
"context"
_ "embed"
"github.com/coder/coder/coderd/rbac/regosql"
"sync"

"github.com/open-policy-agent/opa/rego"
Expand All @@ -20,7 +21,7 @@ type Authorizer interface {

type PreparedAuthorized interface {
Authorize(ctx context.Context, object Object) error
Compile() (AuthorizeFilter, error)
Compile(cfg regosql.ConvertConfig) (AuthorizeFilter, error)
}

// Filter takes in a list of objects, and will filter the list removing all
Expand Down
2 changes: 1 addition & 1 deletion coderd/rbac/authz_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ func testAuthorize(t *testing.T, name string, subject subject, sets ...[]authTes

// Ensure the partial can compile to a SQL clause.
// This does not guarantee that the clause is valid SQL.
_, err = Compile(partialAuthz)
_, err = Compile(ConfigWithACL(), partialAuthz)
require.NoError(t, err, "compile prepared authorizer")

// Also check the rego policy can form a valid partial query result.
Expand Down
5 changes: 3 additions & 2 deletions coderd/rbac/partial.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rbac
import (
"context"

"github.com/coder/coder/coderd/rbac/regosql"
"golang.org/x/xerrors"

"github.com/open-policy-agent/opa/ast"
Expand All @@ -28,8 +29,8 @@ type PartialAuthorizer struct {

var _ PreparedAuthorized = (*PartialAuthorizer)(nil)

func (pa *PartialAuthorizer) Compile() (AuthorizeFilter, error) {
filter, err := Compile(pa)
func (pa *PartialAuthorizer) Compile(cfg regosql.ConvertConfig) (AuthorizeFilter, error) {
filter, err := Compile(cfg, pa)
if err != nil {
return nil, xerrors.Errorf("compile: %w", err)
}
Expand Down
Loading