[ 
https://issues.apache.org/jira/browse/KAFKA-21557?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Andras Katona updated KAFKA-21557:
----------------------------------
    Description: 

When a Connect worker starts, it tries to create its internal topics (config, 
offsets, status) with {{cleanup.policy=compact}}. If CreateTopics fails with an 
authorization error, {{TopicAdmin}} logs it at DEBUG and Connect carries on, 
assuming the topic exists or will be auto-created.

If the topic doesn't exist, {{KafkaBasedLog.start()}} then calls 
{{consumer.partitionsFor(topic)}} for up to 30s. The internal consumer uses the 
default {{allow.auto.create.topics=true}}, so with 
{{auto.create.topics.enable=true}} on the broker this metadata request can 
create the topic with the broker's defaults, usually {{cleanup.policy=delete}} 
and {{num.partitions=1}}.

The cleanup policy check doesn't catch this on the worker that triggered the 
auto-create: it runs before the topic exists, finds no config, and only logs at 
INFO. That worker keeps running on a non-compacted topic, and retention can 
delete its data, such as source offsets. Every other worker then fails at 
startup with:
{noformat}
ConfigException: Topic '...' supplied via the 'offset.storage.topic' property 
is required to have 'cleanup.policy=compact' ... but found the topic currently 
has 'cleanup.policy=delete'.
{noformat}

*When it happens:* CREATE is checked on the active controller for Connect's 
CreateTopics, but on the broker first (then on the controller) for an 
auto-create. If the broker denies, the consumer gets 
{{TOPIC_AUTHORIZATION_FAILED}} and the worker fails cleanly. The topic is 
auto-created only if the controller denies Connect's CreateTopics, the broker 
already allows CREATE, and the controller starts allowing it within the 30s 
retry loop. We hit this with an authorizer whose nodes load their policies 
independently at startup, so the active controller was the last to allow. With 
{{StandardAuthorizer}} it's hard to reproduce, because the controller applies 
ACL changes before the brokers. It can be reproduced by making the Connect 
principal a super user on the brokers only and adding a CREATE ACL while the 
worker is starting.

The connector-specific offsets topics (KIP-618) have the same problem.

*Fix:*
# If a missing internal topic can't be created, check whether it exists; if it 
doesn't, retry the creation until {{default.api.timeout.ms}}, then fail with a 
clear error ({{KafkaTopicBasedBackingStore}}). Setups where the topic is 
created manually and the worker has no CREATE permission keep working as before.
# Set {{allow.auto.create.topics=false}} on the consumers of Connect's internal 
topics, so the broker can never create them with its defaults 
({{KafkaBasedLog.createConsumer()}}; 
{{Worker.regularSourceOffsetsConsumerConfigs}} and 
{{Worker.exactlyOnceSourceOffsetsConsumerConfigs}} for connector-specific 
offsets topics).

MirrorMaker 2 in dedicated mode uses the same backing stores for its 
{{mm2-*.internal}} topics, so this likely causes KAFKA-13465, KAFKA-17101, 
KAFKA-17784 and KAFKA-19046.

*Not covered:* MM2's connector-level topics (offset-syncs, checkpoints, 
heartbeats) are created by {{MirrorUtils.createCompactedTopic}}, which has the 
same fallback, and are read by consumers with the same default. This can be a 
follow-up.

  was:
When a Connect worker starts, it tries to create its internal topics (config, 
offsets, status) with {color:#0747A6}cleanup.policy=compact{color}. If that 
CreateTopics call fails with an authorization error, Connect logs it at DEBUG 
and carries on. It assumes the topic exists or will be auto-created.

Next, {color:#0747A6}KafkaBasedLog.start(){color} calls 
{color:#0747A6}consumer.partitionsFor(topic){color}. The internal consumer uses 
the default {color:#0747A6}allow.auto.create.topics=true{color}. So if the 
broker has {color:#0747A6}auto.create.topics.enable=true{color}, this metadata 
request creates the topic with the broker's defaults, usually 
{color:#0747A6}cleanup.policy=delete{color} and 
{color:#0747A6}num.partitions=1{color}.

The cleanup policy check doesn't catch this on the worker that triggered the 
auto-create. It runs before the topic exists, finds no config, and only logs at 
INFO. That worker keeps running on a non-compacted topic. Its data, such as 
source offsets, can be removed by retention. Every other worker then fails at 
startup with:

{color:#0747A6}ConfigException: Topic '...' supplied via the 
'offset.storage.topic' property is required to have 'cleanup.policy=compact' 
... but found the topic currently has 'cleanup.policy=delete'.{color}

We hit this when the worker's CreateTopics call was briefly denied: the 
authorizer was still loading its policies at startup.

The connector-specific offsets topics (KIP-618) have the same problem.

Proposed fix: set {color:#0747A6}allow.auto.create.topics=false{color} on the 
consumers that read Connect's internal topics:
- {color:#0747A6}KafkaBasedLog.createConsumer(){color}, for the worker's 
config, offsets and status topics
- {color:#0747A6}Worker.regularSourceOffsetsConsumerConfigs{color} and 
{color:#0747A6}Worker.exactlyOnceSourceOffsetsConsumerConfigs{color}, for 
connector-specific offsets topics

The topic should always be created by Connect with the right settings. If 
Connect can't create it, the worker should fail rather than run on a topic with 
the wrong config.

Related, possibly separate:
- {color:#0747A6}TopicAdmin.createOrFindTopics{color} logs a denied create at 
DEBUG only. It should at least be a WARN.
- The MirrorMaker 2 internal topics (offset-syncs, checkpoints, heartbeats) are 
compacted too, and their consumers have the same default.


> Connect internal topics can be auto-created by the broker with the wrong 
> cleanup policy
> ---------------------------------------------------------------------------------------
>
>                 Key: KAFKA-21557
>                 URL: https://issues.apache.org/jira/browse/KAFKA-21557
>             Project: Kafka
>          Issue Type: Bug
>          Components: connect
>            Reporter: Andras Katona
>            Assignee: Andras Katona
>            Priority: Major
>
> When a Connect worker starts, it tries to create its internal topics (config, 
> offsets, status) with {{cleanup.policy=compact}}. If CreateTopics fails with 
> an authorization error, {{TopicAdmin}} logs it at DEBUG and Connect carries 
> on, assuming the topic exists or will be auto-created.
> If the topic doesn't exist, {{KafkaBasedLog.start()}} then calls 
> {{consumer.partitionsFor(topic)}} for up to 30s. The internal consumer uses 
> the default {{allow.auto.create.topics=true}}, so with 
> {{auto.create.topics.enable=true}} on the broker this metadata request can 
> create the topic with the broker's defaults, usually 
> {{cleanup.policy=delete}} and {{num.partitions=1}}.
> The cleanup policy check doesn't catch this on the worker that triggered the 
> auto-create: it runs before the topic exists, finds no config, and only logs 
> at INFO. That worker keeps running on a non-compacted topic, and retention 
> can delete its data, such as source offsets. Every other worker then fails at 
> startup with:
> {noformat}
> ConfigException: Topic '...' supplied via the 'offset.storage.topic' property 
> is required to have 'cleanup.policy=compact' ... but found the topic 
> currently has 'cleanup.policy=delete'.
> {noformat}
> *When it happens:* CREATE is checked on the active controller for Connect's 
> CreateTopics, but on the broker first (then on the controller) for an 
> auto-create. If the broker denies, the consumer gets 
> {{TOPIC_AUTHORIZATION_FAILED}} and the worker fails cleanly. The topic is 
> auto-created only if the controller denies Connect's CreateTopics, the broker 
> already allows CREATE, and the controller starts allowing it within the 30s 
> retry loop. We hit this with an authorizer whose nodes load their policies 
> independently at startup, so the active controller was the last to allow. 
> With {{StandardAuthorizer}} it's hard to reproduce, because the controller 
> applies ACL changes before the brokers. It can be reproduced by making the 
> Connect principal a super user on the brokers only and adding a CREATE ACL 
> while the worker is starting.
> The connector-specific offsets topics (KIP-618) have the same problem.
> *Fix:*
> # If a missing internal topic can't be created, check whether it exists; if 
> it doesn't, retry the creation until {{default.api.timeout.ms}}, then fail 
> with a clear error ({{KafkaTopicBasedBackingStore}}). Setups where the topic 
> is created manually and the worker has no CREATE permission keep working as 
> before.
> # Set {{allow.auto.create.topics=false}} on the consumers of Connect's 
> internal topics, so the broker can never create them with its defaults 
> ({{KafkaBasedLog.createConsumer()}}; 
> {{Worker.regularSourceOffsetsConsumerConfigs}} and 
> {{Worker.exactlyOnceSourceOffsetsConsumerConfigs}} for connector-specific 
> offsets topics).
> MirrorMaker 2 in dedicated mode uses the same backing stores for its 
> {{mm2-*.internal}} topics, so this likely causes KAFKA-13465, KAFKA-17101, 
> KAFKA-17784 and KAFKA-19046.
> *Not covered:* MM2's connector-level topics (offset-syncs, checkpoints, 
> heartbeats) are created by {{MirrorUtils.createCompactedTopic}}, which has 
> the same fallback, and are read by consumers with the same default. This can 
> be a follow-up.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to