Skip to content

Read API key from K8s secret on every RPC call#301

Merged
carlydf merged 2 commits intomainfrom
dynamic-api-key-credentials
Apr 25, 2026
Merged

Read API key from K8s secret on every RPC call#301
carlydf merged 2 commits intomainfrom
dynamic-api-key-credentials

Conversation

@carlydf
Copy link
Copy Markdown
Collaborator

@carlydf carlydf commented Apr 25, 2026

Summary

Follow-up to #300. Solves #295 more gracefully.

  • Replaces the static secret.Data capture in the NewAPIKeyDynamicCredentials closure with a live K8s secret read via a new fetchAPIKeyFromSecret helper
  • A rotated API key now takes effect on the next outgoing Temporal RPC — no permission-denied cycle needed to evict and re-dial the cached client
  • The k8s client is controller-runtime's cache-backed client, so reads hit the local informer cache (cheap in-memory lookup, not a raw API server call)
  • fetchAPIKeyFromSecret is extracted as a testable method; new test verifies the live-read and rotation behavior directly

Test plan

  • go test ./internal/controller/clientpool/... — new TestFetchAPIKey_CredentialClosureReadsLiveSecret passes (verifies initial read and post-rotation read return correct values)
  • go test ./internal/controller/... — existing tests still pass
  • go build ./... — compiles clean

🤖 Generated with Claude Code

Replaces the static capture of secret.Data in the dynamic credentials
closure with a live K8s secret read via fetchAPIKeyFromSecret. This lets a
rotated API key take effect on the next outgoing RPC without requiring a
permission-denied cycle to evict the cached client first.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@carlydf carlydf requested review from a team and jlegrone as code owners April 25, 2026 00:21
@carlydf carlydf merged commit 9e35aad into main Apr 25, 2026
17 checks passed
@carlydf carlydf deleted the dynamic-api-key-credentials branch April 25, 2026 00:55
shashwatsuri pushed a commit to shashwatsuri/temporal-worker-controller that referenced this pull request Apr 28, 2026
## Summary

Follow-up to temporalio#300. Solves temporalio#295 more gracefully.

- Replaces the static `secret.Data` capture in the
`NewAPIKeyDynamicCredentials` closure with a live K8s secret read via a
new `fetchAPIKeyFromSecret` helper
- A rotated API key now takes effect on the next outgoing Temporal RPC —
no permission-denied cycle needed to evict and re-dial the cached client
- The k8s client is controller-runtime's cache-backed client, so reads
hit the local informer cache (cheap in-memory lookup, not a raw API
server call)
- `fetchAPIKeyFromSecret` is extracted as a testable method; new test
verifies the live-read and rotation behavior directly

## Test plan

- [ ] `go test ./internal/controller/clientpool/...` — new
`TestFetchAPIKey_CredentialClosureReadsLiveSecret` passes (verifies
initial read and post-rotation read return correct values)
- [ ] `go test ./internal/controller/...` — existing tests still pass
- [ ] `go build ./...` — compiles clean

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants