Repository navigation
feat(socket): admin socket settings (switch, mode, token TTL, origins) with signed config for the socket server - #314
Merged
Conversation
… server System administrators can now manage the socket server from the console instead of only through the environment: - system.socket.enabled / mode / token_ttl / origins / publisher_origin settings; a missing or cleared one falls back to the environment (SOCKETCLUSTER_AUTH_ENABLED, _AUTH_MODE, _TOKEN_TTL, _OPTIONS.origins, _ORIGIN), which is the behaviour before this change. - SocketSettings resolves the effective values and their sources; the stored values are cached for 60 seconds and the cache is cleared on save. An unreachable settings table reads as nothing stored. - SocketToken::enabled(), the default token TTL and the websocket publisher's Origin header follow the effective settings. - GET/POST int/v1/settings/socket (AdminRequest): effective settings plus the socket server's signed /stats (2 s timeout, short reason on failure). Switching on without SOCKETCLUSTER_AUTH_KEY is refused with 422 key_missing; saves are recorded in the activity log. - GET int/v1/socket/config, signed with the authorize key and answered while the switch is off, so the socket server can apply the switch, mode and origins at runtime. The auth key stays environment-only and is never stored or returned; only key_configured is reported.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release/v1.6.71 #314 +/- ##
====================================================
Coverage 100.00% 100.00%
- Complexity 8885 8931 +46
====================================================
Files 472 473 +1
Lines 27934 28065 +131
====================================================
+ Hits 27934 28065 +131
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 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.
What
System administrators can manage the socket server from the console (Configure → Socket) instead of only through environment variables.
Settings (one
settingsrow each; missing ornull= fall back to the environment, which is today's behaviour):system.socket.enabledSOCKETCLUSTER_AUTH_ENABLEDsystem.socket.modeoff|log|enforceSOCKETCLUSTER_AUTH_MODE(null = the socket server's own default)system.socket.token_ttlSOCKETCLUSTER_TOKEN_TTLsystem.socket.originsoriginsstringSOCKETCLUSTER_OPTIONS.originssystem.socket.publisher_originSOCKETCLUSTER_ORIGINsystem.socket.updated_atis written on every save and served asupdated_atby the config endpoint.Resolver:
Fleetbase\Support\SocketCluster\SocketSettings::effective()returns{enabled, mode, token_ttl, origins, publisher_origin, key_configured, sources: {field: 'setting'|'env'}}. Stored values are cached for 60 s undersocket_settings:stored, and the cache is cleared on save. If the settings table can't be reached (e.g. during install) it falls back to the environment without an error.SocketToken::enabled(), the default token TTL and the websocket publisher'sOriginheader now use the effective settings.Endpoints
GET int/v1/settings/socket(system admin,AdminRequest) returns{settings: <effective>, status: <socket /stats or null>, status_error: <string|null>}. Status comes from the socket server'sGET /stats, signed with the publish key, with a 2 s timeout. On failure,statusis null andstatus_errorgives a short reason.POST int/v1/settings/socket(system admin) takes any subset of{enabled, mode, token_ttl, origins, publisher_origin}, wherenullclears a value. The values are validated.enabled: trueis refused with422 {code: "key_missing"}while no valid key is configured. Each save is recorded in the activity log (settings/socket_settings_updated). The response has the same shape as GET.GET int/v1/socket/configis for the socket server only. It is signed with the authorize key (VerifySocketSignature:key-only) and has no session. It returns{enabled, mode, origins, updated_at}and also answers while the API's own switch is off, which is how the server learns the switch was turned on.Why
Before this, changing the switch, mode, TTL or origins meant editing the environment on the API and the socket server and restarting both. Now the socket server polls the config endpoint and applies changes at runtime.
The key stays env-only
SOCKETCLUSTER_AUTH_KEYis never stored, returned or settable through the API. Responses report onlykey_configured: bool, and the tests check that no response contains the key or any derived key.Test plan
Verified by CI (unit suite with the 100% coverage gate, php-cs-fixer, date drift). New tests cover:
enabled: truerefused without a keySocketToken::enabled, TTL and publisher Origin following the effective settingsRelated: #313 (release), console + socket server PR to follow in fleetbase/fleetbase (release/v0.7.70, fleetbase/fleetbase#721)