func main() { cf_debug_server.AddFlags(flag.CommandLine) cf_lager.AddFlags(flag.CommandLine) flag.Parse() logger, reconfigurableSink := cf_lager.New("sshd") serverConfig, err := configure(logger) if err != nil { logger.Error("configure-failed", err) os.Exit(1) } runner := handlers.NewCommandRunner() shellLocator := handlers.NewShellLocator() dialer := &net.Dialer{} sshDaemon := daemon.New( logger, serverConfig, nil, map[string]handlers.NewChannelHandler{ "session": handlers.NewSessionChannelHandler(runner, shellLocator, getDaemonEnvironment(), 15*time.Second), "direct-tcpip": handlers.NewDirectTcpipChannelHandler(dialer), }, ) server := server.NewServer(logger, *address, sshDaemon) members := grouper.Members{ {"sshd", server}, } if dbgAddr := cf_debug_server.DebugAddress(flag.CommandLine); dbgAddr != "" { members = append(grouper.Members{ {"debug-server", cf_debug_server.Runner(dbgAddr, reconfigurableSink)}, }, members...) } group := grouper.NewOrdered(os.Interrupt, members) monitor := ifrit.Invoke(sigmon.New(group)) logger.Info("started") err = <-monitor.Wait() if err != nil { logger.Error("exited-with-failure", err) os.Exit(1) } logger.Info("exited") os.Exit(0) }
func main() { cf_debug_server.AddFlags(flag.CommandLine) cf_lager.AddFlags(flag.CommandLine) flag.Parse() cf_http.Initialize(*communicationTimeout) logger, reconfigurableSink := cf_lager.New("ssh-proxy") initializeDropsonde(logger) proxyConfig, err := configureProxy(logger) if err != nil { logger.Error("configure-failed", err) os.Exit(1) } sshProxy := proxy.New(logger, proxyConfig) server := server.NewServer(logger, *address, sshProxy) consulClient, err := consuladapter.NewClientFromUrl(*consulCluster) if err != nil { logger.Fatal("new-client-failed", err) } registrationRunner := initializeRegistrationRunner(logger, consulClient, *address, clock.NewClock()) members := grouper.Members{ {"ssh-proxy", server}, {"registration-runner", registrationRunner}, } if dbgAddr := cf_debug_server.DebugAddress(flag.CommandLine); dbgAddr != "" { members = append(grouper.Members{{ "debug-server", cf_debug_server.Runner(dbgAddr, reconfigurableSink), }}, members...) } group := grouper.NewOrdered(os.Interrupt, members) monitor := ifrit.Invoke(sigmon.New(group)) logger.Info("started") err = <-monitor.Wait() if err != nil { logger.Error("exited-with-failure", err) os.Exit(1) } logger.Info("exited") os.Exit(0) }
func main() { cf_debug_server.AddFlags(flag.CommandLine) cf_lager.AddFlags(flag.CommandLine) flag.Parse() cf_http.Initialize(*communicationTimeout) logger, reconfigurableSink := cf_lager.New("ssh-proxy") err := dropsonde.Initialize(dropsondeDestination, dropsondeOrigin) if err != nil { logger.Error("failed-to-initialize-dropsonde", err) } proxyConfig, err := configureProxy(logger) if err != nil { logger.Error("configure-failed", err) os.Exit(1) } sshProxy := proxy.New(logger, proxyConfig) server := server.NewServer(logger, *address, sshProxy) members := grouper.Members{ {"ssh-proxy", server}, } if dbgAddr := cf_debug_server.DebugAddress(flag.CommandLine); dbgAddr != "" { members = append(grouper.Members{{ "debug-server", cf_debug_server.Runner(dbgAddr, reconfigurableSink), }}, members...) } group := grouper.NewOrdered(os.Interrupt, members) monitor := ifrit.Invoke(sigmon.New(group)) logger.Info("started") err = <-monitor.Wait() if err != nil { logger.Error("exited-with-failure", err) os.Exit(1) } logger.Info("exited") os.Exit(0) }
func createServer( logger lager.Logger, address string, sshDaemon server.ConnectionHandler, ) (*server.Server, error) { host, port, err := net.SplitHostPort(address) if err != nil { return nil, err } jsonPortMappings := os.Getenv("CF_INSTANCE_PORTS") var portMappings []PortMapping json.Unmarshal([]byte(jsonPortMappings), &portMappings) for _, mapping := range portMappings { if strconv.Itoa(mapping.Internal) == port { port = strconv.Itoa(mapping.External) } } address = strings.Join([]string{host, port}, ":") return server.NewServer(logger, address, sshDaemon), err }
func main() { cf_debug_server.AddFlags(flag.CommandLine) cf_lager.AddFlags(flag.CommandLine) flag.Parse() logger, reconfigurableSink := cf_lager.New("sshd") serverConfig, err := configure(logger) if err != nil { logger.Error("configure-failed", err) os.Exit(1) } sshDaemon := daemon.New(logger, serverConfig, nil, newChannelHandlers()) server := server.NewServer(logger, *address, sshDaemon) members := grouper.Members{ {"sshd", server}, } if dbgAddr := cf_debug_server.DebugAddress(flag.CommandLine); dbgAddr != "" { members = append(grouper.Members{ {"debug-server", cf_debug_server.Runner(dbgAddr, reconfigurableSink)}, }, members...) } group := grouper.NewOrdered(os.Interrupt, members) monitor := ifrit.Invoke(sigmon.New(group)) logger.Info("started") err = <-monitor.Wait() if err != nil { logger.Error("exited-with-failure", err) os.Exit(1) } logger.Info("exited") os.Exit(0) }
) BeforeEach(func() { logger = lagertest.NewTestLogger("test") echoHandler = &fake_server.FakeConnectionHandler{} echoHandler.HandleConnectionStub = func(conn net.Conn) { io.Copy(conn, conn) conn.Close() } echoListener, err := net.Listen("tcp", "127.0.0.1:0") Expect(err).NotTo(HaveOccurred()) echoAddress = echoListener.Addr().String() echoServer = server.NewServer(logger.Session("echo"), "", echoHandler) echoServer.SetListener(echoListener) go echoServer.Serve() serverSSHConfig = &ssh.ServerConfig{ NoClientAuth: true, } serverSSHConfig.AddHostKey(TestHostKey) testDialer = &fakes.FakeDialer{} testDialer.DialStub = net.Dial testHandler = handlers.NewDirectTcpipChannelHandler(testDialer) handler = &fake_handlers.FakeNewChannelHandler{} handler.HandleNewChannelStub = testHandler.HandleNewChannel
Index: 1, }) Expect(err).NotTo(HaveOccurred()) permissions := &ssh.Permissions{ CriticalOptions: map[string]string{ "proxy-target-config": string(targetConfigJson), "log-message": string(logMessageJson), }, } proxyAuthenticator.AuthenticateReturns(permissions, nil) }) JustBeforeEach(func() { sshProxy = proxy.New(logger.Session("proxy"), proxySSHConfig) proxyServer = server.NewServer(logger, "127.0.0.1:0", sshProxy) proxyServer.SetListener(proxyListener) go proxyServer.Serve() sshDaemon = daemon.New(logger.Session("sshd"), daemonSSHConfig, daemonGlobalRequestHandlers, daemonNewChannelHandlers) sshdServer = server.NewServer(logger, "127.0.0.1:0", sshDaemon) sshdServer.SetListener(sshdListener) go sshdServer.Serve() }) AfterEach(func() { proxyServer.Shutdown() sshdServer.Shutdown() }) Context("when a new connection arrives", func() {
handler *fakes.FakeConnectionHandler address string ) BeforeEach(func() { handler = &fakes.FakeConnectionHandler{} address = fmt.Sprintf("127.0.0.1:%d", 7001+GinkgoParallelNode()) logger = lagertest.NewTestLogger("test") }) Describe("Run", func() { var process ifrit.Process BeforeEach(func() { srv = server.NewServer(logger, address, handler) process = ifrit.Invoke(srv) }) AfterEach(func() { process.Signal(os.Interrupt) Eventually(process.Wait()).Should(Receive()) }) It("accepts connections on the specified address", func() { _, err := net.Dial("tcp", address) Expect(err).NotTo(HaveOccurred()) }) Context("when a second client connects", func() { JustBeforeEach(func() {