Skip to content

Only send polling requests to clients presenting the expected certificate - #738

Merged
sburmanoctopus merged 4 commits into
mainfrom
levi/validate-polling-subscription-thumbprint
Nov 16, 2026
Merged

sburmanoctopus merged 4 commits into
mainfrom
levi/validate-polling-subscription-thumbprint

Conversation

@sburmanoctopus

Copy link
Copy Markdown
Contributor

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:

  • The request is not sent. It fails with a new PollingClientCertificateMismatchHalibutClientException, which counts as not retryable. The message names the subscription and both thumbprints.
  • The mismatch is logged as ErrorInIdentify to Logs.ForEndpoint(subscriptionId). In Octopus, that puts it in the target's Communications log and in the server log, with no Octopus change.
  • The connection is closed.

How to review this PR

Key logic: MessageExchangeProtocol.ProcessReceiverInternalAsync / AuthenticatedSubscriber. Both listeners now pass the authenticated thumbprint through.

Worth knowing:

  • Behaviour change. Polling ServiceEndPoints must carry the correct thumbprint, and null is rejected. Octopus Server always sets it.
  • Public API change. There's a new ServerExchangeActionAsync delegate for the listener constructors, and ExchangeAsServerAsync gains two parameters. Octopus Server doesn't use either directly.
  • A rejected request fails. The request is already off the queue when the check runs, so it can't be put back.
  • Existing tests updated. Three tests only passed because nothing was checked. Two had the wrong expected thumbprint (ManyPollingTentacleTests, HalibutExamplesFixture). The third (BadCertificatesTests) now expects the service's real thumbprint, so it still covers OnUnauthorizedClientConnect.

Testing: new unit tests in ProtocolFixture and end-to-end tests in PollingSubscriptionCertificateFixture. The net10.0 suite passed locally, apart from two macOS-only environment tests. net48 hasn't been run locally.

🤖 Generated with Claude Code

…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>
@sburmanoctopus
sburmanoctopus requested a review from a team as a code owner November 16, 2026 04:36
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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are thumbprints case insensitive?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does this happen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have plenty of tests testing this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Deleted!

@LukeButters LukeButters left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LukeButters

Copy link
Copy Markdown
Contributor

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.

@sburmanoctopus
sburmanoctopus enabled auto-merge (squash) November 16, 2026 21:43
@sburmanoctopus
sburmanoctopus merged commit 180e030 into main Nov 16, 2026
13 checks passed
@sburmanoctopus
sburmanoctopus deleted the levi/validate-polling-subscription-thumbprint branch November 16, 2026 22:11
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.

2 participants