Repository navigation
[rpc] Add mTLS authentication from client certificates - #5333
Conversation
| ``` | ||
|
|
||
| ### 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. |
There was a problem hiding this comment.
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
| String internalListener = conf.get(ConfigOptions.INTERNAL_LISTENER_NAME); | ||
| String clientProtocol = conf.get(ConfigOptions.CLIENT_SECURITY_PROTOCOL); | ||
| if (sslConfig != null | ||
| && sslConfig.requiresClientAuth(internalListener) |
There was a problem hiding this comment.
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.
|
|
||
| public MutualTlsServerAuthenticator(Configuration configuration) { | ||
| this.principalMapper = | ||
| SslPrincipalMapper.fromRules( |
There was a problem hiding this comment.
Nit: this parses the rules and compiles their regexes for every new connection. The plugin could parse them once and share the mapper.
There was a problem hiding this comment.
I think it is fine since the regexes are short strings, but opted for parsing them once and sharing the mapper 🤝
There was a problem hiding this comment.
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?
6358c5e to
4cbc08b
Compare
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
left a comment
There was a problem hiding this comment.
@morazow Thank you, looks fine overall, a couple of comments, PTAL
| distinguishedName)); | ||
| } | ||
|
|
||
| principal = new FlussPrincipal(principalName, "User"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
what happens if the server certificate only allows serverAuth? How does it fail and what does the user see?
There was a problem hiding this comment.
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.
| 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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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`. " |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Created #5364 for it 🤝 It is mentioned in FIP-29 but we didn't have ticket for it so far.
|
|
||
| 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`. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
907cd1b to
92cdd00
Compare
|
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.
92cdd00 to
7e7e6e0
Compare
fresh-borzoni
left a comment
There was a problem hiding this comment.
@morazow thank you, LGTM 👍
Will merge once CI is green
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
mTLSentry insecurity.protocol.mapfailed 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
FlussPrincipalwithsecurity.ssl.principal.mapping.rules. The principal then goes through the existingSessionandAuthorizerpath.Brief change log
MutualTlsAuthenticationPlugin(new, registered inMETA-INF/services), with the client and server authenticators as nested classes:ServerConnectionsends noAuthenticateRequestfor a null token and the server would then reject every request of the connection.SSLSession, maps the DN, and creates a principal of typeUser. It reads the session once, so a later renegotiation cannot change the principal of the connection.AuthenticationExceptiongoes to the client. The server logs the rules.ServerAuthenticator.AuthenticateContext: new default methodSSLSession sslSession(), which returns null for a connection without TLS.NettyServerHandlerimplements it from theSslHandlerof the channel.SslConfig.fromServerConfigparsessecurity.ssl.principal.mapping.rulesat 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 whenclient.security.protocoldiffers 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.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 inclient.security.ssl.keystore.*. This covers an untrusted certificate, a certificate that no mapping rule matches, a principal outsidesuper.users, and a certificate whose extended key usage allows onlyserverAuth.FlussPrincipal.parsePrincipals: only the first colon of asuper.usersentry separates the type from the name. Before,User:spiffe://example.org/flusswas parsed asUser:spiffe.NettyServerHandlerlogs 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 rejectedAuthenticateRequest.FlussClusterExtension(test code) copiesclient.security.protocolfrom 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
SslConfigand 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, realNettyServerandNettyClient): principal from a rule that extracts the common name; principal with theDEFAULTrule; 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 butclient.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. Theadmincertificate, listed insuper.users, creates a table and writes rows, and all 3 replicas stay in sync, which shows that the servers replicate over mTLS. Theguestcertificate is denied and succeeds after an ACL grant. On the internal listener, theguestcertificate is rejected. The servers connect to each other with a certificate of their own, which is listed insuper.users.SslContextFactoryTest: invalid mapping rules failSslConfig.fromServerConfig.FlussProtocolPluginTest: the internal listener check, for the failing and the matching configuration. The check of the server's own certificate: a principal outsidesuper.users, no matching rule, an untrusted certificate, and a CA-issued certificate with and withoutclientAuthin its extended key usage.FlussPrincipalTest(new):super.usersentries, 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 methodsslSession(). Existing implementations stay source and binary compatible.mTLSis a new value forsecurity.protocol.mapandclient.security.protocol.AuthenticateRequest.security.ssl.principal.mapping.rules, an internal listener whose authentication protocol differs fromclient.security.protocol, and an mTLS internal listener that rejects the server's own client certificate.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 includemTLS.security.protocol.mapandclient.security.protocolinConfigOptions.🤖 Generated with Claude Code