@@ -5,13 +5,13 @@ import (
55 "errors"
66 "fmt"
77 "io"
8+ "log/slog"
89 "net"
910 "os"
1011 "sync"
1112
1213 "github.com/epithet-ssh/epithet/pkg/caclient"
1314 "github.com/epithet-ssh/epithet/pkg/sshcert"
14- log "github.com/sirupsen/logrus"
1515 "golang.org/x/crypto/ssh"
1616 "golang.org/x/crypto/ssh/agent"
1717)
@@ -24,12 +24,13 @@ var errAgentStopped = errors.New("agent has been stopped")
2424// has internal synchronization and can be safely accessed from multiple goroutines.
2525// The done channel and closeOnce provide safe shutdown coordination.
2626//
27- // Immutable after creation: agentSocketPath, publicKey, privateKey, caClient
27+ // Immutable after creation: agentSocketPath, publicKey, privateKey, caClient, log
2828// Protected by internal sync: keyring (uses its own locking)
2929// Protected by closeOnce: agentListener, done channel
3030type Agent struct {
3131 keyring agent.Agent // Thread-safe (has internal locking)
3232 caClient * caclient.Client
33+ log * slog.Logger // Immutable after New()
3334
3435 agentSocketPath string // Immutable after New()
3536 agentListener net.Listener
@@ -43,7 +44,7 @@ type Agent struct {
4344
4445// New creates a new SSH agent. This does not start listening - call Serve() to begin accepting connections.
4546// If agentSocketPath is empty, a temporary socket will be created when Serve() is called.
46- func New (caClient * caclient.Client , agentSocketPath string ) (* Agent , error ) {
47+ func New (logger * slog. Logger , caClient * caclient.Client , agentSocketPath string ) (* Agent , error ) {
4748 pub , priv , err := sshcert .GenerateKeys ()
4849 if err != nil {
4950 return nil , err
@@ -53,6 +54,7 @@ func New(caClient *caclient.Client, agentSocketPath string) (*Agent, error) {
5354 agentSocketPath : agentSocketPath ,
5455 keyring : agent .NewKeyring (),
5556 caClient : caClient ,
57+ log : logger ,
5658 publicKey : pub ,
5759 privateKey : priv ,
5860 done : make (chan struct {}),
@@ -88,7 +90,7 @@ func (a *Agent) UseCredential(c Credential) error {
8890 return errAgentStopped
8991 }
9092
91- log .Debug ("replacing credentials" )
93+ a . log .Debug ("replacing credentials" )
9294 oldKeys , err := a .keyring .List ()
9395 if err != nil {
9496 a .Close ()
@@ -174,7 +176,7 @@ func (a *Agent) serve(ctx context.Context) {
174176 case <- ctx .Done ():
175177 return
176178 default :
177- log .Warnf ("error on accept from SSH_AUTH_SOCK listener: %v " , err )
179+ a . log .Warn ("error on accept from SSH_AUTH_SOCK listener" , "error " , err )
178180 continue
179181 }
180182 }
@@ -185,10 +187,10 @@ func (a *Agent) serve(ctx context.Context) {
185187func (a * Agent ) serveAgent (conn net.Conn ) {
186188 defer conn .Close ()
187189
188- log .Debug ("new connection to agent" )
190+ a . log .Debug ("new connection to agent" )
189191 err := agent .ServeAgent (a .keyring , conn )
190192 if err != nil && err != io .EOF {
191- log .Warnf ("error from ssh-agent: %v " , err )
193+ a . log .Warn ("error from ssh-agent" , "error " , err )
192194 }
193195}
194196
0 commit comments