-
Notifications
You must be signed in to change notification settings - Fork 0
/
srv.go
782 lines (698 loc) · 20.3 KB
/
srv.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
/*
Copyright 2015 Gravitational, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package reversetunnel
import (
"fmt"
"net"
"net/http"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/gravitational/configure/cstrings"
"github.com/gravitational/teleport"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/defaults"
"github.com/gravitational/teleport/lib/limiter"
"github.com/gravitational/teleport/lib/services"
"github.com/gravitational/teleport/lib/sshutils"
"github.com/gravitational/teleport/lib/utils"
log "github.com/Sirupsen/logrus"
"github.com/gravitational/roundtrip"
"github.com/gravitational/trace"
"github.com/mailgun/oxy/forward"
"golang.org/x/crypto/ssh"
)
// RemoteSite represents remote teleport site that can be accessed via
// teleport tunnel or directly by proxy
type RemoteSite interface {
// ConnectToServer allows to SSH into remote teleport server
ConnectToServer(addr, user string, auth []ssh.AuthMethod) (*ssh.Client, error)
// DialServer dials teleport server and returns connection
DialServer(addr string) (net.Conn, error)
// Dial dials any address withing reach of remote site's servers
Dial(network, addr string) (net.Conn, error)
// GetLastConnected returns last time the remote site was seen connected
GetLastConnected() time.Time
// GetName returns site name (identified by authority domain's name)
GetName() string
// GetStatus returns status of this site (either offline or connected)
GetStatus() string
// GetClient returns client connected to remote auth server
GetClient() (auth.ClientI, error)
}
// Server represents server connected to one or many remote sites
type Server interface {
// GetSites returns a list of connected remote sites
GetSites() []RemoteSite
// GetSite returns remote site this node belongs to
GetSite(name string) (RemoteSite, error)
// FindSimilarSite returns site that matches domain name
FindSimilarSite(name string) (RemoteSite, error)
// Start starts server
Start() error
// Wait waits for server to close all outstanding operations
Wait()
}
type server struct {
sync.RWMutex
localAuth auth.ClientI
hostCertChecker ssh.CertChecker
userCertChecker ssh.CertChecker
l net.Listener
srv *sshutils.Server
timeout time.Duration
limiter *limiter.Limiter
tunnelSites []*tunnelSite
directSites []*directSite
}
// ServerOption sets reverse tunnel server options
type ServerOption func(s *server)
// ServerTimeout sets server timeout for read and write operations
func ServerTimeout(duration time.Duration) ServerOption {
return func(s *server) {
s.timeout = duration
}
}
// DirectSite instructs server to proxy access to this site not using
// reverse tunnel
func DirectSite(domainName string, clt auth.ClientI) ServerOption {
return func(s *server) {
s.directSites = append(s.directSites, newDirectSite(domainName, clt))
}
}
func SetLimiter(limiter *limiter.Limiter) ServerOption {
return func(s *server) {
s.limiter = limiter
}
}
// NewServer returns an unstarted server
func NewServer(addr utils.NetAddr, hostSigners []ssh.Signer,
clt auth.ClientI, opts ...ServerOption) (Server, error) {
srv := &server{
directSites: []*directSite{},
tunnelSites: []*tunnelSite{},
localAuth: clt,
}
var err error
srv.limiter, err = limiter.NewLimiter(limiter.LimiterConfig{})
if err != nil {
return nil, trace.Wrap(err)
}
for _, o := range opts {
o(srv)
}
if srv.timeout == 0 {
srv.timeout = teleport.DefaultTimeout
}
s, err := sshutils.NewServer(
addr,
srv,
hostSigners,
sshutils.AuthMethods{
PublicKey: srv.keyAuth,
},
sshutils.SetLimiter(srv.limiter),
)
if err != nil {
return nil, err
}
srv.hostCertChecker = ssh.CertChecker{IsAuthority: srv.isHostAuthority}
srv.userCertChecker = ssh.CertChecker{IsAuthority: srv.isUserAuthority}
srv.srv = s
return srv, nil
}
func (s *server) Wait() {
s.srv.Wait()
}
func (s *server) Addr() string {
return s.srv.Addr()
}
func (s *server) Start() error {
return s.srv.Start()
}
func (s *server) Close() error {
return s.srv.Close()
}
func (s *server) HandleNewChan(conn net.Conn, sconn *ssh.ServerConn, nch ssh.NewChannel) {
log.Infof("got new channel request: %v", nch.ChannelType())
switch nch.ChannelType() {
case chanHeartbeat:
log.Infof("got heartbeat request from agent: %v", sconn)
var site *tunnelSite
var remoteConn *remoteConn
var err error
switch sconn.Permissions.Extensions[extCertType] {
case extCertTypeHost:
site, remoteConn, err = s.upsertSite(conn, sconn)
default:
err = trace.Wrap(
teleport.BadParameter(
"certType", "can't retrieve certificate type"))
}
if err != nil {
log.Errorf("failed to upsert site: %v", err)
nch.Reject(ssh.ConnectionFailed, "failed to upsert site")
return
}
ch, req, err := nch.Accept()
if err != nil {
log.Errorf("failed to accept channel: %v", err)
sconn.Close()
return
}
go site.handleHeartbeat(remoteConn, ch, req)
}
}
// isHostAuthority is called during checking the client key, to see if the signing
// key is the real host CA authority key.
func (s *server) isHostAuthority(auth ssh.PublicKey) bool {
keys, err := s.getTrustedCAKeys(services.HostCA)
if err != nil {
log.Errorf("failed to retrieve trusted keys, err: %v", err)
return false
}
for _, k := range keys {
if sshutils.KeysEqual(k, auth) {
return true
}
}
return false
}
// isUserAuthority is called during checking the client key, to see if the signing
// key is the real user CA authority key.
func (s *server) isUserAuthority(auth ssh.PublicKey) bool {
keys, err := s.getTrustedCAKeys(services.UserCA)
if err != nil {
log.Errorf("failed to retrieve trusted keys, err: %v", err)
return false
}
for _, k := range keys {
if sshutils.KeysEqual(k, auth) {
return true
}
}
return false
}
func (s *server) getTrustedCAKeys(CertType services.CertAuthType) ([]ssh.PublicKey, error) {
cas, err := s.localAuth.GetCertAuthorities(CertType)
if err != nil {
return nil, err
}
out := []ssh.PublicKey{}
for _, ca := range cas {
checkers, err := ca.Checkers()
if err != nil {
return nil, trace.Wrap(err)
}
out = append(out, checkers...)
}
return out, nil
}
func (s *server) checkTrustedKey(CertType services.CertAuthType, domainName string, key ssh.PublicKey) error {
cas, err := s.localAuth.GetCertAuthorities(CertType)
if err != nil {
return trace.Wrap(err)
}
for _, ca := range cas {
if ca.DomainName != domainName {
continue
}
checkers, err := ca.Checkers()
if err != nil {
return trace.Wrap(err)
}
for _, checker := range checkers {
if sshutils.KeysEqual(key, checker) {
return nil
}
}
}
return trace.Wrap(&teleport.NotFoundError{
Message: fmt.Sprintf("authority domain %v not found or has no mathching keys", domainName)})
}
func (s *server) keyAuth(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
logger := log.WithFields(log.Fields{
"remote": conn.RemoteAddr(),
"user": conn.User(),
})
logger.Infof("auth attempt with key %v", key.Type())
cert, ok := key.(*ssh.Certificate)
if !ok {
logger.Warningf("server doesn't support provided key type")
return nil, trace.Wrap(
teleport.BadParameter("key", "server doesn't support provided key type"))
}
switch cert.CertType {
case ssh.HostCert:
authDomain, ok := cert.Extensions[utils.CertExtensionAuthority]
if !ok || authDomain == "" {
err := trace.Wrap(teleport.BadParameter("domainName", "missing authority domain"))
logger.Warningf("failed authenticate host, err: %v", err)
return nil, err
}
err := s.hostCertChecker.CheckHostKey(conn.User(), conn.RemoteAddr(), key)
if err != nil {
logger.Warningf("failed authenticate host, err: %v", err)
return nil, trace.Wrap(err)
}
if err := s.hostCertChecker.CheckCert(conn.User(), cert); err != nil {
logger.Warningf("failed to authenticate host err: %v", err)
return nil, trace.Wrap(err)
}
// this fixes possible injection attack
// when we have 2 trusted remote sites, and one can simply
// pose as another. so we have to check that authority
// matches by some other way (in absence of x509 chains)
if err := s.checkTrustedKey(services.HostCA, authDomain, cert.SignatureKey); err != nil {
logger.Warningf("this claims to be signed as authDomain %v, but no matching signing keys found")
return nil, trace.Wrap(err)
}
return &ssh.Permissions{
Extensions: map[string]string{
extHost: conn.User(),
extCertType: extCertTypeHost,
extAuthority: authDomain,
},
}, nil
case ssh.UserCert:
_, err := s.userCertChecker.Authenticate(conn, key)
if err != nil {
logger.Warningf("failed to authenticate user, err: %v", err)
return nil, err
}
if err := s.userCertChecker.CheckCert(conn.User(), cert); err != nil {
logger.Warningf("failed to authenticate user err: %v", err)
return nil, trace.Wrap(err)
}
return &ssh.Permissions{
Extensions: map[string]string{
extHost: conn.User(),
extCertType: extCertTypeUser,
},
}, nil
default:
return nil, trace.Wrap(
teleport.BadParameter("cert",
fmt.Sprintf("unsupported cert type: %v", cert.CertType)))
}
}
func (s *server) upsertSite(conn net.Conn, sshConn *ssh.ServerConn) (*tunnelSite, *remoteConn, error) {
domainName := sshConn.Permissions.Extensions[extAuthority]
if !cstrings.IsValidDomainName(domainName) {
return nil, nil, trace.Wrap(teleport.BadParameter(
"authDomain", fmt.Sprintf("'%v' is a bad domain name", domainName)))
}
s.Lock()
defer s.Unlock()
var site *tunnelSite
for _, st := range s.tunnelSites {
if st.domainName == domainName {
site = st
break
}
}
log.Infof("found authority domain: %v", domainName)
var err error
var remoteConn *remoteConn
if site != nil {
if remoteConn, err = site.addConn(conn, sshConn); err != nil {
return nil, nil, trace.Wrap(err)
}
} else {
site, err = newRemoteSite(s, domainName)
if err != nil {
return nil, nil, trace.Wrap(err)
}
if remoteConn, err = site.addConn(conn, sshConn); err != nil {
return nil, nil, trace.Wrap(err)
}
s.tunnelSites = append(s.tunnelSites, site)
}
return site, remoteConn, nil
}
func (s *server) GetSites() []RemoteSite {
s.RLock()
defer s.RUnlock()
out := make([]RemoteSite, 0, len(s.tunnelSites)+len(s.directSites))
for i := range s.tunnelSites {
out = append(out, s.tunnelSites[i])
}
for i := range s.directSites {
out = append(out, s.directSites[i])
}
return out
}
func (s *server) GetSite(domainName string) (RemoteSite, error) {
s.RLock()
defer s.RUnlock()
for i := range s.tunnelSites {
if s.tunnelSites[i].domainName == domainName {
return s.tunnelSites[i], nil
}
}
for i := range s.directSites {
if s.directSites[i].domainName == domainName {
return s.directSites[i], nil
}
}
return nil, trace.Wrap(teleport.NotFound(
fmt.Sprintf("site '%v' not found", domainName)))
}
// FindSimilarSite finds the site that is the most similar to domain.
// Returns nil if no sites with such domain name.
//
// NOTE: currently the notion of "sites" is not exposed to teleport users via tsh or tctl,
// only Gravitational products use this capability
func (s *server) FindSimilarSite(domainName string) (RemoteSite, error) {
s.RLock()
defer s.RUnlock()
sites := s.GetSites()
// this is always true:
if len(sites) == 1 {
return sites[0], nil
}
result := -1
resultSimilarity := 1
domainName1 := strings.Split(domainName, ".")
log.Infof("Find matching domain: %v", domainName)
for i, site := range sites {
domainName2 := strings.Split(site.GetName(), ".")
similarity := 0
for j := 1; (j <= len(domainName1)) && (j <= len(domainName2)); j++ {
if domainName1[len(domainName1)-j] != domainName2[len(domainName2)-j] {
break
}
similarity++
}
if (similarity > resultSimilarity) || (result == -1) {
result = i
resultSimilarity = similarity
}
}
if result != -1 {
return sites[result], nil
}
return nil, trace.Wrap(teleport.NotFound(
fmt.Sprintf("no site matching '%v' found", domainName)))
}
type remoteConn struct {
sshConn ssh.Conn
conn net.Conn
invalid int32
log *log.Entry
counter int32
}
func (rc *remoteConn) String() string {
return fmt.Sprintf("remoteConn(remoteAddr=%v)", rc.conn.RemoteAddr())
}
func (rc *remoteConn) Close() error {
return rc.sshConn.Close()
}
func (rc *remoteConn) markInvalid(err error) {
rc.log.Infof("%v is marked as invalid because of error: %v", rc, err)
atomic.StoreInt32(&rc.invalid, 1)
}
func (rc *remoteConn) isInvalid() bool {
return atomic.LoadInt32(&rc.invalid) == 1
}
func newRemoteConn(log *log.Entry, conn net.Conn, sshConn ssh.Conn) (*remoteConn, error) {
return &remoteConn{
sshConn: sshConn,
conn: conn,
log: log,
}, nil
}
func newRemoteSite(srv *server, domainName string) (*tunnelSite, error) {
remoteSite := &tunnelSite{
srv: srv,
domainName: domainName,
log: log.WithFields(log.Fields{
teleport.Component: teleport.ComponentReverseTunnel,
teleport.ComponentFields: map[string]string{
"domainName": domainName,
"side": "server",
},
}),
}
// transport uses connection do dial out to the remote address
remoteSite.transport = &http.Transport{
Dial: remoteSite.dialAccessPoint,
}
clt, err := auth.NewClient(
"http://stub:0",
roundtrip.HTTPClient(&http.Client{
Transport: remoteSite.transport,
Timeout: 5 * time.Second,
}))
if err != nil {
return nil, trace.Wrap(err)
}
remoteSite.clt = clt
return remoteSite, nil
}
// tunnelSite is a site accessed via SSH reverse tunnel that established
// between proxy and remote site
type tunnelSite struct {
sync.Mutex
log *log.Entry
domainName string
connections []*remoteConn
lastUsed int
lastActive time.Time
srv *server
transport *http.Transport
clt *auth.Client
}
func (s *tunnelSite) GetClient() (auth.ClientI, error) {
return s.clt, nil
}
func (s *tunnelSite) String() string {
return fmt.Sprintf("remoteSite(%v)", s.domainName)
}
func (s *tunnelSite) nextConn() (*remoteConn, error) {
s.Lock()
defer s.Unlock()
for {
if len(s.connections) == 0 {
return nil, trace.Wrap(
teleport.NotFound("no active connections"))
}
s.lastUsed = (s.lastUsed + 1) % len(s.connections)
remoteConn := s.connections[s.lastUsed]
if !remoteConn.isInvalid() {
s.log.Infof("return connection %v", s.lastUsed)
return remoteConn, nil
}
s.connections = append(s.connections[:s.lastUsed], s.connections[s.lastUsed+1:]...)
s.lastUsed = 0
go remoteConn.Close()
}
}
func (s *tunnelSite) addConn(conn net.Conn, sshConn ssh.Conn) (*remoteConn, error) {
remoteConn, err := newRemoteConn(s.log, conn, sshConn)
if err != nil {
return nil, trace.Wrap(err)
}
s.Lock()
defer s.Unlock()
s.connections = append(s.connections, remoteConn)
s.lastUsed = 0
return remoteConn, nil
}
func (s *tunnelSite) GetStatus() string {
s.Lock()
defer s.Unlock()
diff := time.Now().Sub(s.lastActive)
if diff > 2*defaults.ReverseTunnelAgentHeartbeatPeriod {
return RemoteSiteStatusOffline
}
return RemoteSiteStatusOnline
}
func (s *tunnelSite) setLastActive(t time.Time) {
s.Lock()
defer s.Unlock()
s.lastActive = t
}
func (s *tunnelSite) handleHeartbeat(conn *remoteConn, ch ssh.Channel, reqC <-chan *ssh.Request) {
go func() {
for {
select {
case req := <-reqC:
if req == nil {
s.log.Infof("agent disconnected")
conn.markInvalid(teleport.ConnectionProblem("agent disconnected", nil))
return
}
s.setLastActive(time.Now())
case <-time.After(2 * defaults.ReverseTunnelAgentHeartbeatPeriod):
conn.markInvalid(teleport.ConnectionProblem("agent missed 2 heartbeats", nil))
conn.sshConn.Close()
}
}
}()
}
func (s *tunnelSite) GetName() string {
return s.domainName
}
func (s *tunnelSite) GetLastConnected() time.Time {
s.Lock()
defer s.Unlock()
return s.lastActive
}
func (s *tunnelSite) timeout() time.Duration {
return s.srv.timeout
}
func (s *tunnelSite) ConnectToServer(server, user string, auth []ssh.AuthMethod) (*ssh.Client, error) {
s.log.Infof("ConnectToServer(server=%v, user=%v)", server, user)
remoteConn, err := s.nextConn()
if err != nil {
return nil, trace.Wrap(err)
}
ch, _, err := remoteConn.sshConn.OpenChannel(chanTransport, nil)
if err != nil {
remoteConn.markInvalid(err)
return nil, trace.Wrap(err)
}
// ask remote channel to dial
dialed, err := ch.SendRequest(chanTransportDialReq, true, []byte(server))
if err != nil {
remoteConn.markInvalid(err)
return nil, trace.Wrap(err)
}
if !dialed {
return nil, trace.Errorf("remote server %v is not available", server)
}
transportConn := utils.NewChConn(remoteConn.sshConn, ch)
conn, chans, reqs, err := ssh.NewClientConn(
transportConn, server,
&ssh.ClientConfig{
User: user,
Auth: auth,
})
if err != nil {
s.log.Infof("connectToServer %v", err)
return nil, trace.Wrap(err)
}
return ssh.NewClient(conn, chans, reqs), nil
}
func (s *tunnelSite) tryDialAccessPoint(network, addr string) (net.Conn, error) {
s.log.Infof("tryDialAccessPoint(net=%v, addr=%v)", network, addr)
remoteConn, err := s.nextConn()
if err != nil {
return nil, trace.Wrap(err)
}
ch, _, err := remoteConn.sshConn.OpenChannel(chanAccessPoint, nil)
if err != nil {
remoteConn.markInvalid(err)
s.log.Infof("%v marking connection invalid, conn err: %v", remoteConn.conn.RemoteAddr(), err)
return nil, trace.Wrap(err)
}
return utils.NewChConn(remoteConn.sshConn, ch), nil
}
func (s *tunnelSite) dialAccessPoint(network, addr string) (net.Conn, error) {
s.log.Infof("dialAccessPoint(net=%v, addr=%v)", network, addr)
for {
conn, err := s.tryDialAccessPoint(network, addr)
if err != nil {
if teleport.IsNotFound(err) {
return nil, trace.Wrap(err)
}
continue
}
return conn, nil
}
}
func (s *tunnelSite) tryDial(net, addr string) (net.Conn, error) {
s.log.Infof("tryDial(net=%v, addr=%v)", net, addr)
remoteConn, err := s.nextConn()
if err != nil {
return nil, trace.Wrap(err)
}
var ch ssh.Channel
ch, _, err = remoteConn.sshConn.OpenChannel(chanTransport, nil)
if err != nil {
remoteConn.markInvalid(err)
return nil, trace.Wrap(err)
}
// ask remote channel to dial
var dialed bool
dialed, err = ch.SendRequest(chanTransportDialReq, true, []byte(addr))
if err != nil {
remoteConn.markInvalid(err)
return nil, trace.Wrap(err)
}
if !dialed {
remoteConn.markInvalid(err)
return nil, trace.Wrap(
teleport.ConnectionProblem(
fmt.Sprintf("remote server %v is not available", addr), nil))
}
return utils.NewChConn(remoteConn.sshConn, ch), nil
}
func (s *tunnelSite) Dial(net string, addr string) (net.Conn, error) {
s.log.Infof("Dial(net=%v, addr=%v)", net, addr)
for {
conn, err := s.tryDial(net, addr)
if err != nil {
s.log.Infof("got connection problem: %v", err)
// we interpret it as a "out of connections and will try again"
if teleport.IsNotFound(err) {
return nil, trace.Wrap(err)
}
continue
}
return conn, nil
}
}
func (s *tunnelSite) DialServer(addr string) (net.Conn, error) {
s.log.Infof("DialServer(addr=%v)", addr)
clt, err := s.GetClient()
if err != nil {
return nil, trace.Wrap(err)
}
var knownServers []services.Server
for i := 0; i < 10; i++ {
knownServers, err = clt.GetNodes()
if err != nil {
log.Infof("failed to get servers: %v", err)
time.Sleep(time.Second)
}
}
if err != nil {
return nil, trace.Wrap(err)
}
server, err := findServer(addr, knownServers)
if err != nil {
return nil, trace.Wrap(err)
}
return s.Dial("tcp", server.Addr)
}
func (s *tunnelSite) handleAuthProxy(w http.ResponseWriter, r *http.Request) {
s.log.Infof("handleAuthProxy()")
fwd, err := forward.New(forward.RoundTripper(s.transport), forward.Logger(s.log))
if err != nil {
roundtrip.ReplyJSON(w, http.StatusInternalServerError, err.Error())
return
}
r.URL.Scheme = "http"
r.URL.Host = "stub"
fwd.ServeHTTP(w, r)
}
const (
extHost = "host@teleport"
extCertType = "certtype@teleport"
extAuthority = "auth@teleport"
extCertTypeHost = "host"
extCertTypeUser = "user"
)