Hi,

A dynamic keystore update is rejected for any certificate whose
subjectAltName contains an otherName entry, even when the renewed
certificate has exactly the same SANs as the old one. I initially
considered opening a JIRA issue, but it seems this is the place to go
to, first.



What we see (Kafka 4.4.0, KRaft, PEM keystore, OpenJDK 25): after
renewing a broker certificate in place, a per-broker update of
listener.name.client.ssl.keystore.location (same path) fails while
publishing the metadata delta, and the broker keeps serving the old
certificate:

ERROR Encountered metadata publishing fault: Error updating node with
new configuration:  in MetadataDelta up to 974
org.apache.kafka.common.config.ConfigException: Validation of dynamic
config update of SSLFactory failed:
org.apache.kafka.common.config.ConfigException: Keystore
SubjectAltNames do not match:
  existing={alias=kafka, SAN=[[2, kafka.example.com],
    [2, broker3.example.com],
    [0, [B@5126b2cb, 1.3.6.1.4.1.311.20.2.3,
HTTP/[email protected]],
    [0, [B@4a72d47e, 1.3.6.1.5.2.2, [B@3e953fd2]]},
  new={alias=kafka, SAN=[[0, [B@69e3b0a, 1.3.6.1.4.1.311.20.2.3,
HTTP/[email protected]],
    [2, kafka.example.com], [2, broker3.example.com],
    [0, [B@442d6aa3, 1.3.6.1.5.2.2, [B@30b8545b]]}
  at 
org.apache.kafka.common.security.ssl.SslFactory.createNewSslEngineFactory(SslFactory.java:192)
  at 
org.apache.kafka.common.security.ssl.SslFactory.validateReconfiguration(SslFactory.java:118)
  at 
org.apache.kafka.common.network.SaslChannelBuilder.validateReconfiguration(SaslChannelBuilder.java:196)
  at 
kafka.server.DynamicBrokerConfig.processReconfigurable(DynamicBrokerConfig.scala:522)
  at 
kafka.server.DynamicBrokerConfig.processListenerReconfigurable(DynamicBrokerConfig.scala:510)
  at 
kafka.server.DynamicBrokerConfig.$anonfun$reloadUpdatedFilesWithoutConfigChange$2(DynamicBrokerConfig.scala:314)
...

Both sets hold the same entries; only the byte[] identities differ.

Cause, as far as I can tell:

SslFactory.CertificateEntries stores
Set.copyOf(cert.getSubjectAlternativeNames()) (SslFactory.java:371-373
at 4.4.0)

ensureCompatibleSANs checks
newEntry.subjectAltNames.containsAll(oldEntry.subjectAltNames)
(SslFactory.java:360).

Each SAN is a List<?>, and for an otherName (type 0) the JDK puts the
DER-encoded value into that list as a byte[].

List.equals compares elements with equals(), and byte[] uses identity,
so an otherName entry never matches one decoded from another
certificate, or from the same certificate decoded twice.

The superset check comes from KAFKA-10279; KIP-978 (KAFKA-15464) added
ssl.allow.san.changes to bypass it, but neither covers otherName
entries, and I found nothing about this in the archives.

To reproduce:
1. A broker listener on SSL or SASL_SSL whose keystore certificate has
an otherName SAN (e.g. a FreeIPA service certificate requested with
ipa-getcert request -K HTTP/<host> ...).
2. Renew the certificate with the same subject and SANs, and write it
to the same keystore file.
3. kafka-configs.sh --bootstrap-server <host>:9092 --entity-type
brokers --entity-name <id> --alter --add-config
listener.name.<listener>.ssl.keystore.location=<same path>

Expected: the renewed certificate is loaded.
Actual: "Keystore SubjectAltNames do not match"; the old certificate
stays in use.

A possible fix: compare SAN entries by content: replace byte[]
elements with ByteBuffer.wrap(bytes) when building subjectAltNames,
before Set.copyOf. A unit test that reloads an unchanged keystore
whose certificate has an otherName SAN should reproduce it.

Best regards,
Robert Sjöblom

-- 
Innehållet i detta e-postmeddelande är konfidentiellt och avsett endast för 
adressaten.Varje spridning, kopiering eller utnyttjande av innehållet är 
förbjuden utan tillåtelse av avsändaren. Om detta meddelande av misstag 
gått till fel adressat vänligen radera det ursprungliga meddelandet och 
underrätta avsändaren via e-post

Reply via email to