-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: add a consumer group role configuration #529
Open
ludovic-boutros
wants to merge
1
commit into
kafka-ops:master
Choose a base branch
from
ludovic-boutros:feat/support-consumer-group-role-configuration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
136 changes: 67 additions & 69 deletions
136
src/main/java/com/purbon/kafka/topology/roles/ResourceFilter.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,80 @@ | ||
package com.purbon.kafka.topology.roles; | ||
|
||
import com.purbon.kafka.topology.AccessControlManager; | ||
import com.purbon.kafka.topology.Configuration; | ||
import java.util.List; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.List; | ||
|
||
public class ResourceFilter { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(ResourceFilter.class); | ||
|
||
private final List<String> managedServiceAccountPrefixes; | ||
private final List<String> managedTopicPrefixes; | ||
private final List<String> managedGroupPrefixes; | ||
|
||
public ResourceFilter(Configuration config) { | ||
this.managedServiceAccountPrefixes = config.getServiceAccountManagedPrefixes(); | ||
this.managedTopicPrefixes = config.getTopicManagedPrefixes(); | ||
this.managedGroupPrefixes = config.getGroupManagedPrefixes(); | ||
private static final Logger LOGGER = LogManager.getLogger(ResourceFilter.class); | ||
|
||
private final List<String> managedServiceAccountPrefixes; | ||
private final List<String> managedTopicPrefixes; | ||
private final List<String> managedGroupPrefixes; | ||
|
||
public ResourceFilter(Configuration config) { | ||
this.managedServiceAccountPrefixes = config.getServiceAccountManagedPrefixes(); | ||
this.managedTopicPrefixes = config.getTopicManagedPrefixes(); | ||
this.managedGroupPrefixes = config.getGroupManagedPrefixes(); | ||
} | ||
|
||
public boolean matchesManagedPrefixList(TopologyAclBinding topologyAclBinding) { | ||
String resourceName = topologyAclBinding.getResourceName(); | ||
String principle = topologyAclBinding.getPrincipal(); | ||
// For global wild cards ACL's we manage only if we manage the service account/principle, | ||
// regardless. Filtering by service account will always take precedence if defined | ||
if (haveServiceAccountPrefixFilters() || resourceName.equals("*")) { | ||
if (resourceName.equals("*")) { | ||
return matchesServiceAccountPrefixList(principle); | ||
} else { | ||
return matchesServiceAccountPrefixList(principle) | ||
&& matchesTopicOrGroupPrefix(topologyAclBinding, resourceName); | ||
} | ||
} else if (haveTopicNamePrefixFilter() || haveGroupNamePrefixFilter()) { | ||
return matchesTopicOrGroupPrefix(topologyAclBinding, resourceName); | ||
} | ||
|
||
public boolean matchesManagedPrefixList(TopologyAclBinding topologyAclBinding) { | ||
String resourceName = topologyAclBinding.getResourceName(); | ||
String principle = topologyAclBinding.getPrincipal(); | ||
// For global wild cards ACL's we manage only if we manage the service account/principle, | ||
// regardless. Filtering by service account will always take precedence if defined | ||
if (haveServiceAccountPrefixFilters() || resourceName.equals("*")) { | ||
if (resourceName.equals("*")) { | ||
return matchesServiceAccountPrefixList(principle); | ||
} else { | ||
return matchesServiceAccountPrefixList(principle) | ||
&& matchesTopicOrGroupPrefix(topologyAclBinding, resourceName); | ||
} | ||
} else if (haveTopicNamePrefixFilter() || haveGroupNamePrefixFilter()) { | ||
return matchesTopicOrGroupPrefix(topologyAclBinding, resourceName); | ||
} | ||
|
||
return true; // should include everything if not properly excluded earlier. | ||
} | ||
|
||
private boolean matchesTopicOrGroupPrefix( | ||
TopologyAclBinding topologyAclBinding, String resourceName) { | ||
if ("TOPIC".equalsIgnoreCase(topologyAclBinding.getResourceType())) { | ||
return matchesTopicPrefixList(resourceName); | ||
} else if ("GROUP".equalsIgnoreCase(topologyAclBinding.getResourceType())) { | ||
return matchesGroupPrefixList(resourceName); | ||
} | ||
return false; | ||
} | ||
|
||
private boolean matchesTopicPrefixList(String topic) { | ||
return matchesPrefix(managedTopicPrefixes, topic, "Topic"); | ||
} | ||
|
||
private boolean matchesGroupPrefixList(String group) { | ||
return matchesPrefix(managedGroupPrefixes, group, "Group"); | ||
} | ||
|
||
private boolean matchesServiceAccountPrefixList(String principal) { | ||
return matchesPrefix(managedServiceAccountPrefixes, principal, "Principal"); | ||
} | ||
|
||
private boolean haveServiceAccountPrefixFilters() { | ||
return managedServiceAccountPrefixes.size() != 0; | ||
} | ||
|
||
private boolean haveTopicNamePrefixFilter() { | ||
return managedTopicPrefixes.size() != 0; | ||
} | ||
|
||
private boolean haveGroupNamePrefixFilter() { | ||
return managedGroupPrefixes.size() != 0; | ||
} | ||
return true; // should include everything if not properly excluded earlier. | ||
} | ||
|
||
private boolean matchesPrefix(List<String> prefixes, String item, String type) { | ||
boolean matches = prefixes.size() == 0 || prefixes.stream().anyMatch(item::startsWith); | ||
LOGGER.debug(String.format("%s %s matches %s with $s", type, item, matches, prefixes)); | ||
return matches; | ||
private boolean matchesTopicOrGroupPrefix( | ||
TopologyAclBinding topologyAclBinding, String resourceName) { | ||
if ("TOPIC".equalsIgnoreCase(topologyAclBinding.getResourceType())) { | ||
return matchesTopicPrefixList(resourceName); | ||
} else if ("GROUP".equalsIgnoreCase(topologyAclBinding.getResourceType())) { | ||
return matchesGroupPrefixList(resourceName); | ||
} | ||
return false; | ||
} | ||
|
||
private boolean matchesTopicPrefixList(String topic) { | ||
return matchesPrefix(managedTopicPrefixes, topic, "Topic"); | ||
} | ||
|
||
private boolean matchesGroupPrefixList(String group) { | ||
return matchesPrefix(managedGroupPrefixes, group, "Group"); | ||
} | ||
|
||
private boolean matchesServiceAccountPrefixList(String principal) { | ||
return matchesPrefix(managedServiceAccountPrefixes, principal, "Principal"); | ||
} | ||
|
||
private boolean haveServiceAccountPrefixFilters() { | ||
return managedServiceAccountPrefixes.size() != 0; | ||
} | ||
|
||
private boolean haveTopicNamePrefixFilter() { | ||
return managedTopicPrefixes.size() != 0; | ||
} | ||
|
||
private boolean haveGroupNamePrefixFilter() { | ||
return managedGroupPrefixes.size() != 0; | ||
} | ||
|
||
private boolean matchesPrefix(List<String> prefixes, String item, String type) { | ||
boolean matches = prefixes.size() == 0 || prefixes.stream().anyMatch(item::startsWith); | ||
LOGGER.debug(String.format("%s %s matches %s with $s", type, item, matches, prefixes)); | ||
return matches; | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This model is used for both RBAC and ACLs permissions and might be even used later on for other integrations (I know some people who tried to do it with Ranger, for example).
I think we should not be using here:
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I will try to see how to deal with this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we add a level called "rbac" in the configuration of a consumer, would it be okay for you ?
We should do the same in the schema configuration I guess, even if currently, ACLs are only available with RBAC for schemas.
WDYT ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@purbon kind reminder on the proposal :)