Shared knowledge · Advanced · Language-neutral

Connections, TLS and mTLS in CoAkka Runtime

Network mode decides whether a process accepts connections. Connection strategy decides how Core opens and reuses them. TLS/mTLS protects that same path. These decisions are related, but none replaces another.

01 · Shared model

Configure each axis for the question it answers

Network mode

Does this process keep all work local, call remote peers only, or also accept peer connections? Choose EMBEDDED, OUTBOUND_ONLY or NETWORK_NODE.

Connection strategy

Does every exchange open a connection, or does Core keep a bounded set for reuse? This is a startup policy for each CoAkka Runtime instance.

Transport security

Does the TCP path use plaintext, server-authenticated TLS, or mutual identity with mTLS? Security mode is independent of strategy.

Under the current startup contract, omitting the connection group asks Core to select MULTIPLEXED; omitting the security group keeps PLAINTEXT. This is an effective default published by Core, not a connector default table. The frozen legacy constructor alone retains PER_EXCHANGE + PLAINTEXT. Read the startup configuration and effective capabilities of the exact native artifact; an edition or package name is not capability evidence.

02 · Connection strategy

Keep multiplexing by default; select another mode only when the workload needs it

Per exchange

Connect, send one request, receive one terminal result, then close. One exchange uses one connection. This is the explicit baseline and legacy-constructor default, not the current omitted-input default.

Bounded pool

Borrow and reuse one of a bounded set of retained connections. Each connection still handles only one exchange at a time.

Persistent single-flight

Retain at most one connection for an exact endpoint and serialize exchanges. Use it only when its capability is effective.

Multiplexed

Retain a connection and correlate multiple bounded streams concurrently. This is the current startup contract's omitted-input default; the current limit is 16 streams per connection.

Bounded-pool defaults revision 1 retains at most 8 connections, retires one after 1024 requests and uses a 30-second idle timeout. Override tuning only when the artifact reports tuning capability and measurements show that the defaults do not fit.

03 · Trust boundary

Terminate TLS/mTLS where identity is actually checked

Plaintext

No encryption and no certificate-based peer authentication. Use it only when an external boundary has been selected and accepted explicitly.

TLS

Encrypts traffic and lets the outbound participant verify the receiver certificate and host identity.

Mutual TLS

Adds a client certificate so the receiver also verifies the caller's identity.

CoAkka Runtime TLS protects the built-in public TCP path with TLS 1.2 as the minimum; TLS 1.3 may be negotiated. Public ingress TLS still belongs at the gateway or ingress. Certificate issuance, secret distribution, firewall/CNI/DNS, authorization and clock readiness remain platform or app-host concerns. Runtime TLS/mTLS between CoAkka participants does not require a service-mesh sidecar, although an organization may still choose a mesh for non-CoAkka traffic or a centralized proxy policy.

On edge devices, a LAN or a private VLAN, a private address alone does not prove confidentiality or peer identity. Do not enable certificate validation before the host has a trustworthy wall clock.

See how mTLS and user permissions work in an order lookup.

04 · Credential lifecycle

The platform provisions credentials; Core publishes an immutable context

mode
PLAINTEXT, TLS or MUTUAL_TLS.
credential_generation
Positive at startup; a live reload must be strictly newer.
credential_id
A non-secret operator label of at most 127 bytes.
ca_certificate_file
PEM trust roots used to verify peers.
identity_certificate_file
The process's PEM identity certificate chain.
private_key_file
The matching PEM private key, protected by narrow file permissions.
GRACEFUL
The new generation serves new handshakes; existing sessions finish on their captured generation.
DRAIN_EXISTING_CONNECTIONS
Adds bounded retirement for old sessions without interrupting an in-flight request.
  1. Platform or secret tooling writes the next file set atomically.
  2. Application control flow submits the same TLS/mTLS mode with a higher generation; do not reload inside a latency-sensitive request handler.
  3. Core loads and validates the entire candidate before publishing a new immutable context.
  4. The app checks the structured result before retiring old material under its deployment policy.

Paths are borrowed only during synchronous apply. Public snapshots never return paths, PEM, private keys or raw TLS diagnostics. Core does not run a file-polling thread or renew certificates.

05 · Language projection · Go first

Go: network node + bounded pool + mTLS + reload

This is an advanced deployment sample, not a Beginner lesson. It requires connector v3.3.2, a native profile with the required capabilities, a DNS/advertise name present in the certificate SAN and two mounted secret sets. Copy the file into an IDE, then replace the identity, endpoint and secret paths for your platform.

ReadRuntimeCapabilities
Reads truth from the loaded native artifact; the sample fails closed without bounded pool, mTLS and credential reload.
NetworkNode
Binds every interface on port 19301 but advertises one concrete DNS name shared by peers and certificate identity.
ConnectionStrategy
Selects bounded pool while leaving provenance-bearing defaults in Core instead of copying a tuning table into the app.
Security
Generation 1 is applied while the host is still CREATED; rejected startup releases the handle.
TCPConnectionConfig / TCPSecurityInfo
Read what Core actually accepted instead of inferring effective state from input.
ApplyTCPSecurity
Submits generation 2 in the same mTLS mode; the result identifies which generation remains active if the candidate is rejected.
connectivity.go
package main

import (
	"errors"
	"fmt"
	"os"

	coakka "github.com/phuong-tran/coakka-runtime-go/v3"
)

func run() (err error) {
	capabilities, err := coakka.ReadRuntimeCapabilities("")
	if err != nil {
		return fmt.Errorf("read CoAkka Runtime capabilities: %w", err)
	}
	required := coakka.RuntimeCapabilityTCPBoundedPool |
		coakka.RuntimeCapabilityTCPMutualTLS |
		coakka.RuntimeCapabilityTLSCredentialReload
	if !capabilities.Supports(required) {
		return errors.New("loaded CoAkka Runtime profile does not provide bounded pool, mTLS and credential reload")
	}

	security := coakka.RuntimeTCPSecuritySpec{
		Mode:                    coakka.RuntimeTCPSecurityMutualTLS,
		ReloadMode:              coakka.RuntimeTLSReloadGraceful,
		CredentialGeneration:    1,
		CredentialID:            "orders-2026-11-a",
		CACertificateFile:       "/run/secrets/coakka/ca.pem",
		IdentityCertificateFile: "/run/secrets/coakka/tls.crt",
		PrivateKeyFile:          "/run/secrets/coakka/tls.key",
	}
	host, err := coakka.StartRuntimeHost(coakka.ConnectorStartSpec{
		SystemName: "orders",
		NodeID:     "orders-0",
		Routes:     []coakka.RouteSpec{coakka.LocalRouteDefault("orders.quote")},
		Network: coakka.NetworkNode(
			"0.0.0.0", 19301,
			"orders-0.orders.default.svc.cluster.local", 19301,
		),
		ConnectionStrategy: &coakka.RuntimeTCPConnectionStrategySpec{
			Mode: coakka.RuntimeTCPConnectionBoundedPool,
		},
		Security: &security,
	}, "")
	if err != nil {
		return fmt.Errorf("start secure CoAkka Runtime node: %w", err)
	}
	defer func() {
		err = errors.Join(err, host.Close())
	}()

	connection, err := host.TCPConnectionConfig()
	if err != nil {
		return fmt.Errorf("read effective connection strategy: %w", err)
	}
	activeSecurity, err := host.TCPSecurityInfo()
	if err != nil {
		return fmt.Errorf("read effective transport security: %w", err)
	}
	fmt.Printf("connection_mode=%d security_mode=%d credential_generation=%d\n",
		connection.Mode, activeSecurity.Mode, activeSecurity.CredentialGeneration)

	nextSecurity := security
	nextSecurity.CredentialGeneration = 2
	nextSecurity.CredentialID = "orders-2026-11-b"
	nextSecurity.IdentityCertificateFile = "/run/secrets/coakka-next/tls.crt"
	nextSecurity.PrivateKeyFile = "/run/secrets/coakka-next/tls.key"

	result, err := host.ApplyTCPSecurity(nextSecurity)
	if err != nil {
		return fmt.Errorf("submit credential generation 2: %w", err)
	}
	if !result.Applied() {
		return fmt.Errorf("credential reload rejected: %s; active generation=%d",
			result.ReasonName, result.ActiveSecurity.CredentialGeneration)
	}
	fmt.Printf("credential_generation=%d credential_id=%s\n",
		result.ActiveSecurity.CredentialGeneration,
		result.ActiveSecurity.CredentialID)
	return nil
}

func main() {
	if err := run(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}

The sample is formatted and compile-checked against the exact Go connector. It is not executed in the portal because certificates, DNS and a TLS-capable native profile are deployment inputs, not fake secrets that belong in an example.

06 · Failure law and effective state

Read a failure at the boundary where it occurs

Initial apply or reload is invalid
The synchronous apply result rejects the candidate and preserves the active immutable context. No envelope exists, so no deadletter is created.
Outbound handshake fails for an admitted envelope
CoAkka Runtime emits REMOTE_TRANSPORT_SECURITY_FAILED with bounded metadata. Because negotiation precedes business bytes, delivery certainty is NOT_DELIVERED.
Inbound handshake fails before request decode
No message_id or original envelope exists. Core records a REMOTE_TRANSPORT_FAILED ingress event instead of inventing a deadletter.

Stable diagnostic categories cover invalid local configuration, handshake failure, untrusted or expired certificates, identity mismatch and a missing client certificate. Connectors and applications branch on stable reasons and structured metadata, never the prose in detail. A failed or stale reload must not change the active generation.