Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: join owner, template, and org in new workspace view#15116

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 23 commits intomainfromstevenmasley/workspace_org_view
Oct 22, 2024

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedOct 16, 2024
edited
Loading

Closes#15114

What this does

Joins in fields likeusername,avatar_url,organization_name,template_name toworkspaces via aview.

Views are a nuisance to maintain, however they have become the only clean way to handle RBAC related objects for:

If this is not done, the backend has to do multiple fetches when trying to retrieve information always displayed like the Owner's username. These fetches have the RBAC issue that they require theREAD permission the related object, whichgets even more complicated with custom roles.

Without these joins, if you giveREAD permission to a workspace in an org, it also requires the permission toREAD the user only to fetch the username & avatar. When using custom roles, these implicit links are confusing to use, and have caused a reported error.

We can further make this better, as some overfetching is still done, but this change is already a lot.

What this costs

We have to maintain yet another view.Insert rant about SQLc supporting client-side views that update with the schema.

RBAC Change

GivingREAD to a workspace now lets you see all these fields without needing perms to the related objects.

-- Ownercoalesce(visible_users.avatar_url,'')AS owner_avatar_url,coalesce(visible_users.username,'')AS owner_username,-- Organizationcoalesce(organizations.name,'')AS organization_name,coalesce(organizations.display_name,'')AS organization_display_name,coalesce(organizations.icon,'')AS organization_icon,coalesce(organizations.description,'')AS organization_description,-- Templatecoalesce(templates.name,'')AS template_name,coalesce(templates.display_name,'')AS template_display_name,coalesce(templates.icon,'')AS template_icon,coalesce(templates.description,'')AS template_description

Guardrails

Converting toWorkspaceTable is guarded to stay in sync with the view. If you update the view, but not the converter function, this test will fail.

// TestWorkspaceTableConvert verifies all workspace fields are converted
// when reducing a `Workspace` to a `WorkspaceTable`.
// This test is a guard rail to prevent developer oversight mistakes.
funcTestWorkspaceTableConvert(t*testing.T) {
.

And static structs are also guarded. Does the same as above, but ignores the converter function.

funcTestViewSubsetWorkspace(t*testing.T) {

We useWorkspaceTable for audit logs, since fields likeUsername are mutable, it would not make sense to include in the audit log with a workspace. It is sourced from the mutable field of Users.

@EmyrkEmyrkforce-pushed thestevenmasley/workspace_org_view branch fromaf796d7 toe1cb2cfCompareOctober 18, 2024 14:08
@EmyrkEmyrk marked this pull request as ready for reviewOctober 18, 2024 14:40
@EmyrkEmyrk changed the titlechore: new workspace view to join in owner, template, and orgchore: join owner, template, and org in new workspace viewOct 18, 2024
Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

submitting partial review now

| WorkspaceBuild<br><i>start, stop</i> | <table><thead><tr><th>Field</th><th>Tracked</th></tr></thead><tbody><tr><td>build_number</td><td>false</td></tr><tr><td>created_at</td><td>false</td></tr><tr><td>daily_cost</td><td>false</td></tr><tr><td>deadline</td><td>false</td></tr><tr><td>id</td><td>false</td></tr><tr><td>initiator_by_avatar_url</td><td>false</td></tr><tr><td>initiator_by_username</td><td>false</td></tr><tr><td>initiator_id</td><td>false</td></tr><tr><td>job_id</td><td>false</td></tr><tr><td>max_deadline</td><td>false</td></tr><tr><td>provisioner_state</td><td>false</td></tr><tr><td>reason</td><td>false</td></tr><tr><td>template_version_id</td><td>true</td></tr><tr><td>transition</td><td>false</td></tr><tr><td>updated_at</td><td>false</td></tr><tr><td>workspace_id</td><td>false</td></tr></tbody></table> |
| WorkspaceProxy<br><i></i> | <table><thead><tr><th>Field</th><th>Tracked</th></tr></thead><tbody><tr><td>created_at</td><td>true</td></tr><tr><td>deleted</td><td>false</td></tr><tr><td>derp_enabled</td><td>true</td></tr><tr><td>derp_only</td><td>true</td></tr><tr><td>display_name</td><td>true</td></tr><tr><td>icon</td><td>true</td></tr><tr><td>id</td><td>true</td></tr><tr><td>name</td><td>true</td></tr><tr><td>region_id</td><td>true</td></tr><tr><td>token_hashed_secret</td><td>true</td></tr><tr><td>updated_at</td><td>false</td></tr><tr><td>url</td><td>true</td></tr><tr><td>version</td><td>true</td></tr><tr><td>wildcard_hostname</td><td>true</td></tr></tbody></table> |
| WorkspaceTable<br><i></i> | <table><thead><tr><th>Field</th><th>Tracked</th></tr></thead><tbody><tr><td>automatic_updates</td><td>true</td></tr><tr><td>autostart_schedule</td><td>true</td></tr><tr><td>created_at</td><td>false</td></tr><tr><td>deleted</td><td>false</td></tr><tr><td>deleting_at</td><td>true</td></tr><tr><td>dormant_at</td><td>true</td></tr><tr><td>favorite</td><td>true</td></tr><tr><td>id</td><td>true</td></tr><tr><td>last_used_at</td><td>false</td></tr><tr><td>name</td><td>true</td></tr><tr><td>organization_id</td><td>false</td></tr><tr><td>owner_id</td><td>true</td></tr><tr><td>template_id</td><td>true</td></tr><tr><td>ttl</td><td>true</td></tr><tr><td>updated_at</td><td>false</td></tr></tbody></table> |
Copy link
Member

Choose a reason for hiding this comment

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

Can we keep the old resource name? I don't think admins care if there is a difference between a change to aWorkspaceTable or a change to aWorkspace?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

The type is stillworkspace to admins:

case database.WorkspaceTable:
returndatabase.ResourceTypeWorkspace

It is justWorkspaceTable in Go

@EmyrkEmyrk requested a review fromjohnstcnOctober 21, 2024 16:14
// Handle some special cases
switch v.Type() {
case reflect.TypeOf(time.Time{}):
v.Set(reflect.ValueOf(time.Date(2020, 5, 2, 5, 19, 21, 30, time.UTC)))
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: use a non-UTC timezone

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I am going to be lazy here.

Previously this data was fetched via seperate queries. This causedan issue in orgs, as users are site wide scoped. So user readaccess was required to read another user's username.Now it is all joined into the workspace, implcitly giving read permsto some fields in related objects.
This reverts commite23704c.
@EmyrkEmyrkforce-pushed thestevenmasley/workspace_org_view branch fromb05b00c to6e448d8CompareOctober 22, 2024 14:05
@EmyrkEmyrk merged commit343f8ec intomainOct 22, 2024
27 checks passed
@EmyrkEmyrk deleted the stevenmasley/workspace_org_view branchOctober 22, 2024 14:20
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsOct 22, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

RBAC error when viewing all users' workspaces
2 participants
@Emyrk@johnstcn

[8]ページ先頭

©2009-2025 Movatter.jp