-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[fga] prebuild access #18560
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
[fga] prebuild access #18560
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,9 +134,14 @@ export class WorkspaceService { | |
|
||
// Internal method for allowing for additional DBs to be passed in | ||
private async doGetWorkspace(userId: string, workspaceId: string, db: WorkspaceDB = this.db): Promise<Workspace> { | ||
await this.auth.checkPermissionOnWorkspace(userId, "access", workspaceId); | ||
|
||
const workspace = await db.findById(workspaceId); | ||
|
||
if (workspace?.type === "prebuild" && workspace.projectId) { | ||
await this.auth.checkPermissionOnProject(userId, "read_prebuild", workspace.projectId); | ||
} else { | ||
await this.auth.checkPermissionOnWorkspace(userId, "access", workspaceId); | ||
} | ||
|
||
// TODO(gpl) We might want to add || !!workspace.softDeleted here in the future, but we were unsure how that would affect existing clients | ||
// In order to reduce risk, we leave it for a future changeset. | ||
if (!workspace || workspace.deleted) { | ||
|
@@ -678,9 +683,13 @@ export class WorkspaceService { | |
): Promise<HeadlessLogUrls> { | ||
const workspace = await this.db.findByInstanceId(instanceId); | ||
if (!workspace) { | ||
throw new ApplicationError(ErrorCodes.NOT_FOUND, `Workspace for instanceId ${instanceId} not found`); | ||
throw new ApplicationError(ErrorCodes.NOT_FOUND, `Prebuild for instanceId ${instanceId} not found`); | ||
} | ||
await this.auth.checkPermissionOnWorkspace(userId, "access", workspace.id); | ||
if (workspace.type !== "prebuild" || !workspace.projectId) { | ||
throw new ApplicationError(ErrorCodes.CONFLICT, `Workspace is not a prebuild`); | ||
} | ||
|
||
await this.auth.checkPermissionOnProject(userId, "read_prebuild", workspace.projectId); | ||
|
||
const wsiPromise = this.db.findInstanceById(instanceId); | ||
await check(workspace); | ||
|
@@ -703,8 +712,8 @@ export class WorkspaceService { | |
workspaceId: string, | ||
client: Pick<GitpodClient, "onWorkspaceImageBuildLogs">, | ||
): Promise<void> { | ||
await this.auth.checkPermissionOnWorkspace(userId, "access", workspaceId); | ||
|
||
// check access | ||
await this.getWorkspace(userId, workspaceId); | ||
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: it still works, but I wonder what the motivation for this change is? Feels a bit like hiding the check somewhat. π€ 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. Ah, missed the indirection. Can we maybe work around this pattern? E.g., by moving the "is prebuild" check in doGetWorkspace into Authorizer, and call it here as well? π€ 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. Resolved sync: As it's only two call-sites, we go with this approach for now. |
||
const logCtx: LogContext = { userId, workspaceId }; | ||
let instance = await this.db.findCurrentInstance(workspaceId); | ||
if (!instance || instance.status.phase === "stopped") { | ||
|
Uh oh!
There was an error while loading. Please reload this page.