mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
fix(multiplayer): bound workload credential lifetime
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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()}
|
||||
|
||||
@@ -30,6 +30,7 @@ func main() {
|
||||
transport := flag.String("transport", envOrDefault("COSMIC_CLASH_TRANSPORT", "enet"), "game transport: enet or steam_sdr")
|
||||
interval := flag.Duration("interval", time.Second, "allocation poll interval")
|
||||
workloadSecret := flag.String("workload-secret", os.Getenv("COSMIC_CLASH_WORKLOAD_SECRET"), "HMAC secret for control-plane-issued workload tokens (see workload/signed_token.go); must match cmd/control-plane's own --workload-secret. Unset skips minting a cosmic-clash.io/workload-token annotation entirely")
|
||||
workloadTokenTTL := flag.Duration("workload-token-ttl", agones.DefaultWorkloadTokenTTL, "lifetime for allocated workload tokens; must cover bounded match play and result retry")
|
||||
allocationQuota := flag.Int("allocation-quota", 0, "optional per-replica allocation attempts per region per quota window; zero disables this local guard")
|
||||
allocationQuotaWindow := flag.Duration("allocation-quota-window", time.Minute, "window for --allocation-quota")
|
||||
metricsAddr := flag.String("metrics-addr", envOrDefault("COSMIC_CLASH_ALLOCATOR_METRICS_ADDR", ":9091"), "allocator Prometheus metrics address; empty disables metrics")
|
||||
@@ -43,8 +44,8 @@ func main() {
|
||||
if *readinessMaxStale < *interval+*providerTimeout {
|
||||
fatalf("--readiness-max-stale must be at least --interval plus --provider-timeout")
|
||||
}
|
||||
if *allocationQuota < 0 || *allocationQuotaWindow <= 0 {
|
||||
fatalf("--allocation-quota must be non-negative and --allocation-quota-window must be positive")
|
||||
if *allocationQuota < 0 || *allocationQuotaWindow <= 0 || *workloadTokenTTL <= 0 {
|
||||
fatalf("--allocation-quota must be non-negative and --allocation-quota-window/--workload-token-ttl must be positive")
|
||||
}
|
||||
db, err := sql.Open("pgx", *dsn)
|
||||
if err != nil {
|
||||
@@ -77,7 +78,7 @@ func main() {
|
||||
if err != nil {
|
||||
fatalf("configure Kubernetes API client: %v", err)
|
||||
}
|
||||
client := agones.Client{BaseURL: *agonesURL, Namespace: *namespace, HTTP: providerHTTP, WorkloadSecret: []byte(*workloadSecret)}
|
||||
client := agones.Client{BaseURL: *agonesURL, Namespace: *namespace, HTTP: providerHTTP, WorkloadSecret: []byte(*workloadSecret), WorkloadTokenTTL: *workloadTokenTTL}
|
||||
worker := allocator.Worker{
|
||||
Claims: store.AllocatingMatchClaims{DB: db, Transport: *transport},
|
||||
Service: allocator.Service{
|
||||
|
||||
Reference in New Issue
Block a user