diff --git a/lib/reversetunnel/localsite_test.go b/lib/reversetunnel/localsite_test.go index 81cb4e0c77d61..9b92ff19faa90 100644 --- a/lib/reversetunnel/localsite_test.go +++ b/lib/reversetunnel/localsite_test.go @@ -471,6 +471,7 @@ func Test_shouldDialAndForward(t *testing.T) { }, nil, ) + require.NoError(t, err) openSSHNode, err := types.NewNode( "openssh", types.SubKindOpenSSHNode, diff --git a/lib/srv/forward/sshserver.go b/lib/srv/forward/sshserver.go index 788439c92dbe4..2db32a04376dd 100644 --- a/lib/srv/forward/sshserver.go +++ b/lib/srv/forward/sshserver.go @@ -315,14 +315,12 @@ func (s *ServerConfig) CheckDefaults() error { s.TracerProvider = tracing.DefaultProvider() } - if s.component == "" { - switch { - case s.TargetServer != nil && s.TargetServer.GetKind() == types.KindGitServer: - s.component = teleport.ComponentForwardingGit - s.Emitter = git.NewEmitter(s.Emitter) - default: - s.component = teleport.ComponentForwardingNode - } + switch { + case s.TargetServer != nil && s.TargetServer.GetKind() == types.KindGitServer: + s.component = teleport.ComponentForwardingGit + s.Emitter = git.NewEmitter(s.Emitter) + default: + s.component = teleport.ComponentForwardingNode } return nil } @@ -345,7 +343,7 @@ func New(c ServerConfig) (*Server, error) { s := &Server{ component: c.component, - logger: slog.With(teleport.ComponentKey, teleport.ComponentForwardingNode, + logger: slog.With(teleport.ComponentKey, c.component, "src_addr", c.SrcAddr.String(), "dst_addr", c.DstAddr.String(), ), @@ -519,14 +517,10 @@ func (s *Server) GetHostSudoers() srv.HostSudoers { return &srv.HostSudoersNotImplemented{} } -// GetInfo returns a services.Server that represents this server. +// GetInfo returns a types.Server that represents this server. func (s *Server) GetInfo() types.Server { - spec := types.ServerSpecV2{ - Addr: s.AdvertiseAddr(), - } - if s.targetServer != nil { - spec.Hostname = s.targetServer.GetHostname() - spec.GitHub = s.targetServer.GetGitHub() + if s.component == teleport.ComponentForwardingGit && s.targetServer != nil { + return s.targetServer } return &types.ServerV2{ Kind: types.KindNode, @@ -535,7 +529,9 @@ func (s *Server) GetInfo() types.Server { Name: s.ID(), Namespace: s.GetNamespace(), }, - Spec: spec, + Spec: types.ServerSpecV2{ + Addr: s.AdvertiseAddr(), + }, } } diff --git a/lib/srv/regular/sshserver_test.go b/lib/srv/regular/sshserver_test.go index e0cbd76424c91..b3948e08994ae 100644 --- a/lib/srv/regular/sshserver_test.go +++ b/lib/srv/regular/sshserver_test.go @@ -1675,6 +1675,7 @@ func TestProxyRoundRobin(t *testing.T) { Log: logger, LockWatcher: lockWatcher, NodeWatcher: nodeWatcher, + GitServerWatcher: newGitServerWatcher(ctx, t, proxyClient), CertAuthorityWatcher: caWatcher, CircuitBreakerConfig: breaker.NoopBreakerConfig(), }) @@ -1814,6 +1815,7 @@ func TestProxyDirectAccess(t *testing.T) { Log: logger, LockWatcher: lockWatcher, NodeWatcher: nodeWatcher, + GitServerWatcher: newGitServerWatcher(ctx, t, proxyClient), CertAuthorityWatcher: caWatcher, CircuitBreakerConfig: breaker.NoopBreakerConfig(), }) @@ -2502,6 +2504,7 @@ func TestParseSubsystemRequest(t *testing.T) { Log: logrus.StandardLogger(), LockWatcher: lockWatcher, NodeWatcher: nodeWatcher, + GitServerWatcher: newGitServerWatcher(ctx, t, proxyClient), CertAuthorityWatcher: caWatcher, }) require.NoError(t, err) @@ -2766,6 +2769,7 @@ func TestIgnorePuTTYSimpleChannel(t *testing.T) { Log: logger, LockWatcher: lockWatcher, NodeWatcher: nodeWatcher, + GitServerWatcher: newGitServerWatcher(ctx, t, proxyClient), CertAuthorityWatcher: caWatcher, }) require.NoError(t, err) @@ -3105,6 +3109,18 @@ func newNodeWatcher(ctx context.Context, t *testing.T, client *authclient.Client t.Cleanup(nodeWatcher.Close) return nodeWatcher } +func newGitServerWatcher(ctx context.Context, t *testing.T, client *authclient.Client) *services.GenericWatcher[types.Server, readonly.Server] { + watcher, err := services.NewGitServerWatcher(ctx, services.GitServerWatcherConfig{ + ResourceWatcherConfig: services.ResourceWatcherConfig{ + Component: "test", + Client: client, + }, + GitServerGetter: client, + }) + require.NoError(t, err) + t.Cleanup(watcher.Close) + return watcher +} func newCertAuthorityWatcher(ctx context.Context, t *testing.T, client types.Events) *services.CertAuthorityWatcher { caWatcher, err := services.NewCertAuthorityWatcher(ctx, services.CertAuthorityWatcherConfig{ @@ -3189,6 +3205,7 @@ func TestHostUserCreationProxy(t *testing.T) { Log: logger, LockWatcher: lockWatcher, NodeWatcher: nodeWatcher, + GitServerWatcher: newGitServerWatcher(ctx, t, proxyClient), CertAuthorityWatcher: caWatcher, CircuitBreakerConfig: breaker.NoopBreakerConfig(), }) diff --git a/lib/srv/sess.go b/lib/srv/sess.go index a125ca254da55..57ba21a602135 100644 --- a/lib/srv/sess.go +++ b/lib/srv/sess.go @@ -1481,8 +1481,8 @@ func newRecorder(s *session, ctx *ServerContext) (events.SessionPreparerRecorder return events.WithNoOpPreparer(events.NewDiscardRecorder()), nil } - // Don't record Git commands through Git proxy servers. Dedicated Git - // command events will be emitted. + // Git commands have no recordings. Dedicated Git command events will be + // emitted. if s.registry.Srv.Component() == teleport.ComponentForwardingGit { return events.WithNoOpPreparer(events.NewDiscardRecorder()), nil } diff --git a/lib/web/apiserver_test.go b/lib/web/apiserver_test.go index 5b78a5cd60c54..bbda0cc700ada 100644 --- a/lib/web/apiserver_test.go +++ b/lib/web/apiserver_test.go @@ -385,6 +385,15 @@ func newWebSuiteWithConfig(t *testing.T, cfg webSuiteConfig) *WebSuite { }) require.NoError(t, err) + proxyGitServerWatcher, err := services.NewGitServerWatcher(s.ctx, services.GitServerWatcherConfig{ + ResourceWatcherConfig: services.ResourceWatcherConfig{ + Component: teleport.ComponentProxy, + Client: s.proxyClient, + }, + GitServerGetter: s.proxyClient, + }) + require.NoError(t, err) + caWatcher, err := services.NewCertAuthorityWatcher(s.ctx, services.CertAuthorityWatcherConfig{ ResourceWatcherConfig: services.ResourceWatcherConfig{ Component: teleport.ComponentProxy, @@ -410,6 +419,7 @@ func newWebSuiteWithConfig(t *testing.T, cfg webSuiteConfig) *WebSuite { DataDir: t.TempDir(), LockWatcher: proxyLockWatcher, NodeWatcher: proxyNodeWatcher, + GitServerWatcher: proxyGitServerWatcher, CertAuthorityWatcher: caWatcher, CircuitBreakerConfig: breaker.NoopBreakerConfig(), LocalAuthAddresses: []string{s.server.TLS.Listener.Addr().String()},