Skip to content

Commit 97ee2ea

Browse files
committed
Improve logging and error handling
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 497277a commit 97ee2ea

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.23 as build
1+
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.25 as build
22

33
ARG TARGETPLATFORM
44
ARG BUILDPLATFORM

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module slicer-ssh-agent
22

3-
go 1.23.4
3+
go 1.25
44

55
require (
66
github.com/creack/pty v1.1.24

main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Copyright (c) 2025 Alex Ellis, OpenFaaS Ltd
3232
`, Version)
3333

3434
port := uint32(514)
35+
3536
l, err := vsock.Listen(port, nil)
3637
if err != nil {
3738
log.Fatal(err)
@@ -41,10 +42,11 @@ Copyright (c) 2025 Alex Ellis, OpenFaaS Ltd
4142
for {
4243
conn, err := l.Accept()
4344
if err != nil {
44-
log.Fatal(err)
45+
log.Printf("Error accepting connection: %v", err)
46+
continue
4547
}
4648

47-
fmt.Printf("Connection accepted from socket\n")
49+
fmt.Printf("Connection from socket. CID: %d\n", conn.RemoteAddr().(*vsock.Addr).ContextID)
4850

4951
go handleConnection(conn)
5052
}
@@ -53,6 +55,11 @@ Copyright (c) 2025 Alex Ellis, OpenFaaS Ltd
5355
func handleConnection(conn net.Conn) {
5456
defer conn.Close()
5557

58+
if conn.RemoteAddr().(*vsock.Addr).ContextID != vsock.Host {
59+
log.Printf("Closing connection from CID: %d, not allowed.", conn.RemoteAddr().(*vsock.Addr).ContextID)
60+
return
61+
}
62+
5663
var err error
5764
// Try multiple shells in order of preference
5865
shells := []string{"/bin/bash", "/bin/sh", "/usr/bin/sh"}

0 commit comments

Comments
 (0)