KAFKA-15701: Expose the requesting principal to CreateTopicPolicy and AlterConfigPolicy#22594
Open
danoSF wants to merge 1 commit into
Open
KAFKA-15701: Expose the requesting principal to CreateTopicPolicy and AlterConfigPolicy#22594danoSF wants to merge 1 commit into
danoSF wants to merge 1 commit into
Conversation
… AlterConfigPolicy
The CreateTopicPolicy and AlterConfigPolicy plugin interfaces let operators
constrain the *shape* of a request (topic name, partitions, replication factor,
configs) but not *who* issued it. In multi-tenant clusters this prevents a
policy from enforcing per-principal rules that prefixed ACLs cannot express,
e.g. "tenant-a may only create topics with replication.factor <= 3" or
per-principal topic/partition quotas.
This change exposes the authenticated KafkaPrincipal to both policies:
* CreateTopicPolicy.RequestMetadata and AlterConfigPolicy.RequestMetadata
gain an overloaded constructor that accepts a KafkaPrincipal and an
Optional<KafkaPrincipal> principal() accessor. The existing constructors
are retained and delegate with a null principal, so the change is source-
and binary-compatible for existing policy implementations. The principal
is excluded from equals()/hashCode() (it is request-scoped metadata, not
part of the identity of the requested change) and included in toString().
* The KRaft controller populates the principal from
ControllerRequestContext.principal(): ReplicationControlManager passes it
to CreateTopicPolicy, and it is threaded through ConfigurationControlManager
(alongside the existing 'forwarded' parameter) to AlterConfigPolicy for both
the incremental and legacy alter-configs paths. The legacy ZooKeeper path is
intentionally out of scope.
Policies constructed without a principal (including via the legacy
constructors) observe Optional.empty().
NOTE: This is a public-interface change and therefore requires a KIP before it
can be merged upstream. This commit is the implementation/proof-of-concept to
support that discussion; see KAFKA-15701.
Member
|
Thanks for the PR. The CreateTopicPolicy and AlterConfigPolicy classes are part of the public API. To update them we need to approve a Kafka Improvement Proposal (KIP). You can see the process on https://cwiki.apache.org/confluence/display/KAFKA/Kafka+Improvement+Proposals |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The CreateTopicPolicy and AlterConfigPolicy plugin interfaces let operators constrain the shape of a request (topic name, partitions, replication factor, configs) but not who issued it. In multi-tenant clusters this prevents a policy from enforcing per-principal rules that prefixed ACLs cannot express, e.g. "tenant-a may only create topics with replication.factor <= 3" or per-principal topic/partition quotas.
This change exposes the authenticated KafkaPrincipal to both policies:
CreateTopicPolicy.RequestMetadata and AlterConfigPolicy.RequestMetadata gain an overloaded constructor that accepts a KafkaPrincipal and an Optional principal() accessor. The existing constructors are retained and delegate with a null principal, so the change is source- and binary-compatible for existing policy implementations. The principal is excluded from equals()/hashCode() (it is request-scoped metadata, not part of the identity of the requested change) and included in toString().
The KRaft controller populates the principal from ControllerRequestContext.principal(): ReplicationControlManager passes it to CreateTopicPolicy, and it is threaded through ConfigurationControlManager (alongside the existing 'forwarded' parameter) to AlterConfigPolicy for both the incremental and legacy alter-configs paths. The legacy ZooKeeper path is intentionally out of scope.
Policies constructed without a principal (including via the legacy constructors) observe Optional.empty().
Reviewers: Mickael Maison mimaison@apache.org