-
Notifications
You must be signed in to change notification settings - Fork 1.2k
test: Add unit test for rbac Authorize() function
#853
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
Changes from 1 commit
ab61328
03e4d0f
9981291
3ab32da
e1d5893
84a90f3
1fac0d9
1e3aac0
e977e84
00a7c3f
1f04c01
fbf4db1
4946897
7e6cc66
a0017e5
4b110b3
65ef4e3
d294786
c1f8945
01f3d40
de7de6e
4c86e44
30c6568
a419a65
bbd1c4c
def010f
c4ee590
84e3ab9
c2eec18
5a2834a
913d141
2804b92
5698938
75ed8ef
b2db661
26ef1e6
19aba30
ceee9cd
ee8bf04
44c02a1
dfb9ad1
e482d2c
a4e038f
9918c16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # Authz | ||
|
|
||
| Package `authz` implements AuthoriZation for Coder. | ||
|
|
||
| ## Overview | ||
|
|
||
| Authorization defines what **permission** an **subject** has to perform **actions** to **resources**: | ||
| - **Permission** is binary: *yes* (allowed) or *no* (denied). | ||
| - **Subject** in this case is anything that implements interface `authz.Subject`. | ||
| - **Action** here is an enumerated list of actions, but we stick to `Create`, `Read`, `Update`, and `Delete` here. | ||
| - **Resource** here is anything that implements `authz.Resource`. | ||
|
|
||
| ## Permission Structure | ||
|
|
||
| A **permission** is a rule that grants or denies access for a **subject** to perform an **action** on a **resource**. | ||
| A **permission** is always applied at a given **level**: | ||
|
|
||
| - **site** level applies to all resources in a given Coder deployment. | ||
| - **org** level applies to all resources that have an organization owner (`org_owner`) | ||
| - **user** level applies to all resources that have an owner with the same ID as the subject. | ||
|
|
||
| **Permissions** at a higher **level** always override permissions at a **lower** level. | ||
|
|
||
| The effect of a **permission** can be: | ||
| - **positive** (allows) | ||
| - **negative** (denies) | ||
| - **abstain** (neither allows or denies, but interpreted as deny by default) | ||
|
||
|
|
||
| **Negative** permissions **always** override **positive** permissions at the same level. | ||
| Both **negative** and **positive** permissions override **abstain** at the same level. | ||
|
|
||
| This can be represented by the following truth table, where Y represents *positive*, N represents *negative*, and _ represents *abstain*: | ||
|
|
||
| | Action | Positive | Negative | Result | | ||
| |--------|----------|----------|--------| | ||
| | read | Y | _ | Y | | ||
| | read | Y | N | N | | ||
| | read | _ | _ | _ | | ||
| | read | _ | N | Y | | ||
|
|
||
|
|
||
| ## Permission Representation | ||
|
|
||
| **Permissions** are represented in string format as `<sign>?<level>.<resource>.<id>.<action>`, where: | ||
|
|
||
| - `sign` can be either `+` or `-`. If it is omitted, sign is assumed to be `+`. | ||
| - `level` is either `*`, `site`, `org`, or `user`. | ||
| - `resource` is any valid resource type. | ||
| - `id` is any valid UUID v4. | ||
| - `action` is `create`, `read`, `modify`, or `delete`. | ||
|
|
||
| ## Example Permissions | ||
|
|
||
| - `+site.devurl.*.read`: allowed to perform the `read` action against all resources of type `devurl` in a given Coder deployment. | ||
|
||
| - `-user.workspace.*.create`: user is not allowed to create workspaces. | ||
|
|
||
| ## Roles | ||
|
|
||
| A *role* is a set of permissions. When evaluating a role's permission to form an action, all the relevant permissions for the role are combined at each level. Permissions at a higher level override permissions at a lower level. | ||
|
|
||
| The following table shows the per-level role evaluation. | ||
| Y indicates that the role provides positive permissions, N indicates the role provides negative permissions, and _ indicates the role does not provide positive or negative permissions. YN_ indicates that the value in the cell does not matter for the access result. | ||
|
|
||
| | Role (example) | Site | Org | User | Result | | ||
| |-----------------|------|-----|------|--------| | ||
| | site-admin | Y | YN_ | YN_ | Y | | ||
| | no-permission | N | YN_ | YN_ | N | | ||
| | org-admin | _ | Y | YN_ | Y | | ||
| | non-org-member | _ | N | YN_ | N | | ||
| | user | _ | _ | Y | Y | | ||
| | | _ | _ | N | N | | ||
| | unauthenticated | _ | _ | _ | N | | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we default to allows in the absence of denies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's a good idea.
Default deny is the de-facto behaviour of operation for the other authorization implementations I reviewed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just so I understand,
workspaces.*.createwould be interpreted as a deny by default in those implementations?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, for example here: https://sourcegraph.com/github.com/fleetdm/fleet/-/blob/server/authz/policy_test.go?L69
A
niluser is not allowed to either read or writesession. Obviously what you want to deny-by-default depends on what you're building.