Skip to content
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

Add the missing TransactionID permission for producers when using rbac #370

Merged
merged 2 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ public List<TopologyAclBinding> buildBindingsForProducers(
TopologyAclBinding binding =
apiClient.bind(producer.getPrincipal(), DEVELOPER_WRITE, resource, patternType);
bindings.add(binding);

if (producer.getTransactionId().isPresent()) {
binding =
apiClient.bind(
producer.getPrincipal(),
DEVELOPER_WRITE,
producer.getTransactionId().get(),
"TransactionalId",
LITERAL);
bindings.add(binding);
}
});
return bindings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.purbon.kafka.topology.ExecutionPlan;
import com.purbon.kafka.topology.TestTopologyBuilder;
import com.purbon.kafka.topology.api.mds.MDSApiClient;
import com.purbon.kafka.topology.api.mds.RbacResourceType;
import com.purbon.kafka.topology.model.Impl.ProjectImpl;
import com.purbon.kafka.topology.model.Impl.TopologyImpl;
import com.purbon.kafka.topology.model.Platform;
Expand Down Expand Up @@ -148,6 +149,32 @@ public void producerAclsCreation() throws IOException {
verifyProducerAcls(producers, topicA.toString());
}

@Test
public void producerAclsWithExtraPropertiesShouldNotBreak() throws IOException {

List<Producer> producers = new ArrayList<>();
var producer = new Producer("User:app3");
producer.setTransactionId(Optional.of("12345"));
producers.add(producer);

Project project = new ProjectImpl("project");
project.setProducers(producers);
Topic topicA = new Topic("topicA");
project.addTopic(topicA);

Topology topology = new TopologyImpl();
topology.setContext("producerAclsWithExtraPropertiesShouldNotBreak-test");
topology.addProject(project);

accessControlManager.apply(topology, plan);
plan.run();

// this method is call twice, once for consumers and one for consumers
verify(cs, times(1)).addBindings(anyList());
verify(cs, times(1)).flushAndClose();
verifyProducerAcls(producers, topicA.toString(), 2);
}

@Test
public void kstreamsAclsCreation() throws IOException {
Project project = new ProjectImpl();
Expand Down Expand Up @@ -513,11 +540,19 @@ private void verifyKSqlAppAcls(KSqlApp app) {
}

private void verifyProducerAcls(List<Producer> producers, String topic) {
verifyProducerAcls(producers, topic, 1);
}

private void verifyProducerAcls(List<Producer> producers, String topic, int resourcesCount) {
producers.forEach(
producer -> {
List<String> roles = apiClient.lookupRoles(producer.getPrincipal());
assertEquals(1, roles.size());
assertTrue(roles.contains(DEVELOPER_WRITE));

List<RbacResourceType> resources =
apiClient.lookupResourcesForKafka(producer.getPrincipal(), DEVELOPER_WRITE);
assertEquals(resourcesCount, resources.size());
});
}

Expand Down