Skip to content

Add bridge metrics and broker API key rotation#91

Open
ashioyajotham wants to merge 1 commit into
Prescott-Data:mainfrom
ashioyajotham:feat/bridge-metrics-broker-security-44-49
Open

Add bridge metrics and broker API key rotation#91
ashioyajotham wants to merge 1 commit into
Prescott-Data:mainfrom
ashioyajotham:feat/bridge-metrics-broker-security-44-49

Conversation

@ashioyajotham

Copy link
Copy Markdown
Contributor

Description

Adds bridge timing observability and broker API key rotation hardening.

Fixes #44.
Fixes #49.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactor

Changes Made

  • nexus-bridge: add Prometheus histograms for connection duration and token refresh latency, wire observations into WebSocket and gRPC lifecycles, and update custom metrics docs/tests.
  • nexus-broker: add reloadable API key sources backed by API_KEY_FILE / API_KEYS_FILE with API_KEY_RELOAD_INTERVAL, while keeping the existing static middleware API compatible.
  • nexus-broker: verify AES-GCM token vault behavior with tests for round trip, unique ciphertexts/nonces, tamper rejection, and invalid key length.
  • Docs/env examples: document API key file rotation and reload settings.

How to Test

  1. cd nexus-bridge && go test ./... -timeout=90s
  2. cd nexus-broker && go test ./... -timeout=180s

Migration / Breaking Changes

  • Database migration required - include the migration file path
  • No migration required

No schema changes. Existing API_KEY / API_KEYS deployments continue to work; file-backed key loading is additive.

Checklist

  • Code follows the Go styleguide (gofmt applied)
  • Commit messages use present tense, imperative mood, <=72 chars
  • Documentation updated where applicable
  • No secrets or credentials committed

Copilot AI review requested due to automatic review settings July 20, 2026 12:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds timing observability to nexus-bridge and hardens nexus-broker API-key handling by supporting file-backed key rotation with periodic reload, plus accompanying tests and documentation updates.

Changes:

  • nexus-bridge: add Prometheus histograms for connection duration and token refresh latency, and record observations in WebSocket + gRPC lifecycles.
  • nexus-broker: introduce an APIKeySource abstraction with a reloadable implementation backed by API_KEY_FILE / API_KEYS_FILE and API_KEY_RELOAD_INTERVAL.
  • Add/extend tests and docs to cover AES-GCM vault behavior and API key rotation configuration.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
nexus-broker/README.md Documents file-backed API key rotation and reload interval.
nexus-broker/pkg/vault/encrypt_test.go Adds AES-GCM vault tests (round-trip, unique ciphertext, tamper rejection, invalid key length).
nexus-broker/pkg/server/apikey.go Adds APIKeySource + reloadable key source and middleware integration.
nexus-broker/pkg/server/apikey_test.go Adds tests for reload behavior, failure fallback, and missing file startup failure.
nexus-broker/pkg/config/broker.go Adds env parsing for key files + reload interval with defaults and validation.
nexus-broker/pkg/config/broker_test.go Tests API key file parsing and reload interval parsing/validation.
nexus-broker/cmd/nexus-broker/main.go Switches protected routes to use reloadable API key source.
nexus-bridge/telemetry/metrics.go Adds Prometheus histograms + observe methods for timing metrics.
nexus-bridge/telemetry/metrics_test.go Verifies timing histograms are registered and receive samples.
nexus-bridge/README.md Updates Metrics interface docs to include new observe methods.
nexus-bridge/options.go Extends Metrics interface + nop implementation for new methods.
nexus-bridge/bridge.go Observes connection duration (WS + gRPC) and token refresh latency.
nexus-bridge/bridge_test.go Extends mock metrics + assertions for new observations; adjusts cancellation test server.
docs/services/broker.md Documents new broker env vars for API key rotation.
docs/reference/security-model.md Documents runtime API key rotation via secret files.
docs/infrastructure/deploying-nexus.md Adds deployment guidance for API key rotation and reload interval.
docs/getting-started/configuration.md Updates config matrix for API key env options and defaults.
docs/concepts/security-model.md Notes broker API key rotation capability.
docs/concepts/broker.md Updates broker security notes and rotation guidance.
.env.example Adds example env vars for API key rotation via mounted files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +93 to +115
func (s *ReloadingAPIKeySource) reloadIfDue() {
now := s.now()

s.mu.RLock()
reloadDue := now.Sub(s.lastReload) >= s.reloadInterval
s.mu.RUnlock()
if !reloadDue {
return
}

s.mu.Lock()
defer s.mu.Unlock()
if now.Sub(s.lastReload) < s.reloadInterval {
return
}

next, err := s.load()
s.lastReload = now
if err != nil {
return
}
s.keys = next
}
Comment on lines +257 to +259
conn, _ := upgrader.Upgrade(w, r, nil)
defer conn.Close()
<-r.Context().Done()
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.

Enhancement: Enhance Security & Data Protection in nexus-broker Enhancement: Add Connection Duration and Refresh Latency Metrics to nexus-bridge

2 participants