Skip to content

Fix/credential reset on 401#17

Open
etgraylog wants to merge 10 commits into
mainfrom
fix/credential-reset-on-401
Open

Fix/credential reset on 401#17
etgraylog wants to merge 10 commits into
mainfrom
fix/credential-reset-on-401

Conversation

@etgraylog

Copy link
Copy Markdown

Notes for Reviewers

This PR supercedes PR Graylog2/collector-sidecar#545 to resolve issue #14 .

Summary

  • Adds auth.reset_on_auth_rejection config flag (default false) to AuthConfig
  • When enabled, a new handleAuthRejection method called from OnConnectFailed detects 401 on an already-enrolled supervisor and clears all persisted state before exiting with code 1, allowing the service manager to trigger a fresh enrollment
  • State cleared on exit: signing key + cert + encryption key (persistence.ClearCredentials), instance UID (persistence.ClearInstanceUID), own-logs settings (ownLogsPersistence.Delete)
  • When the flag is false (the default), behavior is identical to stock — 401 is logged and polling continues
  • auth.Manager.ClearCredentials() added as a thin wrapper that removes the key/cert files and drops the in-memory cached credentials so IsEnrolled() returns false immediately

Test plan

  • go test ./superv/supervisor/ -run TestHandleAuthRejection passes (6 gate scenarios + persistent-state cleanup test)

  • Deploy with reset_on_auth_rejection: true, delete the server-side collector record via the Graylog API, confirm the supervisor exits on the next 401 and re-enrolls with a fresh UID on restart

  • Deploy with reset_on_auth_rejection: false (default), confirm 401 is logged and the process keeps running without exiting

  • The commit history must be preserved - please use the rebase-merge or standard merge option instead of squash-merge

  • Sync up with the author before merging

etgraylog added 10 commits June 30, 2026 00:55
Removes the signing key, signing certificate, and encryption key files
from the keys directory. Missing files are silently skipped so the
function is safe to call even when only some credentials exist.
Removes the instance UID file from the persistence directory.
Missing file is silently skipped so the call is safe even when
the instance has never been persisted.
Opt-in flag that, when true, causes the supervisor to clear all
persisted credentials and exit on a 401 rejection so the service
manager can trigger fresh enrollment. Defaults to false so existing
deployments are unaffected.
Delegates to persistence.ClearCredentials to remove key and cert files
from disk, then clears the in-memory signing key and certificate so
IsEnrolled returns false immediately after the call.
exitFn defaults to os.Exit and is overridable in tests. handleAuthRejection
detects 401 errors from OnConnectFailed and, when the supervisor is already
enrolled and reset_on_auth_rejection is enabled, clears all persisted
credentials (keys, cert, instance UID, own_logs) before calling exitFn(1)
so the service manager can trigger fresh enrollment.
Calls handleAuthRejection after logging each connect failure so that
sustained 401 responses from an enrolled supervisor trigger the
credential-reset-and-exit path when reset_on_auth_rejection is set.
TestHandleAuthRejection_GatedByConfig covers six gate scenarios:
enabled/disabled flag × enrolled/not × 401/non-401 error and nil.
TestHandleAuthRejection_ClearsPersistentState verifies that when all
gates pass, signing.key, signing.crt, and identity.yaml are removed
from disk and exitFn is called with code 1.
@etgraylog
etgraylog force-pushed the fix/credential-reset-on-401 branch from 82d9506 to 030cf6e Compare June 30, 2026 04:55
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.

1 participant