fix(multiplayer): bound workload credential lifetime

This commit is contained in:
Josh Creek
2026-09-03 21:27:26 +01:00
parent 8507472635
commit ea1c65acfb
12 changed files with 46 additions and 11 deletions
+3 -2
View File
@@ -38,11 +38,12 @@ type Client struct {
// WorkloadTokenTTL bounds how long the minted token remains valid; it
// must comfortably exceed the time between allocation and this
// GameServer completing process-ready/assignment-ready registration.
// Zero defaults to 30 minutes.
// Zero defaults to DefaultWorkloadTokenTTL (two hours).
WorkloadTokenTTL time.Duration
}
const DefaultHTTPTimeout = 10 * time.Second
const DefaultWorkloadTokenTTL = 2 * time.Hour
type AllocatedServer struct {
Allocation domain.Allocation
@@ -250,7 +251,7 @@ func (c Client) Allocate(ctx context.Context, request domain.AllocationRequest,
if len(c.WorkloadSecret) > 0 {
ttl := c.WorkloadTokenTTL
if ttl <= 0 {
ttl = 30 * time.Minute
ttl = DefaultWorkloadTokenTTL
}
token, err := workload.IssueSignedWorkloadToken(c.WorkloadSecret, request.AllocationID, now, ttl)
if err != nil {
+6
View File
@@ -114,6 +114,12 @@ func TestAllocateRequestsAWorkloadTokenAnnotationWhenConfigured(t *testing.T) {
if claims.AllocationID != "allocation-1" {
t.Fatalf("token names allocation %q, want %q", claims.AllocationID, "allocation-1")
}
if _, err := workload.ParseSignedWorkloadToken(secret, token, now.Add(DefaultWorkloadTokenTTL-time.Second)); err != nil {
t.Fatalf("default token expired before its documented lifetime: %v", err)
}
if _, err := workload.ParseSignedWorkloadToken(secret, token, now.Add(DefaultWorkloadTokenTTL)); err == nil {
t.Fatal("default token remained valid at its exact expiry boundary")
}
gotAnnotations = nil
unsigned := Client{BaseURL: server.URL, Namespace: "games", HTTP: server.Client()}