Skip to content

Commit 3dc4446

Browse files
authored
added env variable filtering.groovy.enabled which allows to enable/disable groovy script executions (#4426)
1 parent 53a6553 commit 3dc4446

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

kafka-ui-api/src/main/java/com/provectus/kafka/ui/controller/MessagesController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
import com.provectus.kafka.ui.model.rbac.permission.TopicAction;
2525
import com.provectus.kafka.ui.service.DeserializationService;
2626
import com.provectus.kafka.ui.service.MessagesService;
27+
import com.provectus.kafka.ui.util.DynamicConfigOperations;
2728
import java.util.List;
2829
import java.util.Map;
2930
import java.util.Optional;
3031
import javax.annotation.Nullable;
3132
import javax.validation.Valid;
3233
import lombok.RequiredArgsConstructor;
3334
import lombok.extern.slf4j.Slf4j;
35+
import org.apache.commons.lang3.StringUtils;
3436
import org.apache.commons.lang3.tuple.Pair;
3537
import org.apache.kafka.common.TopicPartition;
3638
import org.springframework.http.ResponseEntity;
@@ -47,6 +49,7 @@ public class MessagesController extends AbstractController implements MessagesAp
4749

4850
private final MessagesService messagesService;
4951
private final DeserializationService deserializationService;
52+
private final DynamicConfigOperations dynamicConfigOperations;
5053

5154
@Override
5255
public Mono<ResponseEntity<Void>> deleteTopicMessages(
@@ -94,6 +97,10 @@ public Mono<ResponseEntity<Flux<TopicMessageEventDTO>>> getTopicMessages(String
9497
.topicActions(MESSAGES_READ)
9598
.operationName("getTopicMessages");
9699

100+
if (StringUtils.isNoneEmpty(q) && MessageFilterTypeDTO.GROOVY_SCRIPT == filterQueryType) {
101+
dynamicConfigOperations.checkIfFilteringGroovyEnabled();
102+
}
103+
97104
if (auditService.isAuditTopic(getCluster(clusterName), topicName)) {
98105
contextBuilder.auditActions(AuditAction.VIEW);
99106
}

kafka-ui-api/src/main/java/com/provectus/kafka/ui/util/DynamicConfigOperations.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
public class DynamicConfigOperations {
4646

4747
static final String DYNAMIC_CONFIG_ENABLED_ENV_PROPERTY = "dynamic.config.enabled";
48+
static final String FILTERING_GROOVY_ENABLED_PROPERTY = "filtering.groovy.enabled";
4849
static final String DYNAMIC_CONFIG_PATH_ENV_PROPERTY = "dynamic.config.path";
4950
static final String DYNAMIC_CONFIG_PATH_ENV_PROPERTY_DEFAULT = "/etc/kafkaui/dynamic_config.yaml";
5051

@@ -64,6 +65,10 @@ public boolean dynamicConfigEnabled() {
6465
return "true".equalsIgnoreCase(ctx.getEnvironment().getProperty(DYNAMIC_CONFIG_ENABLED_ENV_PROPERTY));
6566
}
6667

68+
public boolean filteringGroovyEnabled() {
69+
return "true".equalsIgnoreCase(ctx.getEnvironment().getProperty(FILTERING_GROOVY_ENABLED_PROPERTY));
70+
}
71+
6772
private Path dynamicConfigFilePath() {
6873
return Paths.get(
6974
Optional.ofNullable(ctx.getEnvironment().getProperty(DYNAMIC_CONFIG_PATH_ENV_PROPERTY))
@@ -147,6 +152,14 @@ public Mono<Path> uploadConfigRelatedFile(FilePart file) {
147152
.onErrorMap(th -> new FileUploadException(targetFilePath, th));
148153
}
149154

155+
public void checkIfFilteringGroovyEnabled() {
156+
if (!filteringGroovyEnabled()) {
157+
throw new ValidationException(
158+
"Groovy filters is not allowed. "
159+
+ "Set filtering.groovy.enabled property to 'true' to enabled it.");
160+
}
161+
}
162+
150163
private void checkIfDynamicConfigEnabled() {
151164
if (!dynamicConfigEnabled()) {
152165
throw new ValidationException(

0 commit comments

Comments
 (0)