Skip to content

Commit

Permalink
Change node ID to use a hash of the hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
josephschorr committed Jan 10, 2025
1 parent e658772 commit 45be0b3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/middleware/nodeid/nodeid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 45be0b3

Please sign in to comment.