Skip to content

Automatic certificate renewal does not work #285

Closed
apache/pulsar
#18097

Description

@danny-krueger

Describe the bug
The reissued certificates from the Cert Manager will not be used by Pulsar until the pods are rebooted.

To Reproduce
Steps to reproduce the behavior:

  1. Activate Cert Manager with the internal issuer.
  2. Wait until the certificate has expired.
  3. The certificates have been updated, but the Java Services have not checked this and SSL errors occur in the Zookeeper.
    ERROR org.apache.zookeeper.server.NettyServerCnxnFactory - Unsuccessful handshake with session 0x0
    2022-08-03T14:53:45,862+0000 [epollEventLoopGroup-7-2] WARN org.apache.zookeeper.server.NettyServerCnxnFactory - Exception caught io.netty.handler.codec.DecoderException: javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_expired at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:480) ~[io.netty-netty-codec-4.1.74.Final.jar:4.1.74.Final] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:279) ~[io.netty-netty-codec-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [io.netty-netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [io.netty-netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) [io.netty-netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) [io.netty-netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [io.netty-netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [io.netty-netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) [io.netty-netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:795) [io.netty-netty-transport-classes-epoll-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:480) [io.netty-netty-transport-classes-epoll-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:378) [io.netty-netty-transport-classes-epoll-4.1.74.Final.jar:4.1.74.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986) [io.netty-netty-common-4.1.74.Final.jar:4.1.74.Final] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [io.netty-netty-common-4.1.74.Final.jar:4.1.74.Final] at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [io.netty-netty-common-4.1.74.Final.jar:4.1.74.Final] at java.lang.Thread.run(Thread.java:829) [?:?]

Expected behavior
When the Cert Manager issues new certificates, Pulsar should also be aware of this and use the new certificates.

Additional context
The certificates have been correctly reissued by the Cert Manager. They were also correct in the Config Maps and in the Secrets. Also where we were in the pods per shell, the new correct SSL certificates were there. But since Pulsar itself was already running, it did not re-read them. We think that Java caches the certificates.

Quick fix
After all pods were restarted everything worked again.

Activity

  1. michaeljmarshall commented on Oct 18, 2022

    @michaeljmarshall
    Member

    @danny-krueger - it's possible that zookeeper does not support reloading certificates for the client facing server. I can see that quorum server allows for reloading cert files, but I don't see the same setting for the client facing server:

    https://github.com/apache/zookeeper/blob/b4f9aab099880ba8ef08eaff697debe6cdeae057/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java#L78

    @eolivelli - would you happen to know?

  2. michaeljmarshall commented on Oct 18, 2022

    @michaeljmarshall
    Member

    Looks like my fork was out of date and I was looking at old information. This issue has already been resolved in Apache Zookeeper just earlier this year: https://issues.apache.org/jira/browse/ZOOKEEPER-3806. Here is the relevant documentation:

    client.certReload : (Java system property: zookeeper.client.certReload) New in 3.7.2, 3.8.1, 3.9.0: Allows client SSL keyStore and trustStore reloading when the certificates on the filesystem change without having to restart the ZK process. Default: false

    We can keep this issue open for now. Then, we we upgrade to a version of zookeeper that supports the feature, we'll add it in as a default.

  3. michaeljmarshall commented on Oct 18, 2022

    @michaeljmarshall
    Member

    The right place to fix this is in our default zk config. I've opened a PR here: apache/pulsar#18097.

  4. danny-krueger commented on Oct 20, 2022

    @danny-krueger
    Author

    Thanks for fixing it. We will try it out, if we update to the next version.

    Currently we have helped ourselves by restarting all pods one after the other when the certificate is updated. We have solved this with Stakater Reloader. This worked great for us.

  5. michaeljmarshall commented on Oct 20, 2022

    @michaeljmarshall
    Member

    @danny-krueger - thanks for highlighting a work around. Apache Zookeeper hasn't released 3.8.1 or 3.9.0, so the complete feature won't be available until ZK gets released and Pulsar upgrades to use that ZK version.

  6. d80tb7 commented on Apr 27, 2024

    @d80tb7

    Just to check- has anyone got cert refresh working with zookeeper? I'm of the opinion that this still won't work. Copying the explanation here from my comment on #359 .

    I think the issue here is that although the Pulsar Helm Chart sets the zookeeper.client.certReload property, this isn't enough. All that property does is to get Zookeeper to update the certs when the truststore or keystore files change. When cert-manager updates the certs, this will cause the cert failes in pulsar/certs/zookeeper/ to update but nothing is going to update the keystore.
    The other Pulsar components (e.g. the bookie) solve this by having code inside them that watches the files under /pulsar/certs/ and then updates the keystore accordingly. Zookeeper doesn't have such code and therefore it seems to me that the certs will never be refreshed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions