-
Notifications
You must be signed in to change notification settings - Fork 905
refactor(coderd): fetch owner information when authorizing workspace agent #9123
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 all commits
11c20d6
da03c4b
317537c
8e2430d
4aa23c6
41561b9
0cb0d18
e6ce0f5
b1d4084
b64a870
73de552
1218fa4
8e222e3
e8844ae
06bbda2
3e21545
3a603fc
267aa6c
6e0d3b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
-- name: GetWorkspaceAgentByAuthToken :one | ||
SELECT | ||
* | ||
FROM | ||
workspace_agents | ||
WHERE | ||
auth_token = $1 | ||
ORDER BY | ||
created_at DESC; | ||
|
||
-- name: GetWorkspaceAgentByID :one | ||
SELECT | ||
* | ||
|
@@ -200,3 +190,56 @@ WHERE | |
WHERE | ||
wb.workspace_id = @workspace_id :: uuid | ||
); | ||
|
||
-- name: GetWorkspaceAgentAndOwnerByAuthToken :one | ||
SELECT | ||
sqlc.embed(workspace_agents), | ||
workspaces.id AS workspace_id, | ||
users.id AS owner_id, | ||
users.username AS owner_name, | ||
users.status AS owner_status, | ||
array_cat( | ||
array_append(users.rbac_roles, 'member'), | ||
array_append(ARRAY[]::text[], 'organization-member:' || organization_members.organization_id::text) | ||
)::text[] as owner_roles, | ||
array_agg(COALESCE(group_members.group_id::text, ''))::text[] AS owner_groups | ||
FROM users | ||
INNER JOIN | ||
workspaces | ||
ON | ||
workspaces.owner_id = users.id | ||
INNER JOIN | ||
workspace_builds | ||
ON | ||
workspace_builds.workspace_id = workspaces.id | ||
INNER JOIN | ||
workspace_resources | ||
ON | ||
workspace_resources.job_id = workspace_builds.job_id | ||
INNER JOIN | ||
workspace_agents | ||
ON | ||
workspace_agents.resource_id = workspace_resources.id | ||
INNER JOIN -- every user is a member of some org | ||
organization_members | ||
ON | ||
organization_members.user_id = users.id | ||
LEFT JOIN -- as they may not be a member of any groups | ||
group_members | ||
ON | ||
group_members.user_id = users.id | ||
WHERE | ||
-- TODO: we can add more conditions here, such as: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: out of curiosity, why is it left for later improvement? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would change the existing behaviour; right now we just get the agent by the token without further restrictions. |
||
-- 1) The user must be active | ||
-- 2) The user must not be deleted | ||
-- 3) The workspace must be running | ||
workspace_agents.auth_token = @auth_token | ||
GROUP BY | ||
workspace_agents.id, | ||
workspaces.id, | ||
users.id, | ||
organization_members.organization_id, | ||
workspace_builds.build_number | ||
ORDER BY | ||
workspace_builds.build_number DESC | ||
LIMIT 1; |
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'm curious if we should start testing users being part of 2 organizations.
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.
TBH I'd honestly defer it until we start having multiple organizations. I'm not sure if we expose multi-orgs at a higher level, or plan to?
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.
My comment was rather preventing the accumulation of technical debt, but we can leave it for now.
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.
@mtojek we have quite a bit of the 1 org assumption.