Repository navigation
Only send polling requests to clients presenting the expected certificate - #738
Conversation
…cate A polling client is authorized by its certificate, but chooses which subscription it polls. Before sending a queued request to a polling client, check that the certificate it presented matches the thumbprint the request's destination expects. On a mismatch the request is not sent, it fails with PollingClientCertificateMismatchHalibutClientException, the mismatch is logged as ErrorInIdentify against the subscription's endpoint log, and the connection is closed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The polling service (pollingServer) presents the TentacleListening certificate, but the polling endpoints expected TentaclePolling, which is the listening runtime's own certificate. Requests are now only sent to a polling client presenting the certificate its endpoint expects, so the endpoints must expect TentacleListening. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| { | ||
| expectedTcpClientCount++; // each time the server polls, it keeps a tcpclient (as we dont have support to say StopPolling) | ||
| RunPollingClient(pollingServer, Certificates.TentaclePolling, Certificates.TentaclePollingPublicThumbprint).GetAwaiter().GetResult(); | ||
| RunPollingClient(pollingServer, Certificates.TentaclePolling, Certificates.TentacleListeningPublicThumbprint).GetAwaiter().GetResult(); |
There was a problem hiding this comment.
Oh so this only passed because of the bug
| { | ||
| // Fail closed: a destination that does not say which certificate it expects is never sent to a polling client. | ||
| return !string.IsNullOrWhiteSpace(destination.RemoteThumbprint) | ||
| && string.Equals(destination.RemoteThumbprint, Thumbprint, StringComparison.OrdinalIgnoreCase); |
There was a problem hiding this comment.
Are thumbprints case insensitive?
There was a problem hiding this comment.
Thumbprints are hex, so AB12 and ab12 mean the same thing. X509Certificate2.Thumbprint always returns uppercase, so the client side of this check is always uppercase. The other side, Destination.RemoteThumbprint, is whatever the caller passed in.
We ignored case to match DefaultTrustProvider, which already ignores case (StringComparer.OrdinalIgnoreCase).
|
|
||
| public bool IsExpectedBy(ServiceEndPoint destination) | ||
| { | ||
| // Fail closed: a destination that does not say which certificate it expects is never sent to a polling client. |
There was a problem hiding this comment.
When does this happen?
There was a problem hiding this comment.
It shouldn't happen in practice. Octopus always sets the thumbprint on polling endpoints. But ServiceEndPoint.remoteThumbprint is string?, so the API lets a caller build a poll:// endpoint without one. In that case we'd have nothing to compare the client's certificate to. Sending the request anyway would bring back the original hole, so we reject it. The only null thumbprints in the repo are on discovery and queue endpoints, which never reach this code.
| } | ||
|
|
||
| [Test] | ||
| public async Task PollingClientPresentingTheExpectedCertificateReceivesRequests() |
There was a problem hiding this comment.
Don't we have plenty of tests testing this?
There was a problem hiding this comment.
True. Deleted!
|
I think it would make sense to have another PR to reject connections from polling tentacles that are attempting to collect work for a subscription id that doesn't match their cert. It would change the interface to Octopus, but it does mean we don't allow wrongly configured Tentacles in from the start. |
Background
A polling client is authorized by its certificate, but it chooses which subscription it polls. Halibut never checked that the two belong together. Any trusted certificate could poll any subscription.
Results
Before sending a queued request to a polling client, Halibut now checks that the client's TLS certificate matches the request's
Destination.RemoteThumbprint. The comparison ignores case.If they don't match, or the destination has no thumbprint:
PollingClientCertificateMismatchHalibutClientException, which counts as not retryable. The message names the subscription and both thumbprints.ErrorInIdentifytoLogs.ForEndpoint(subscriptionId). In Octopus, that puts it in the target's Communications log and in the server log, with no Octopus change.How to review this PR
Key logic:
MessageExchangeProtocol.ProcessReceiverInternalAsync/AuthenticatedSubscriber. Both listeners now pass the authenticated thumbprint through.Worth knowing:
ServiceEndPoints must carry the correct thumbprint, and null is rejected. Octopus Server always sets it.ServerExchangeActionAsyncdelegate for the listener constructors, andExchangeAsServerAsyncgains two parameters. Octopus Server doesn't use either directly.ManyPollingTentacleTests,HalibutExamplesFixture). The third (BadCertificatesTests) now expects the service's real thumbprint, so it still coversOnUnauthorizedClientConnect.Testing: new unit tests in
ProtocolFixtureand end-to-end tests inPollingSubscriptionCertificateFixture. The net10.0 suite passed locally, apart from two macOS-only environment tests. net48 hasn't been run locally.🤖 Generated with Claude Code