Skip to content

fix: add the 401 hint only when the server's message leaves the cause open - #159

Open
tas50 wants to merge 1 commit into
mainfrom
fix/401-hint-cause
Open

tas50 wants to merge 1 commit into
mainfrom
fix/401-hint-cause

Conversation

@tas50

@tas50 tas50 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

ErrorResponse.Error() appended " (check the client key and that the local clock is in sync)" to every 401. The server's message usually names the cause already, and the hint could contradict it.

Change

Error() now picks the hint from ServerMessage() (unauthorizedHint in errors.go):

Server message Source Hint
Failed to authenticate as 'x'. Ensure that your node_name and client key are correct. erchef unknown actor; cinc-server-ng every actor failure none
Invalid signature for user or client 'x' erchef bad key (check that the client key is the one the server has for this client)
Failed to authenticate as x. Synchronize the clock on your host. erchef clock skew none
Original request time stamp too far in the future or past. / invalid X-Ops-Timestamp cinc-server-ng clock / timestamp none
missing required authentication header(s) ..., bad header(s) ..., auth: missing X-Ops-... header both, bad signing headers none
Failed to authenticate: Username and password incorrect both, password login none
anything else, or no message (a proxy's 401, say) the general hint, unchanged

A message names its cause when it mentions "client key", "clock", "time stamp"/"timestamp", "header" or "password". A bad signature leaves only the key: both servers check the clock before the signature.

Why this design

  • Matching on what the message names, not on exact server strings, holds up when the wording changes. cinc-server-ng#322 answers every failed authentication with the unknown-actor message, which mentions "client key", so it gets no hint there.
  • Unrecognized 401s keep the old hint, so callers that print Error() as-is lose no guidance where the server gave none.
  • Messages, ServerMessage() and errors.Is(err, ErrUnauthorized) are unchanged.

Wording checked against erchef (oc_chef_wm_base:verify_request_message, chef_wm_malformed:malformed_request_message) and cinc-server-ng server/auth.go, internal/auth.

Test plan

  • TestErrorResponse_401HintMatchesCause covers each row above (failed before the fix)
  • go test -race -count=2 ./... in the root and integration/
  • golangci-lint run ./... (v2.15.0) clean in both modules

Fixes #156

… open

Error() appended "check the client key and that the local clock is in
sync" to every 401, even when the server's message already named a
different cause. Drop it when the message names one (unknown actor,
clock skew, signing headers, password login), name the key alone for
"Invalid signature for user or client" (the clock is checked first), and
keep the general hint for any other message or none.

Fixes #156

Signed-off-by: Tim Smith <tsmith84@proton.me>
@tas50
tas50 requested review from damacus and ramereth December 1, 2026 01:27
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.

ErrorResponse.Error() appends a 401 hint that is often wrong

1 participant