-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[public-api] Validate Workspace IDs #15423
Conversation
}, | ||
}, | ||
} | ||
t.Run("invalid argument when workspace ID is missing", func(t *testing.T) { |
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.
Changing the tests into individual sub-tests made it much easier to follow the test and debug.
switch req.Msg.GetPort().GetPolicy() { | ||
case v1.PortPolicy_PORT_POLICY_PRIVATE: | ||
_, err = conn.OpenPort(ctx, workspaceID, &protocol.WorkspaceInstancePort{ | ||
Port: float64(req.Msg.Port.Port), | ||
Visibility: protocol.PortVisibilityPrivate, | ||
}) | ||
} else if req.Msg.Port.Policy == v1.PortPolicy_PORT_POLICY_PUBLIC { | ||
_, err = conn.OpenPort(ctx, req.Msg.GetWorkspaceId(), &protocol.WorkspaceInstancePort{ | ||
case v1.PortPolicy_PORT_POLICY_PUBLIC: | ||
_, err = conn.OpenPort(ctx, workspaceID, &protocol.WorkspaceInstancePort{ | ||
Port: float64(req.Msg.Port.Port), | ||
Visibility: protocol.PortVisibilityPublic, | ||
}) | ||
default: | ||
return nil, connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("Unknown port policy specified.")) | ||
} | ||
if err != nil { | ||
log.WithField("workspace_id", workspaceID).Error("Failed to update port") | ||
return nil, proxy.ConvertError(err) | ||
} |
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.
Drive-by cleanup: this ensures that an unknown port policy fails on the API layer. Previously, it would skip both branches and return OK, without actually doing anything.
|
||
func ValidateWorkspaceID(id string) error { | ||
if !WorkspaceIDPattern.MatchString(id) { | ||
return fmt.Errorf("id '%s' does not match workspace ID regex '%s': %w", id, WorkspaceIDPattern.String(), InvalidWorkspaceID) |
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.
return fmt.Errorf("id '%s' does not match workspace ID regex '%s': %w", id, WorkspaceIDPattern.String(), InvalidWorkspaceID) | |
return xerrors.Errorf("id '%s' does not match workspace ID regex '%s': %w", id, WorkspaceIDPattern.String(), InvalidWorkspaceID) |
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.
LGTM
3e53270
to
fca202c
Compare
/werft run 👍 started the job as gitpod-build-mp-papi-validate-workspace-id.4 |
/hold this appears to be blocking tide |
/unhold tide is no longer blocked, see https://prow.gitpod-dev.com/tide |
/werft run 👍 started the job as gitpod-build-mp-papi-validate-workspace-id.5 |
Thanks @kylos101, there are some flaky supervisor tests which caused the build to fail |
Description
Adds validation to Workspace IDs on the API level
Related Issue(s)
Fixes #
How to test
Unit tests
Release Notes
Documentation
Werft options:
If enabled this will build
install/preview
Valid options are
all
,workspace
,webapp
,ide
,jetbrains
,vscode
,ssh