Skip to content

Conversation

@Aaronontheweb
Copy link
Member

Summary

Fixes #7917 - DotNettySslSetup settings were being ignored when HOCON configuration had valid SSL certificate configuration.

Root Cause

The bug occurred in DotNettyTransportSettings.Create() where CreateOrDefault() tried parsing HOCON first and only used the programmatic DotNettySslSetup as an exception fallback. This meant:

  • When HOCON had enable-ssl = true AND valid certificate config → HOCON won, programmatic setup ignored ❌
  • When HOCON had enable-ssl = true BUT no/invalid certificate → Exception thrown, programmatic setup used ✅

This was backwards from the expected behavior where programmatic configuration should take precedence over HOCON defaults.

Changes

  1. Added failing test - DotNettySslSetup_should_override_HOCON_certificate that exposes the bug by configuring both HOCON and programmatic SSL with different certificates
  2. Fixed precedence order - Changed line 206 to check sslSettings (from DotNettySslSetup) first before parsing HOCON
  3. Made Create() internal - Changed visibility from private to internal to enable direct usage

Test Results

  • ✅ New test passes (failed before fix)
  • ✅ All 6 DotNettySslSetupSpec tests pass
  • ✅ All 17 SSL-related tests pass
  • ✅ All 39 DotNetty transport tests pass

Background

The bug existed since DotNettySslSetup was introduced in July 2023 (commit 588d5d6, PR #6854). Existing tests passed only because they triggered the exception-based fallback path (HOCON with enable-ssl=true but no certificate path).

…7917)

Added test case that demonstrates DotNettySslSetup settings being ignored
when HOCON has valid certificate configuration. The test configures:

- HOCON with valid certificate path and settings
- DotNettySslSetup with different certificate and settings

Expected: DotNettySslSetup should take precedence (programmatic over config)
Actual: HOCON certificate is used, DotNettySslSetup is completely ignored

The bug occurs because CreateOrDefault() tries HOCON first and only uses
the programmatic setup as an exception fallback. This test fails and
will pass once the fix is applied to make programmatic setup take precedence.

Existing tests didn't catch this because they only test the exception-based
fallback path (HOCON with enable-ssl=true but no certificate path).
…kkadotnet#7917)

Changed SSL settings initialization to prioritize programmatic DotNettySslSetup
over HOCON configuration, fixing the precedence order bug.

Changes:
- Modified DotNettyTransportSettings.Create() to check sslSettings (from
  DotNettySslSetup) first before parsing HOCON configuration
- Changed SslSettings.Create() from private to internal to enable direct usage
- Previous behavior: HOCON always tried first, programmatic setup only used
  as exception fallback
- New behavior: Programmatic setup takes precedence, HOCON used if not provided

This ensures programmatic configuration properly overrides HOCON defaults,
which is the expected behavior for Setup-based configuration in Akka.NET.

The bug existed since DotNettySslSetup was introduced in July 2023
(commit 588d5d6). Existing tests passed only because they triggered
the exception-based fallback path (HOCON with enable-ssl=true but no
certificate path).
Copy link
Member Author

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Detailed my changes

const string setupCertPath = "Resources/akka-client-cert.pfx";
var setupCert = new X509Certificate2(setupCertPath, Password, X509KeyStorageFlags.DefaultKeySet);

var sslSetup = new DotNettySslSetup(setupCert, suppressValidation: true, requireMutualAuthentication: false, validateCertificateHostname: true);
Copy link
Member Author

Choose a reason for hiding this comment

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

Use two different certs - validate that the setup overrides the HOCON

Assert.True(settings.EnableSsl);

// BUG: DotNettySslSetup should take precedence over HOCON, but currently HOCON wins
// because CreateOrDefault tries HOCON first, and only uses the setup as an exception fallback
Copy link
Member Author

Choose a reason for hiding this comment

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

This assertion failed before our fix.

ClientSocketWorkerPoolSize: ComputeWorkerPoolSize(config.GetConfig("client-socket-worker-pool")),
MaxFrameSize: ToNullableInt(config.GetByteSize("maximum-frame-size", null)) ?? 128000,
Ssl: enableSsl ? SslSettings.CreateOrDefault(config.GetConfig("ssl"), sslSettings) : SslSettings.Empty,
Ssl: enableSsl ? (sslSettings ?? SslSettings.Create(config.GetConfig("ssl"))) : SslSettings.Empty,
Copy link
Member Author

Choose a reason for hiding this comment

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

Deprioritizes the default HOCON, in favor of what' specified in the DotNettySslSetup

Copy link
Contributor

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

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

LGTM

@Arkatufus Arkatufus enabled auto-merge (squash) October 22, 2025 19:47
@Aaronontheweb Aaronontheweb merged commit d0c7ad4 into akkadotnet:dev Oct 22, 2025
8 of 11 checks passed
@Aaronontheweb Aaronontheweb deleted the fix/dotnetty-ssl-setup-override-7917 branch October 22, 2025 20:49
Aaronontheweb added a commit to Aaronontheweb/akka.net that referenced this pull request Oct 22, 2025
…kkadotnet#7918)

* Add failing test to expose DotNettySslSetup override bug (akkadotnet#7917)

Added test case that demonstrates DotNettySslSetup settings being ignored
when HOCON has valid certificate configuration. The test configures:

- HOCON with valid certificate path and settings
- DotNettySslSetup with different certificate and settings

Expected: DotNettySslSetup should take precedence (programmatic over config)
Actual: HOCON certificate is used, DotNettySslSetup is completely ignored

The bug occurs because CreateOrDefault() tries HOCON first and only uses
the programmatic setup as an exception fallback. This test fails and
will pass once the fix is applied to make programmatic setup take precedence.

Existing tests didn't catch this because they only test the exception-based
fallback path (HOCON with enable-ssl=true but no certificate path).

* Fix DotNettySslSetup being ignored when HOCON has valid SSL config (akkadotnet#7917)

Changed SSL settings initialization to prioritize programmatic DotNettySslSetup
over HOCON configuration, fixing the precedence order bug.

Changes:
- Modified DotNettyTransportSettings.Create() to check sslSettings (from
  DotNettySslSetup) first before parsing HOCON configuration
- Changed SslSettings.Create() from private to internal to enable direct usage
- Previous behavior: HOCON always tried first, programmatic setup only used
  as exception fallback
- New behavior: Programmatic setup takes precedence, HOCON used if not provided

This ensures programmatic configuration properly overrides HOCON defaults,
which is the expected behavior for Setup-based configuration in Akka.NET.

The bug existed since DotNettySslSetup was introduced in July 2023
(commit 588d5d6). Existing tests passed only because they triggered
the exception-based fallback path (HOCON with enable-ssl=true but no
certificate path).
Aaronontheweb added a commit that referenced this pull request Oct 22, 2025
…7918) (#7919)

* Add failing test to expose DotNettySslSetup override bug (#7917)

Added test case that demonstrates DotNettySslSetup settings being ignored
when HOCON has valid certificate configuration. The test configures:

- HOCON with valid certificate path and settings
- DotNettySslSetup with different certificate and settings

Expected: DotNettySslSetup should take precedence (programmatic over config)
Actual: HOCON certificate is used, DotNettySslSetup is completely ignored

The bug occurs because CreateOrDefault() tries HOCON first and only uses
the programmatic setup as an exception fallback. This test fails and
will pass once the fix is applied to make programmatic setup take precedence.

Existing tests didn't catch this because they only test the exception-based
fallback path (HOCON with enable-ssl=true but no certificate path).

* Fix DotNettySslSetup being ignored when HOCON has valid SSL config (#7917)

Changed SSL settings initialization to prioritize programmatic DotNettySslSetup
over HOCON configuration, fixing the precedence order bug.

Changes:
- Modified DotNettyTransportSettings.Create() to check sslSettings (from
  DotNettySslSetup) first before parsing HOCON configuration
- Changed SslSettings.Create() from private to internal to enable direct usage
- Previous behavior: HOCON always tried first, programmatic setup only used
  as exception fallback
- New behavior: Programmatic setup takes precedence, HOCON used if not provided

This ensures programmatic configuration properly overrides HOCON defaults,
which is the expected behavior for Setup-based configuration in Akka.NET.

The bug existed since DotNettySslSetup was introduced in July 2023
(commit 588d5d6). Existing tests passed only because they triggered
the exception-based fallback path (HOCON with enable-ssl=true but no
certificate path).
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.

SslSettings derived from DotNettySslSetup might never actually gets applied

2 participants