Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 41e50c2

Browse files
authored
Merge pull request #288 from dippynark/fix-vault-tunnel-creation
Improve vault tunnel creation
2 parents 69885a4 + d0a470b commit 41e50c2

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pkg/tarmak/ssh/tunnel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (t *Tunnel) Start() error {
4747
var err error
4848

4949
// ensure there is connectivity to the bastion
50-
args := append(t.sshCommand, "-N", "bastion", "/bin/true")
50+
args := append(t.sshCommand, "bastion", "/bin/true")
5151
cmd := exec.Command(args[0], args[1:len(args)]...)
5252

5353
t.log.Debugf("check SSH connection to bastion cmd=%s", cmd.Args)

pkg/tarmak/vault/vault.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const (
2424
VaultStateUnsealed
2525
VaultStateUnintialised
2626
VaultStateErr
27+
vaultTunnelCreationTimeoutSeconds = 100
2728
)
2829

2930
const (
@@ -107,22 +108,27 @@ func (v *Vault) TunnelFromFQDNs(vaultInternalFQDNs []string, vaultCA string) (in
107108
return
108109
}
109110

110-
if health.Standby == false && health.Sealed == false {
111+
if health.Standby == false && health.Sealed == false && health.Initialized == true {
111112
activeNode <- pos
112-
113113
}
114114

115115
}(pos)
116116
}
117117

118-
activePos := <-activeNode
118+
var activePos int
119+
select {
120+
case activePos = <-activeNode:
121+
v.log.Debug("active channel position recieved")
122+
case <-time.After(vaultTunnelCreationTimeoutSeconds * time.Second):
123+
return nil, fmt.Errorf("failed to retrieve active channel position")
124+
}
119125

120126
go func(activePos int) {
121127

122128
// wait for all tunnel attempts
123129
wg.Wait()
124130

125-
// stop tunnels
131+
// stop non-active tunnels
126132
for pos, _ := range tunnels {
127133
if pos == activePos {
128134
continue

0 commit comments

Comments
 (0)