-
Notifications
You must be signed in to change notification settings - Fork 943
chore: ensure default org always exists #12412
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
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e4b1bb8
chore: ensure default org always exists
Emyrk b4a4dd4
fix ctx for inserting first user
Emyrk 627c9f8
The system user could not read organizations
Emyrk 179828c
manual dbmem migration
Emyrk db8da5a
Fix first org name check:
Emyrk b830625
correctly return implied roles
Emyrk 6b086c6
fix authz tests
Emyrk 9997f59
ensure everyone group on first user
Emyrk 3977c71
fix old unit test, changed assumption
Emyrk d35933d
log critical on a 'should never happen' parsing org roles
Emyrk 1b8690f
drop code that attempts to correct the implied roles
Emyrk c9af8c0
Test 'TestInitialRoles' to not expect member role
Emyrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
correctly return implied roles
- Loading branch information
commit b83062521021ab6bb4412d38dfb440b02c57c80b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ok, so a lot to unpack here.
I don't understand what this has to do with ensuring the default organization exists. Why is it necessary in this PR?
Why is it necessary to query
AsSystemRestricted
and then filter in this function? This kind of logic needs to live in the RBAC layer!It looks like the logic is that if you can read the user's UserDataRBAC at global scope and are just a member of the organization, then you can see their roles in that organization. This is an example of shadow access control where we are computing a permission based on combinations of other permissions, and is going to be undocumented and hard to understand.
The problem here is that we made UserDataRBAC a deployment-scoped resource, but some of the information is not actually global scope (organization roles). Fix the resource scoping issue, don't hack permissions out of other permissions.
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.
Yea, this came up as a result of this PR fixing up some unit tests that behavior changed. One of them was we used to insert the
OrgMember()
role explicitly. An oversight, as this query adds in implied roles automatically:coder/coderd/database/queries/users.sql
Lines 217 to 218 in d35933d
So
GetAuthorizationUserRoles
is the source of truth. This api call was just returning the[]string
fieldRoles
, which is not correct. So this API call should be usingGetAuthorizationUserRoles
.I can make the function no longer a
system
function, and filter in thedbauthz
layer, but then all calls to this function get an added cost. Which happens on every single api request.coder/coderd/database/dbauthz/dbauthz.go
Lines 1005 to 1008 in d35933d
I think this is a system function as an optimization, since this is just a heavily used function.
It is. I can implement the filter in the dbauthz, but I didn't want to add the cost to everything. But I want to use the correct function for the source of truth for roles.
In general, our ability to relate perms is weak because the policy execution can only take 1 object as input at a time. So the relations are enforced outside of it.
For getting through this PR I could:
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.
Option 3, and the one I might just do. Is just not include the implied roles in the api response. The previous behavior was incorrectly omitting these, so this PR does not need to resolve this behavior.
I made an issue to fix this later: #12427
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.
It's actually the relations themselves that I also have a problem with. We've got this global-scoped permission: read UserDataRBAC that is granting access to org-scoped data via a tensor product with org membership. That makes it impossible to grant access just to the org-scoped data in a single org. If you have access to it in one org you have access to it in every org you are a member of.
It's just a confusing mess is you start allowing permissions to beget other permissions. Roles determine the permissions you have in RBAC. We need an org-scoped resource that represents the roles a user has in that org, and then to assign read permission on that resource to one or more roles in our system.
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.
@spikecurtis Yes, this endpoint is incorrectly assuming
UserDataRBAC
should access the org roles. This is a mistake