-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix spicedb throwing on invalid arguments #20269
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
Conversation
|
|
||
| // this pattern matches v4 UUIDs as well as the new generated workspace ids (e.g. pink-panda-ns35kd21) | ||
| const workspaceIDRegex = RegExp(`^(?:debug-)?${baseWorkspaceIDRegex}$`); | ||
| export const workspaceIDRegex = RegExp(`^(?:debug-)?${baseWorkspaceIDRegex}$`); |
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 wonder where this regex comes from... it hopefully is identical with this one?
@filiptronicek Could you check whether we can easily unify something here? 🤔 The code I cited should be the source of truth.
| import { ContextParser } from "../workspace/context-parser-service"; | ||
| import { workspaceIDRegex } from "@gitpod/gitpod-protocol/lib/util/gitpod-host-url"; | ||
|
|
||
| const isWorkspaceId = (workspaceId?: string) => { |
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.
This kind of method should ideally be part of parse-workspace-id.ts.
| async updateWorkspacePort(req: UpdateWorkspacePortRequest): Promise<UpdateWorkspacePortResponse> { | ||
| if (!req.workspaceId) { | ||
| throw new ApplicationError(ErrorCodes.BAD_REQUEST, "workspaceId is required"); | ||
| if (!isWorkspaceId(req.workspaceId)) { |
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.
🧡
| const permitted = response.permissionship === v1.CheckPermissionResponse_Permissionship.HAS_PERMISSION; | ||
| return { permitted, checkedAt: response.checkedAt?.token }; | ||
| } catch (err) { | ||
| if (isGrpcError(err) && err.code === grpc.status.INVALID_ARGUMENT) { |
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.
Please add a comment on the "why"/context 🙏
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.
Code generally looks great, please have a look at the comments! 🙏
Description
If you called
WorkspaceService.GetWorkspacewithworkspaceId: valid-workspace-id?hello, we would let SpiceDB throw an exception, becausecheckPermissionwould fail. This PR fixes that from 2 fronts:INVALID_ARGUMENTa system exception and instead throw aErrorCodes.BAD_REQUEST.WorkspaceServicemethod that needs it using a Regex that seems to have worked for us for ~ 2 years.Related Issue(s)
Fixes ENT-842
How to test
Make a request to some API under
WorkspaceServerwith an invalid workspace ID, you should get back "a valid workspaceId is required"For requests to other resources or things that this validity check just doesn't catch, the error message will be similar to the following:
{"code":"invalid_argument","message":"Invalid request for permission check: Error: 3 INVALID_ARGUMENT: invalid CheckPermissionRequest.Resource: embedded message failed validation | caused by: invalid ObjectReference.ObjectId: value does not match regex pattern \"^(([a-zA-Z0-9/_|\\\\-=+]{1,})|\\\\*)$\""}