fix(ai/live): add -liveAIHeartbeatHeadersFile for dynamic token rotation without pod restart#3887
Closed
livepeer-tessa wants to merge 1 commit into
Closed
fix(ai/live): add -liveAIHeartbeatHeadersFile for dynamic token rotation without pod restart#3887livepeer-tessa wants to merge 1 commit into
livepeer-tessa wants to merge 1 commit into
Conversation
The AI gateway heartbeat was using a static set of headers set at startup via -liveAIHeartbeatHeaders. When the daydream-api access token is rotated or expires, the heartbeat begins returning 401 Unauthorized errors (tracked in daydreamlive/scope#710). Add a new -liveAIHeartbeatHeadersFile flag that specifies a path to a file containing key:value headers (one per line, # comments supported). The file is re-read on every heartbeat call, so a Kubernetes secret volume mount will automatically supply a fresh token whenever the secret is rotated — without requiring a pod restart. File headers take precedence over static -liveAIHeartbeatHeaders when keys conflict. The existing flag is unchanged for backward compatibility. Example usage: -liveAIHeartbeatHeadersFile /run/secrets/heartbeat-headers Where the file contains: Authorization: Bearer <token> Signed-off-by: livepeer-tessa <livepeer-tessa@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3887 +/- ##
===================================================
- Coverage 32.88638% 32.87235% -0.01403%
===================================================
Files 171 171
Lines 42063 42084 +21
===================================================
+ Hits 13833 13834 +1
- Misses 27189 27207 +18
- Partials 1041 1043 +2
... and 3 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The AI gateway's heartbeat to
daydream-apiuses headers (including theAuthorizationbearer token) configured once at startup via-liveAIHeartbeatHeaders. When the daydream-api access token is rotated or expires, the heartbeat begins returning401 Unauthorizederrors indefinitely until the pod is restarted with a new token.This was confirmed in staging (
staging-livepeer-ai-gateway-7280) where recurringInvalid access tokenerrors were traced back to the heartbeat call inai_mediaserver.go:1452:Tracked in: daydreamlive/scope#710
Solution
Add a new
-liveAIHeartbeatHeadersFileflag that points to a file containingkey:valueheaders (one per line). The file is re-read on every heartbeat call, enabling automatic token rotation when the file is backed by a Kubernetes secret volume mount (which updates in-place when the secret is rotated).File headers override static
-liveAIHeartbeatHeaderswhen keys conflict. The existing flag is unchanged.File format
Kubernetes usage
When the K8s secret is rotated via ExternalSecrets (or manually), the mounted file updates automatically and the next heartbeat will use the fresh token — no pod restart needed.
Changes
core/livepeernode.go: addLiveAIHeartbeatHeadersFilefieldcmd/livepeer/starter/flags.go: add-liveAIHeartbeatHeadersFileflagcmd/livepeer/starter/starter.go: wire config field to nodeserver/ai_mediaserver.go: addloadHeartbeatHeaders()helper that merges static + file headers (re-read each call);sendHeartbeatuses it