Skip to content
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

Add WebSocket handler for WebUI database sessions #49749

Merged
merged 20 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0e2468e
feat(web): add websocket handler for database webui sessions
gabrielcorado Dec 4, 2024
1a70cc5
refactor: move common structs into a separate package
gabrielcorado Dec 5, 2024
add121d
refactor(web): use ALPN local proxy to dial databases
gabrielcorado Dec 5, 2024
25f7e6e
Merge branch 'master' into gabrielcorado/pg-webui-handler
gabrielcorado Dec 5, 2024
7a6fd3b
feat(repl): add default registry
gabrielcorado Dec 5, 2024
bbb6b38
refactor(web): code review suggestions
gabrielcorado Dec 12, 2024
6ef2712
refactor: update repl config parameters
gabrielcorado Dec 12, 2024
0db0613
refactor: move default getter implementation
gabrielcorado Dec 13, 2024
b76c6f7
Merge branch 'master' into gabrielcorado/pg-webui-handler
gabrielcorado Dec 13, 2024
6237ed0
feat(web): add supports_interactive field on dbs
gabrielcorado Dec 13, 2024
46df432
Merge branch 'master' into gabrielcorado/pg-webui-handler
gabrielcorado Dec 13, 2024
010445e
refactor: code review suggestions
gabrielcorado Dec 13, 2024
9cb2b71
refactor: update database REPL interfaces
gabrielcorado Dec 13, 2024
4c67214
Merge branch 'master' into gabrielcorado/pg-webui-handler
gabrielcorado Dec 13, 2024
e773a87
chore(web): remove debug print
gabrielcorado Dec 13, 2024
b344080
Merge branch 'master' into gabrielcorado/pg-webui-handler
gabrielcorado Dec 13, 2024
df26468
feat: register postgres repl
gabrielcorado Dec 14, 2024
0e094b9
refactor(web): update MakeDatabase to receive access checker and inte…
gabrielcorado Dec 14, 2024
c05b558
Merge branch 'master' into gabrielcorado/pg-webui-handler
gabrielcorado Dec 14, 2024
a53effd
chore(web): remove unused function
gabrielcorado Dec 14, 2024
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
4 changes: 4 additions & 0 deletions lib/auth/authclient/clt.go
Original file line number Diff line number Diff line change
Expand Up @@ -1897,4 +1897,8 @@ type ClientI interface {

// GitServerClient returns git server client.
GitServerClient() gitserverv1.GitServerServiceClient

// SignDatabaseCSR generates client certificate used by proxy to
// authenticate with a remote database service.
SignDatabaseCSR(ctx context.Context, req *proto.DatabaseCSRRequest) (*proto.DatabaseCSRResponse, error)
}
4 changes: 4 additions & 0 deletions lib/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@ const (

// WebsocketKubeExec provides latency information for a session.
WebsocketKubeExec = "k"

// WebsocketDatabaseSessionRequest is received when a new database session
// is requested.
WebsocketDatabaseSessionRequest = "d"
)

// The following are cryptographic primitives Teleport does not support in
Expand Down
8 changes: 8 additions & 0 deletions lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4641,6 +4641,14 @@ func (process *TeleportProcess) initProxyEndpoint(conn *Connector) error {
AutomaticUpgradesChannels: cfg.Proxy.AutomaticUpgradesChannels,
IntegrationAppHandler: connectionsHandler,
FeatureWatchInterval: retryutils.HalfJitter(web.DefaultFeatureWatchInterval * 2),
DatabasesAddrs: map[string]utils.NetAddr{
defaults.ProtocolPostgres: cfg.Proxy.PostgresAddr,
defaults.ProtocolMySQL: cfg.Proxy.MySQLAddr,
defaults.ProtocolMongoDB: cfg.Proxy.MongoAddr,
},
// TODO(gabrielcorado): place the database REPL getter from
// lib/client/db package once it gets merged.
// DatabaseREPLGetter: ,
}
webHandler, err := web.NewHandler(webConfig)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ type Config struct {
// FeatureWatchInterval is the interval between pings to the auth server
// to fetch new cluster features
FeatureWatchInterval time.Duration

// DatabasesAddrs is the list of separate listeners addresses per database
// protocol.
DatabasesAddrs map[string]utils.NetAddr

// DatabaseREPLGetter is used for retrieving database REPL.
DatabaseREPLGetter DatabaseREPLGetter
}

// SetDefaults ensures proper default values are set if
Expand Down Expand Up @@ -839,6 +846,7 @@ func (h *Handler) bindDefaultEndpoints() {
h.GET("/webapi/sites/:site/sessions", h.WithClusterAuth(h.clusterActiveAndPendingSessionsGet)) // get list of active and pending sessions

h.GET("/webapi/sites/:site/kube/exec/ws", h.WithClusterAuthWebSocket(h.podConnect)) // connect to a pod with exec (via websocket, with auth over websocket)
h.GET("/webapi/sites/:site/db/exec/ws", h.WithClusterAuthWebSocket(h.dbConnect))

// Audit events handlers.
h.GET("/webapi/sites/:site/events/search", h.WithClusterAuth(h.clusterSearchEvents)) // search site events
Expand Down Expand Up @@ -3581,6 +3589,7 @@ func (h *Handler) siteNodeConnect(
}

term, err := NewTerminal(ctx, TerminalHandlerConfig{
Logger: h.logger,
Term: req.Term,
SessionCtx: sessionCtx,
UserAuthClient: clt,
Expand Down Expand Up @@ -3733,6 +3742,7 @@ func (h *Handler) podConnect(
ws: ws,
keepAliveInterval: keepAliveInterval,
log: h.log.WithField(teleport.ComponentKey, "pod"),
logger: h.logger.With(teleport.ComponentKey, "pod"),
userClient: clt,
localCA: hostCA,
configServerAddr: serverAddr,
Expand Down
8 changes: 8 additions & 0 deletions lib/web/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ type webSuiteConfig struct {

// clock to use for all server components
clock clockwork.FakeClock

// databaseREPLGetter allows setting custom database REPLs.
databaseREPLGetter DatabaseREPLGetter

// databasesAddrs allows setting custom database proxy addresses.
databasesAddrs map[string]utils.NetAddr
}

func newWebSuiteWithConfig(t *testing.T, cfg webSuiteConfig) *WebSuite {
Expand Down Expand Up @@ -509,6 +515,8 @@ func newWebSuiteWithConfig(t *testing.T, cfg webSuiteConfig) *WebSuite {
return &proxyClientCert, nil
},
IntegrationAppHandler: &mockIntegrationAppHandler{},
DatabaseREPLGetter: cfg.databaseREPLGetter,
DatabasesAddrs: cfg.databasesAddrs,
}

if handlerConfig.HealthCheckAppServer == nil {
Expand Down
Loading
Loading