Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Allow only workspace owner connections #6875

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
HostnamePrefix: cfg.SSHConfig.DeploymentName.String(),
SSHConfigOptions: configSSHOptions,
},
WorkspaceOwnerConnectionOnly: cfg.WorkspaceOwnerConnectionOnly.Value(),
}
if tlsConfig != nil {
options.TLSCertificates = tlsConfig.Certificates
Expand Down
2 changes: 2 additions & 0 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ type Options struct {
SSHConfig codersdk.SSHConfigResponse

HTTPClient *http.Client

WorkspaceOwnerConnectionOnly bool
}

// @title Coder API
Expand Down
21 changes: 21 additions & 0 deletions coderd/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,16 @@ func (api *API) workspaceAgentPTY(rw http.ResponseWriter, r *http.Request) {
return
}

if api.Options.WorkspaceOwnerConnectionOnly {
user := httpmw.UserAuthorization(r)
if user.Actor.ID != workspace.OwnerID.String() {
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
Message: "Only workspace owners can connect to workspace",
})
return
}
}

apiAgent, err := convertWorkspaceAgent(
api.DERPMap, *api.TailnetCoordinator.Load(), workspaceAgent, nil, api.AgentInactiveDisconnectTimeout,
api.DeploymentValues.AgentFallbackTroubleshootingURL.String(),
Expand Down Expand Up @@ -1087,6 +1097,17 @@ func (api *API) workspaceAgentClientCoordinate(rw http.ResponseWriter, r *http.R
httpapi.ResourceNotFound(rw)
return
}

if api.Options.WorkspaceOwnerConnectionOnly {
user := httpmw.UserAuthorization(r)
if user.Actor.ID != workspace.OwnerID.String() {
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
Message: "Only workspace owners can connect to workspace",
})
return
}
}

// This is used by Enterprise code to control the functionality of this route.
override := api.WorkspaceClientCoordinateOverride.Load()
if override != nil {
Expand Down
10 changes: 10 additions & 0 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ type DeploymentValues struct {
GitAuthProviders clibase.Struct[[]GitAuthConfig] `json:"git_auth,omitempty" typescript:",notnull"`
SSHConfig SSHConfig `json:"config_ssh,omitempty" typescript:",notnull"`
WgtunnelHost clibase.String `json:"wgtunnel_host,omitempty" typescript:",notnull"`
WorkspaceOwnerConnectionOnly clibase.Bool `json:"workspace_owner_connection_only,omitempty" typescript:",notnull"`

Config clibase.String `json:"config,omitempty" typescript:",notnull"`
WriteConfig clibase.Bool `json:"write_config,omitempty" typescript:",notnull"`
Expand Down Expand Up @@ -1379,6 +1380,15 @@ Write out the current server configuration to the path specified by --config.`,
Default: "", // empty string means pick best server
Hidden: true,
},
{
Name: "Workspace Owner Connection Only",
Description: "Specifies whether owners only have access to their workspaces.",
Flag: "workspace-owner-connection-only",
Env: "CODER_WORKSPACE_OWNER_CONNECTION_ONLY",
Default: "false",
Value: &c.WorkspaceOwnerConnectionOnly,
YAML: "workspaceOwnerConnectionOnly",
},
}
return opts
}
Expand Down
1 change: 1 addition & 0 deletions site/src/api/typesGenerated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ export interface DeploymentValues {
readonly git_auth?: any
readonly config_ssh?: SSHConfig
readonly wgtunnel_host?: string
readonly workspace_owner_connection_only?: boolean
readonly config?: string
readonly write_config?: boolean
// Named type "github.com/coder/coder/cli/clibase.HostPort" unknown, using "any"
Expand Down