-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
887 additions
and
42 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Server { | ||
org.apache.zookeeper.server.auth.DigestLoginModule required | ||
user_zkuser="zkuserpassword"; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
version: '2' | ||
services: | ||
|
||
kafka-ui: | ||
container_name: kafka-ui | ||
image: provectuslabs/kafka-ui:latest | ||
ports: | ||
- 8080:8080 | ||
depends_on: | ||
- zookeeper | ||
- kafka | ||
environment: | ||
KAFKA_CLUSTERS_0_NAME: local | ||
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092 | ||
KAFKA_CLUSTERS_0_PROPERTIES_SECURITY_PROTOCOL: SASL_PLAINTEXT | ||
KAFKA_CLUSTERS_0_PROPERTIES_SASL_MECHANISM: PLAIN | ||
KAFKA_CLUSTERS_0_PROPERTIES_SASL_JAAS_CONFIG: 'org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin-secret";' | ||
|
||
zookeeper: | ||
image: wurstmeister/zookeeper:3.4.6 | ||
environment: | ||
JVMFLAGS: "-Djava.security.auth.login.config=/etc/zookeeper/zookeeper_jaas.conf" | ||
volumes: | ||
- ./jaas/zookeeper_jaas.conf:/etc/zookeeper/zookeeper_jaas.conf | ||
ports: | ||
- 2181:2181 | ||
|
||
kafka: | ||
image: confluentinc/cp-kafka:7.2.1 | ||
hostname: kafka | ||
container_name: kafka | ||
ports: | ||
- "9092:9092" | ||
- "9997:9997" | ||
environment: | ||
KAFKA_BROKER_ID: 1 | ||
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181' | ||
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: 'CONTROLLER:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT' | ||
KAFKA_ADVERTISED_LISTENERS: 'SASL_PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092' | ||
KAFKA_OPTS: "-Djava.security.auth.login.config=/etc/kafka/jaas/kafka_server.conf" | ||
KAFKA_AUTHORIZER_CLASS_NAME: "kafka.security.authorizer.AclAuthorizer" | ||
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 | ||
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0 | ||
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 | ||
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 | ||
KAFKA_JMX_PORT: 9997 | ||
KAFKA_JMX_HOSTNAME: localhost | ||
KAFKA_NODE_ID: 1 | ||
KAFKA_CONTROLLER_QUORUM_VOTERS: '1@kafka:29093' | ||
KAFKA_LISTENERS: 'SASL_PLAINTEXT://kafka:29092,CONTROLLER://kafka:29093,PLAINTEXT_HOST://0.0.0.0:9092' | ||
KAFKA_INTER_BROKER_LISTENER_NAME: 'SASL_PLAINTEXT' | ||
KAFKA_SASL_ENABLED_MECHANISMS: 'PLAIN' | ||
KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL: 'PLAIN' | ||
KAFKA_SECURITY_PROTOCOL: 'SASL_PLAINTEXT' | ||
KAFKA_SUPER_USERS: 'User:admin' | ||
volumes: | ||
- ./scripts/update_run.sh:/tmp/update_run.sh | ||
- ./jaas:/etc/kafka/jaas |
115 changes: 115 additions & 0 deletions
115
kafka-ui-api/src/main/java/com/provectus/kafka/ui/controller/AclsController.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 |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package com.provectus.kafka.ui.controller; | ||
|
||
import com.provectus.kafka.ui.api.AclsApi; | ||
import com.provectus.kafka.ui.mapper.ClusterMapper; | ||
import com.provectus.kafka.ui.model.KafkaAclDTO; | ||
import com.provectus.kafka.ui.model.KafkaAclNamePatternTypeDTO; | ||
import com.provectus.kafka.ui.model.KafkaAclResourceTypeDTO; | ||
import com.provectus.kafka.ui.model.rbac.AccessContext; | ||
import com.provectus.kafka.ui.model.rbac.permission.AclAction; | ||
import com.provectus.kafka.ui.service.acl.AclsService; | ||
import com.provectus.kafka.ui.service.rbac.AccessControlService; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.kafka.common.resource.PatternType; | ||
import org.apache.kafka.common.resource.ResourcePatternFilter; | ||
import org.apache.kafka.common.resource.ResourceType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class AclsController extends AbstractController implements AclsApi { | ||
|
||
private final AclsService aclsService; | ||
private final AccessControlService accessControlService; | ||
|
||
@Override | ||
public Mono<ResponseEntity<Void>> createAcl(String clusterName, Mono<KafkaAclDTO> kafkaAclDto, | ||
ServerWebExchange exchange) { | ||
AccessContext context = AccessContext.builder() | ||
.cluster(clusterName) | ||
.aclActions(AclAction.EDIT) | ||
.build(); | ||
|
||
return accessControlService.validateAccess(context) | ||
.then(kafkaAclDto) | ||
.map(ClusterMapper::toAclBinding) | ||
.flatMap(binding -> aclsService.createAcl(getCluster(clusterName), binding)) | ||
.thenReturn(ResponseEntity.ok().build()); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<Void>> deleteAcl(String clusterName, Mono<KafkaAclDTO> kafkaAclDto, | ||
ServerWebExchange exchange) { | ||
AccessContext context = AccessContext.builder() | ||
.cluster(clusterName) | ||
.aclActions(AclAction.EDIT) | ||
.build(); | ||
|
||
return accessControlService.validateAccess(context) | ||
.then(kafkaAclDto) | ||
.map(ClusterMapper::toAclBinding) | ||
.flatMap(binding -> aclsService.deleteAcl(getCluster(clusterName), binding)) | ||
.thenReturn(ResponseEntity.ok().build()); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<Flux<KafkaAclDTO>>> listAcls(String clusterName, | ||
KafkaAclResourceTypeDTO resourceTypeDto, | ||
String resourceName, | ||
KafkaAclNamePatternTypeDTO namePatternTypeDto, | ||
ServerWebExchange exchange) { | ||
AccessContext context = AccessContext.builder() | ||
.cluster(clusterName) | ||
.aclActions(AclAction.VIEW) | ||
.build(); | ||
|
||
var resourceType = Optional.ofNullable(resourceTypeDto) | ||
.map(ClusterMapper::mapAclResourceTypeDto) | ||
.orElse(ResourceType.ANY); | ||
|
||
var namePatternType = Optional.ofNullable(namePatternTypeDto) | ||
.map(ClusterMapper::mapPatternTypeDto) | ||
.orElse(PatternType.ANY); | ||
|
||
var filter = new ResourcePatternFilter(resourceType, resourceName, namePatternType); | ||
|
||
return accessControlService.validateAccess(context).then( | ||
Mono.just( | ||
ResponseEntity.ok( | ||
aclsService.listAcls(getCluster(clusterName), filter) | ||
.map(ClusterMapper::toKafkaAclDto))) | ||
); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<String>> getAclAsCsv(String clusterName, ServerWebExchange exchange) { | ||
AccessContext context = AccessContext.builder() | ||
.cluster(clusterName) | ||
.aclActions(AclAction.VIEW) | ||
.build(); | ||
|
||
return accessControlService.validateAccess(context).then( | ||
aclsService.getAclAsCsvString(getCluster(clusterName)) | ||
.map(ResponseEntity::ok) | ||
.flatMap(Mono::just) | ||
); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<Void>> syncAclsCsv(String clusterName, Mono<String> csvMono, ServerWebExchange exchange) { | ||
AccessContext context = AccessContext.builder() | ||
.cluster(clusterName) | ||
.aclActions(AclAction.EDIT) | ||
.build(); | ||
|
||
return accessControlService.validateAccess(context) | ||
.then(csvMono) | ||
.flatMap(csv -> aclsService.syncAclWithAclCsv(getCluster(clusterName), csv)) | ||
.thenReturn(ResponseEntity.ok().build()); | ||
} | ||
} |
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
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
15 changes: 15 additions & 0 deletions
15
kafka-ui-api/src/main/java/com/provectus/kafka/ui/model/rbac/permission/AclAction.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.provectus.kafka.ui.model.rbac.permission; | ||
|
||
import org.apache.commons.lang3.EnumUtils; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public enum AclAction implements PermissibleAction { | ||
|
||
VIEW, | ||
EDIT; | ||
|
||
@Nullable | ||
public static AclAction fromString(String name) { | ||
return EnumUtils.getEnum(AclAction.class, name); | ||
} | ||
} |
Oops, something went wrong.