Skip to content

Conversation

@jajeffries
Copy link
Contributor

@jajeffries jajeffries commented Nov 14, 2025

This pull request introduces a robust mechanism for proactively monitoring and refreshing JWT tokens used for Fleet MQTT connections. The changes add new configuration options, enhance token management, and implement background monitoring to ensure connections are refreshed before token expiry, reducing downtime and improving reliability.

Token expiry monitoring and proactive reconnection:

  • Added a background goroutine in fleetConfigManager to periodically check JWT token expiry and trigger reconnection before the token expires, using new configuration options for check interval and buffer (monitorTokenExpiry, TokenExpiryCheckInterval, TokenReconnectBuffer). [1] [2]
  • Implemented a channel-based mechanism (reconnectChan) and supporting logic to handle reconnection requests triggered by token expiry or imminent expiry. [1] [2]

Enhanced token management:

  • Extended AuthTokenManager to store credentials, refresh tokens using stored values, and accurately track token expiry using the JWT exp claim with a safety buffer. Added methods for refreshing tokens, checking expiry, and extracting expiry time from JWTs. [1] [2] [3]

Configuration and state improvements:

  • Updated fleetConfigManager to persist connection state, configuration, and backend information for use during reconnection events.

Logging and diagnostics:

  • Improved logging throughout the token request, refresh, and expiry monitoring processes to aid diagnostics and troubleshooting. [1] [2]

These changes collectively improve the agent's resilience to token expiry, reduce manual intervention, and provide better observability into token lifecycle events.

@github-actions
Copy link

github-actions bot commented Nov 14, 2025

Go test coverage

STATUS ELAPSED PACKAGE COVER PASS FAIL SKIP
🟢 PASS 1.03s github.com/netboxlabs/orb-agent/agent 8.2% 1 0 0
🟢 PASS 1.10s github.com/netboxlabs/orb-agent/agent/backend 33.3% 30 0 0
🟢 PASS 4.02s github.com/netboxlabs/orb-agent/agent/backend/devicediscovery 67.1% 2 0 0
🟢 PASS 0.11s github.com/netboxlabs/orb-agent/agent/backend/mocks 0.0% 0 0 0
🟢 PASS 4.02s github.com/netboxlabs/orb-agent/agent/backend/networkdiscovery 59.0% 2 0 0
🟢 PASS 4.02s github.com/netboxlabs/orb-agent/agent/backend/opentelemetryinfinity 46.3% 2 0 0
🟢 PASS 4.03s github.com/netboxlabs/orb-agent/agent/backend/pktvisor 67.0% 2 0 0
🟢 PASS 4.03s github.com/netboxlabs/orb-agent/agent/backend/snmpdiscovery 58.5% 2 0 0
🟢 PASS 5.03s github.com/netboxlabs/orb-agent/agent/backend/worker 68.1% 3 0 0
🟢 PASS 1.01s github.com/netboxlabs/orb-agent/agent/config 100.0% 6 0 0
🟢 PASS 31.41s github.com/netboxlabs/orb-agent/agent/configmgr 47.8% 26 0 0
🟢 PASS 7.61s github.com/netboxlabs/orb-agent/agent/configmgr/fleet 66.0% 136 0 0
🟢 PASS 1.01s github.com/netboxlabs/orb-agent/agent/otlpbridge 30.7% 5 0 0
🟢 PASS 1.01s github.com/netboxlabs/orb-agent/agent/policies 100.0% 15 0 0
🟢 PASS 1.02s github.com/netboxlabs/orb-agent/agent/policymgr 71.6% 11 0 0
🟢 PASS 25.66s github.com/netboxlabs/orb-agent/agent/secretsmgr 48.9% 54 0 0
🟢 PASS 1.02s github.com/netboxlabs/orb-agent/agent/telemetry 81.7% 19 0 0
🟢 PASS 1.01s github.com/netboxlabs/orb-agent/agent/version 100.0% 1 0 0

Total coverage: 55.7%

@jajeffries jajeffries marked this pull request as ready for review November 18, 2025 12:17
@jajeffries jajeffries merged commit 5fcf0d3 into develop Nov 18, 2025
5 checks passed
@jajeffries jajeffries deleted the feat/OBS-1653-reconnect-and-reauth branch November 18, 2025 15:52
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