@@ -3,11 +3,11 @@ package agentssh
3
3
import (
4
4
"bufio"
5
5
"context"
6
- "crypto/rand"
7
6
"crypto/rsa"
8
7
"errors"
9
8
"fmt"
10
9
"io"
10
+ "math/rand"
11
11
"net"
12
12
"os"
13
13
"os/exec"
@@ -115,11 +115,15 @@ func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prom
115
115
// Clients' should ignore the host key when connecting.
116
116
// The agent needs to authenticate with coderd to SSH,
117
117
// so SSH authentication doesn't improve security.
118
- randomHostKey ,err := rsa .GenerateKey (rand .Reader ,2048 )
118
+
119
+ // Create a deterministic random source
120
+ // nolint: gosec
121
+ deterministicRand := rand .New (rand .NewSource (42 ))
122
+ coderHostKey ,err := rsa .GenerateKey (deterministicRand ,2048 )
119
123
if err != nil {
120
124
return nil ,err
121
125
}
122
- randomSigner ,err := gossh .NewSignerFromKey (randomHostKey )
126
+ coderSigner ,err := gossh .NewSignerFromKey (coderHostKey )
123
127
if err != nil {
124
128
return nil ,err
125
129
}
@@ -190,7 +194,7 @@ func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prom
190
194
slog .Error (err ))
191
195
},
192
196
Handler :s .sessionHandler ,
193
- HostSigners : []ssh.Signer {randomSigner },
197
+ HostSigners : []ssh.Signer {coderSigner },
194
198
LocalPortForwardingCallback :func (ctx ssh.Context ,destinationHost string ,destinationPort uint32 )bool {
195
199
// Allow local port forwarding all!
196
200
s .logger .Debug (ctx ,"local port forward" ,