Skip to content

[rpc] Add mTLS authentication from client certificates - #5333

Merged
fresh-borzoni merged 2 commits into
apache:mainfrom
morazow:oss-3793-mtls-authentication
Nov 26, 2026
Merged

fresh-borzoni merged 2 commits into
apache:mainfrom
morazow:oss-3793-mtls-authentication

Conversation

@morazow

@morazow morazow commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Linked issue: close #3793, close #5338

Part of #3786 (FIP-29: (m)TLS Support). Builds on #3795 (SslPrincipalMapper), #3792 (server pipeline) and #3797 (client pipeline).

Before this change, a server with an mTLS entry in security.protocol.map failed at startup with "No plugin for the protocol 'mTLS' is found in the classpath". The earlier pull requests already made such a listener require a client certificate, but no authenticator turned that certificate into a principal.

With this change, the server maps the distinguished name (DN) of the client certificate to a FlussPrincipal with security.ssl.principal.mapping.rules. The principal then goes through the existing Session and Authorizer path.

Brief change log

  • MutualTlsAuthenticationPlugin (new, registered in META-INF/services), with the client and server authenticators as nested classes:
    • The client authenticator sends one empty token. The certificate already travels in the TLS handshake. The token must not be null, because ServerConnection sends no AuthenticateRequest for a null token and the server would then reject every request of the connection.
    • The server authenticator reads the peer principal from the SSLSession, maps the DN, and creates a principal of type User. It reads the session once, so a later renegotiation cannot change the principal of the connection.
    • It rejects a connection without TLS, a client without a certificate, a peer principal that is not an X.500 name, and a DN that matches no rule. The message for an unmatched DN names the DN but not the configured rules, because the message of an AuthenticationException goes to the client. The server logs the rules.
  • ServerAuthenticator.AuthenticateContext: new default method SSLSession sslSession(), which returns null for a connection without TLS. NettyServerHandler implements it from the SslHandler of the channel.
  • SslConfig.fromServerConfig parses security.ssl.principal.mapping.rules at startup. The server creates one authenticator per connection, so without this check an invalid rule would fail every connection of a server that started without error.
  • FlussProtocolPlugin: a server now fails at startup when client.security.protocol differs from the authentication protocol of its internal listener. Servers connect to each other with the client options of the server configuration, so this mismatch would fail every request between servers at runtime.
  • On the internal listener, the mTLS server authenticator accepts only principals listed in super.users. The server skips ACL checks for requests on the internal listener, and all TLS listeners share one truststore and one set of mapping rules. Without this rule, a regular user certificate gets the same access as a server ([TLS] Any trusted client certificate gets server-level access on an mTLS internal listener #5338).
  • InternalListenerConfigValidator (new): a server with an mTLS internal listener connects to itself in memory at startup, and fails to start if the listener rejects the certificate in client.security.ssl.keystore.*. This covers an untrusted certificate, a certificate that no mapping rule matches, a principal outside super.users, and a certificate whose extended key usage allows only serverAuth.
  • FlussPrincipal.parsePrincipals: only the first colon of a super.users entry separates the type from the name. Before, User:spiffe://example.org/fluss was parsed as User:spiffe.
  • NettyServerHandler logs a failed authentication at INFO with the remote address, the listener and the message. This applies to every authentication protocol. Before, the server logged nothing for a rejected AuthenticateRequest.
  • FlussClusterExtension (test code) copies client.security.protocol from the cluster configuration to its helper client, which talks to the internal listener while the cluster starts.

The per-listener client certificate requirement and its validation (an mTLS listener must enable TLS and needs a truststore; an mTLS client needs TLS and a keystore) are already in SslConfig and are not changed here.

Tests

  • MutualTlsAuthenticationPluginTest (new): the client token is empty and not null; the server authenticator rejects a connection without a TLS session.
  • MutualTlsAuthenticationITCase (new, real NettyServer and NettyClient): principal from a rule that extracts the common name; principal with the DEFAULT rule; a DN that matches no rule is rejected and the message does not contain the rules; a client without a certificate; a client with an untrusted certificate; a client with a certificate but client.security.protocol=PLAINTEXT; on an internal listener, a super user is accepted and another principal is rejected.
  • TlsAuthenticationITCase (new): a cluster of 3 tablet servers with the authorizer enabled and mTLS on both the client listener and the internal listener. The admin certificate, listed in super.users, creates a table and writes rows, and all 3 replicas stay in sync, which shows that the servers replicate over mTLS. The guest certificate is denied and succeeds after an ACL grant. On the internal listener, the guest certificate is rejected. The servers connect to each other with a certificate of their own, which is listed in super.users.
  • SslContextFactoryTest: invalid mapping rules fail SslConfig.fromServerConfig.
  • FlussProtocolPluginTest: the internal listener check, for the failing and the matching configuration. The check of the server's own certificate: a principal outside super.users, no matching rule, an untrusted certificate, and a CA-issued certificate with and without clientAuth in its extended key usage.
  • FlussPrincipalTest (new): super.users entries, including a name that contains colons.
  • NettyClientTlsTest.testRejectedClientCertificateFailsAsNonRetriable: uses a real mTLS listener instead of a hand-built Netty server.

API and Format

  • ServerAuthenticator.AuthenticateContext (@PublicEvolving) gets the default method sslSession(). Existing implementations stay source and binary compatible.
  • mTLS is a new value for security.protocol.map and client.security.protocol.
  • No wire format or storage format change. The exchange uses the existing AuthenticateRequest.
  • Three startup rules are new. The server rejects invalid security.ssl.principal.mapping.rules, an internal listener whose authentication protocol differs from client.security.protocol, and an mTLS internal listener that rejects the server's own client certificate.
  • An mTLS internal listener accepts only principals in super.users. The principal of the certificate that servers present to each other must be listed there.
  • FlussPrincipal.parsePrincipals (@PublicEvolving) splits an entry at the first colon only. An entry with one colon parses as before.

Documentation

  • website/docs/security/authentication.md: new mTLS section with the server and client options, the principal mapping rules, mTLS on the internal listener, and certificate validity on open connections.
  • website/docs/security/overview.md, website/docs/engine-flink/ddl.md, website/docs/engine-flink/options.md: the lists of supported protocols include mTLS.
  • Descriptions of security.protocol.map and client.security.protocol in ConfigOptions.

🤖 Generated with Claude Code

@morazow
morazow marked this pull request as ready for review November 23, 2026 09:20
Comment thread website/docs/security/authentication.md Outdated
```

### mTLS on the Internal Listener
Servers connect to each other over the internal listener with the `client.security.*` options of their own `conf/server.yaml`. If the internal listener uses mTLS, each server needs `client.security.protocol: mTLS`, `client.security.ssl.enabled: true`, and a client keystore in `client.security.ssl.keystore.*`. The server truststore must accept the certificate in that keystore. A server whose internal listener uses mTLS but whose `client.security.protocol` is not `mTLS` fails to start.

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.

Requests on the internal listener skip authorization, and the server truststore is shared by all TLS listeners. So any client certificate the server accepts, including a regular user's, gets full access through the internal port. The new ITCase is set up this way too: one truststore holds the guest certificate. Could this section say that clearly and recommend one of these?

  • isolate the internal port at the network level, or
  • issue server certificates from a separate CA that the user-facing listeners don't trust

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.

Done 👍

String internalListener = conf.get(ConfigOptions.INTERNAL_LISTENER_NAME);
String clientProtocol = conf.get(ConfigOptions.CLIENT_SECURITY_PROTOCOL);
if (sslConfig != null
&& sslConfig.requiresClientAuth(internalListener)

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.

This catches an mTLS internal listener with a non-mTLS client protocol, but not the reverse. If the internal listener uses TLS with PLAINTEXT or SASL auth and client.security.protocol is mTLS, the server starts. Then every request between servers fails in matchProtocol, and the client treats that as non-retriable. Comparing the internal listener's protocol-map entry (default PLAINTEXT) with client.security.protocol, ignoring case, would cover both directions and the SASL case as well.

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.

Fixed 👍


public MutualTlsServerAuthenticator(Configuration configuration) {
this.principalMapper =
SslPrincipalMapper.fromRules(

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.

Nit: this parses the rules and compiles their regexes for every new connection. The plugin could parse them once and share the mapper.

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.

I think it is fine since the regexes are short strings, but opted for parsing them once and sharing the mapper 🤝

@polyzos polyzos 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.

Sorry, I approved by mistake. This is my actual review.

Thanks, this fits FIP-29 well. The auth exchange, principal mapping and startup validation look right to me.

Before merge, I'd like the internal-listener gap from the docs comment tracked as its own issue under #3786, linked here and marked as a release blocker for mTLS. Requests on the internal listener skip authorization, and every TLS listener shares one truststore and one set of mapping rules. So with mTLS on the internal listener, any trusted certificate can do what a server can. Fixing that properly is a design decision FIP-29 doesn't cover, for example only accepting super.users principals on the internal listener, or per-listener rules or truststores. I think it's better settled there than in this PR. Until then, the docs warning keeps operators from walking into it.

@fresh-borzoni any thoughts?

@morazow
morazow force-pushed the oss-3793-mtls-authentication branch 2 times, most recently from 6358c5e to 4cbc08b Compare November 23, 2026 10:11
@morazow
morazow requested a review from polyzos November 23, 2026 12:14
@morazow

morazow commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Hello @polyzos , thanks for the reviews! Please have another look 🙏

I have created this issue: #5338 to be addressed later.

@fresh-borzoni

Copy link
Copy Markdown
Member

Sorry, I approved by mistake. This is my actual review.

Thanks, this fits FIP-29 well. The auth exchange, principal mapping and startup validation look right to me.

Before merge, I'd like the internal-listener gap from the docs comment tracked as its own issue under #3786, linked here and marked as a release blocker for mTLS. Requests on the internal listener skip authorization, and every TLS listener shares one truststore and one set of mapping rules. So with mTLS on the internal listener, any trusted certificate can do what a server can. Fixing that properly is a design decision FIP-29 doesn't cover, for example only accepting super.users principals on the internal listener, or per-listener rules or truststores. I think it's better settled there than in this PR. Until then, the docs warning keeps operators from walking into it.

@fresh-borzoni any thoughts?

I'd rather fix the internal listener here than in #5338, since this PR is what enables mTLS on the internal listener, it doesn't block a separate truststore or separate rules later.

@fresh-borzoni fresh-borzoni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@morazow Thank you, looks fine overall, a couple of comments, PTAL

distinguishedName));
}

principal = new FlussPrincipal(principalName, "User");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

on the internal listener, can we accept only principals listed in super.users? Then a user certificate can't open the internal port, and servers only need their own principal in super.users

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.

Done. On an mTLS internal listener the server now rejects any certificate whose principal is not in super.users.

It also also resolves #5338 🤝

checkTlsListenersExist(sslConfig.enabledListeners());
}
checkInternalListenerMatchesClientTls();
checkInternalListenerMatchesClientProtocol();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

when the internal listener uses mTLS, can we check the server's own certificate at startup? Check that it passes its own truststore, that it matches the mapping rules, and that it's in super.users. right now a wrong certificate or rule only shows up later, when every request between servers fails

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.

Added utility class (InternalListenerConfigValidator) to check the own certificate. I think later we can move couple more methods to this class.

```

### mTLS on the Internal Listener
Servers connect to each other over the internal listener with the `client.security.*` options of their own `conf/server.yaml`. If the internal listener uses mTLS, each server needs `client.security.protocol: mTLS`, `client.security.ssl.enabled: true`, and a client keystore in `client.security.ssl.keystore.*`. The server truststore must accept the certificate in that keystore. A server fails to start if `client.security.protocol` differs from the authentication protocol of its internal listener.

@fresh-borzoni fresh-borzoni Nov 24, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what happens if the server certificate only allows serverAuth? How does it fail and what does the user see?

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.

Nice catch 🚀

I reproduced it locally, wich CA that only allows serverAuth. Now server rejects it in the TLS handshake, before it failed at runtime.

With the startup certificate check above, the server now fails to start and with clear error message. I added a test and a note in the docs.

Comment thread website/docs/security/authentication.md Outdated
Servers connect to each other over the internal listener with the `client.security.*` options of their own `conf/server.yaml`. If the internal listener uses mTLS, each server needs `client.security.protocol: mTLS`, `client.security.ssl.enabled: true`, and a client keystore in `client.security.ssl.keystore.*`. The server truststore must accept the certificate in that keystore. A server fails to start if `client.security.protocol` differs from the authentication protocol of its internal listener.

:::warning
The server skips ACL checks for every request on the internal listener. A client that authenticates on the internal listener can run every operation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

with the super.users check, this warning could go away for mTLS. should it stay only for SASL internal listeners? there the same check would break the Helm chart, since it doesn't put the internal user into super.users

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.

Agreed, with the super.users check the warning no longer applies to mTLS, so I removed it and kept one sentence that explains why the internal listener is restricted.

I did not add the same check for SASL: as you say it breaks the Helm chart. For SASL we can follow-up if we want to add note.

"A map defining the authentication protocol for each listener. "
+ "The format is `listenerName1:protocol1,listenerName2:protocol2`, e.g., `INTERNAL:PLAINTEXT,CLIENT:GSSAPI`. "
+ "Each listener can be associated with a specific authentication protocol. "
+ "The built-in protocols are `PLAINTEXT`, `SASL` and `mTLS`. "

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FIP-29 says the server logs a warning at startup when a SASL listener has no TLS, since passwords then go in clear. I don't see it on main or in the sub-issues, is it planned somewhere?

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.

Created #5364 for it 🤝 It is mentioned in FIP-29 but we didn't have ticket for it so far.

Comment thread website/docs/security/authentication.md Outdated

With these rules, the certificate `CN=alice,OU=Engineering,O=Example` authenticates as `User:alice`. If no rule matches a DN, the server rejects the client. The server checks the syntax of the rules at startup and fails to start if a rule is invalid.

With the `DEFAULT` rule, the principal name contains commas. Separate the entries of `super.users` with semicolons, e.g. `User:CN=admin,O=Example;User:CN=ops,O=Example`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what if a mapped name contains a colon, like a URI in the CN? super.users is split on : and would cut the name I would imagine?

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.

Another good point! Yes, it would cut the name: User:spiffe://example.org/fluss was parsed as User:spiffe.

Fixed, super.users now splits at the first colon only.

The server reads the DN in the RFC 2253 form, for example `CN=alice,OU=Engineering,O=Example`. It applies the rules in `security.ssl.principal.mapping.rules` in order and uses the first rule that matches. The principal type is always `User`.

The value is a comma-separated list of rules. Each rule is one of:
* `DEFAULT`: uses the full DN as the principal name.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the name only comes from the subject DN. with SPIFFE certificates the identity is in the SAN, so is that planned as a follow-up? Shall we file it to track otherwise it's easy to miss

@morazow morazow Nov 25, 2026 •

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.

I created #5366 👍

@morazow

morazow commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @fresh-borzoni , I have addressed your findings! Please have another look 🤝

Closing #5338 also here.

Add the mTLS authentication plugin of FIP-29. On a listener whose
security.protocol.map entry is mTLS, the server maps the distinguished
name of the client certificate to a FlussPrincipal with
security.ssl.principal.mapping.rules.

- Add sslSession() to ServerAuthenticator.AuthenticateContext.
- Fail at startup on invalid mapping rules, and when
  client.security.protocol differs from the authentication protocol of
  the internal listener, for any protocol.
- Accept only principals in super.users on an mTLS internal listener.
  The server skips ACL checks on the internal listener, and all TLS
  listeners share one truststore and one set of mapping rules.
- Fail at startup when the mTLS internal listener rejects the client
  certificate of the server itself.
- Accept a principal name that contains colons in super.users.
- Log failed authentication on the server at INFO.
- Document mTLS in the security docs.
@morazow
morazow force-pushed the oss-3793-mtls-authentication branch from 92cdd00 to 7e7e6e0 Compare November 25, 2026 10:33

@fresh-borzoni fresh-borzoni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@morazow thank you, LGTM 👍
Will merge once CI is green

@fresh-borzoni
fresh-borzoni merged commit 996b8d0 into apache:main Nov 26, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants