From 45be0b3ef093944ce1d1fe180179dff2a88fdaa3 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 10 Jan 2025 10:51:19 -0500 Subject: [PATCH] Change node ID to use a hash of the hostname --- pkg/middleware/nodeid/nodeid.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/middleware/nodeid/nodeid.go b/pkg/middleware/nodeid/nodeid.go index 2c8cea66f9..cea4a51521 100644 --- a/pkg/middleware/nodeid/nodeid.go +++ b/pkg/middleware/nodeid/nodeid.go @@ -2,8 +2,10 @@ package nodeid import ( "context" + "fmt" "os" + "github.com/cespare/xxhash/v2" middleware "github.com/grpc-ecosystem/go-grpc-middleware/v2" "google.golang.org/grpc" ) @@ -40,7 +42,14 @@ func FromContext(ctx context.Context) (string, error) { if err != nil { return "", err } - defaultNodeID = spiceDBPrefix + hostname + + // Hash the hostname to get the final default node ID. + hasher := xxhash.New() + if _, err := hasher.WriteString(hostname); err != nil { + return "", fmt.Errorf("failed to hash hostname: %w", err) + } + + defaultNodeID = spiceDBPrefix + fmt.Sprintf("%x", hasher.Sum(nil)) } if err := setInContext(ctx, defaultNodeID); err != nil {