Skip to content

fix(agent): an enrollment that cannot reach the gateway says why, not that verification failed - #500

Merged
samuelmbabhazi merged 2 commits into
mainfrom
fix/agent-gateway-handshake-cause
Nov 25, 2026
Merged

samuelmbabhazi merged 2 commits into
mainfrom
fix/agent-gateway-handshake-cause

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

When enrollment's TLS probe of the gateway fails, the agent's error now wraps the cause (gateway TLS handshake: …) instead of always saying gateway TLS verification failed.

Why

Found while installing the published v0.1.0-alpha.5 on a single machine for #480. The installer restarts Docker for the egress proxy, and the agent started one second before the control plane's gateway listened. docker-proxy accepted the connection on 127.0.0.1:7443, then closed it. The agent logged gateway TLS verification failed and exited. systemd started it again 5 seconds later, and it enrolled.

The outcome was fine. The message was not: it reported a trust failure where the gateway was simply not up yet, and an operator would look in the wrong place. A real verification failure still says what failed, because its error comes from VerifyConnection ("installation CA fingerprint mismatch", "invalid gateway certificate").

How it was tested

TestEnrollmentErrorsKeepTheirCause:

  • A listener that accepts and closes, like docker-proxy with no backend. The error must say EOF and must not say "verification".
  • A gateway with the wrong pinned fingerprint. The error must say installation CA fingerprint mismatch.

The first case failed on the old code, with gateway TLS verification failed. The gateway package tests pass, and golangci-lint run ./agent/... reports 0 issues.

Security considerations

The probe sends no application data, and the join token is sent only after the probe succeeds (TestUntrustedGatewayNeverReceivesToken is unchanged). The wrapped error holds a network error or one of the verifier's own messages, never the token.

… that verification failed

Every dial error of the trust probe became "gateway TLS verification failed", including a gateway that was not listening yet: on a single machine the installer restarts Docker, the agent starts first, and docker-proxy accepts then closes the connection. The error now wraps its cause; a real verification failure keeps its own message from VerifyConnection.

Signed-off-by: samuel mbabhazi <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 12 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b36a033 and dd4594a.

Files selected for processing: 2

  • agent/internal/gateway/client.go
  • agent/internal/gateway/client_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@samuelmbabhazi
samuelmbabhazi merged commit 5f49fb3 into main Nov 25, 2026
27 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the fix/agent-gateway-handshake-cause branch November 25, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant