Skip to content

feat: Dbauthz is now default, remove out of experimental #6650

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 32 commits into from
Mar 21, 2023

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Mar 17, 2023

What this does

Almost all RBAC checks happen in dbauthz layer now.

Unit tests

I removed AuthorizeAllEndpoints, it was flawed anyway.

A new method of doing rbac assertions was added if you want to check this in a route test. This is no longer required though as dbauthz enforces rbac checks. This exists for edge cases or debugging. Tests are optional similar to how we check audit log entries.

Comment on lines +39 to +41
client, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
user := coderdtest.CreateFirstUser(t, client)
authz := coderdtest.AssertRBAC(t, api, client)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this unit test to see how to asset an rbac action was checked.

This is a very basic check on 1 GET, but shows how you can assert certain rbac checks are run with the given client as the subject.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice feature to have, but given that it essentially duplicates what we already codify in our authz_querier, we should probably use it sparingly.

@Emyrk Emyrk marked this pull request as ready for review March 17, 2023 17:33
@Emyrk Emyrk requested a review from johnstcn March 17, 2023 17:33
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocked by #6654

// RBACAsserter is a helper for asserting that the correct RBAC checks are
// performed. This struct is tied to a given user, and only authorizes calls
// for this user are checked.
type RBACAsserter struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice to have integrated into coderdtest.

@johnstcn johnstcn self-requested a review March 20, 2023 11:58
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far; just one comment where we should probably add a separate unit test for the case of an admin resetting another user's password.

@Emyrk
Copy link
Member Author

Emyrk commented Mar 20, 2023

Looking good so far; just one comment where we should probably add a separate unit test for the case of an admin resetting another user's password.

There is a unit test already 👍

Comment on lines 270 to 283
func caller(skip int) string {
pc, file, line, ok := runtime.Caller(skip + 1)
i := strings.Index(file, "coder")
if i >= 0 {
file = file[i:]
}
str := fmt.Sprintf("%s:%d", file, line)
if ok {
f := runtime.FuncForPC(pc)
filepath.Base(f.Name())
str += " | " + filepath.Base(f.Name())
}
return str
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪

@Emyrk Emyrk merged commit 2321160 into main Mar 21, 2023
@Emyrk Emyrk deleted the stevenmasley/dbauthz_on branch March 21, 2023 14:10
@github-actions github-actions bot locked and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants