Kafdrop configured for Openshift, with OAuth proxy

Overview

Deploying Kafdrop to Openshift

This repo takes the original Kafdrop and extends it to deploy it on Openshift.

  • Integration with Kafka Clusters managed by the AMQStreams/Strimzi operator, where mtls user authentication has been tutned on.
  • Authentication using the openshift security domain and oauth proxy.
  • Deployment with a Helm template.

Code chages to allow secrets to be extracted from environment vars at deploy time

index cd34f49..f5d1989 100644
--- a/src/main/java/kafdrop/config/KafkaConfiguration.java
+++ b/src/main/java/kafdrop/config/KafkaConfiguration.java
@@ -14,6 +14,11 @@ import org.springframework.stereotype.*;
 @ConfigurationProperties(prefix = "kafka")
 @Data
 public final class KafkaConfiguration {
+  private static final String KAFKA_SSL_TRUSTSTORE_CREDENTIALS_ENV_KEY = "KAFKA_SSL_TRUSTSTORE_CREDENTIALS";
+  private static final String KAFKA_SSL_TRUSTSTORE_CREDENTIALS_PROP_KEY = "ssl.truststore.password";
+  private static final String KAFKA_SSL_KEYSTORE_CREDENTIALS_ENV_KEY = "KAFKA_SSL_KEYSTORE_CREDENTIALS";
+  private static final String KAFKA_SSL_KEYSTORE_CREDENTIALS_PROP_KEY = "ssl.keystore.password";
+
   private static final Logger LOG = LoggerFactory.getLogger(KafkaConfiguration.class);
 
   private String brokerConnect;
@@ -58,6 +63,19 @@ public final class KafkaConfiguration {
         throw new KafkaConfigurationException(e);
       }
       properties.putAll(propertyOverrides);
+
+      String keystorePassword = System.getenv(KAFKA_SSL_KEYSTORE_CREDENTIALS_ENV_KEY);
+      if (!keystorePassword.isEmpty())
+        properties.put(KAFKA_SSL_KEYSTORE_CREDENTIALS_PROP_KEY, keystorePassword);
+      
+        String truststorePassword = System.getenv(KAFKA_SSL_TRUSTSTORE_CREDENTIALS_ENV_KEY);
+        if (!truststorePassword.isEmpty())
+          properties.put(KAFKA_SSL_TRUSTSTORE_CREDENTIALS_PROP_KEY, truststorePassword);
+
+      for (Object key : properties.keySet()) {
+        LOG.debug(key + " : " + properties.get(key));
+      }
+
     }
   }
 }

How-To deploy

  1. build code
    1. mvn clean package
    2. build image
    3. push image to registry
    4. populate Helm chart values file : values.yml
    5. deploy helm template :
cd chart && helm template . | oc apply -f -

logo Kafdrop – Kafka Web UI   Tweet

Price Release with mvn Docker Language grade: Java

Kafdrop is a web UI for viewing Kafka topics and browsing consumer groups. The tool displays information such as brokers, topics, partitions, consumers, and lets you view messages.

Overview Screenshot

This project is a reboot of Kafdrop 2.x, dragged kicking and screaming into the world of JDK 11+, Kafka 2.x, Helm and Kubernetes. It's a lightweight application that runs on Spring Boot and is dead-easy to configure, supporting SASL and TLS-secured brokers.

Features

  • View Kafka brokers — topic and partition assignments, and controller status
  • View topics — partition count, replication status, and custom configuration
  • Browse messages — JSON, plain text, Avro and Protobuf encoding
  • View consumer groups — per-partition parked offsets, combined and per-partition lag
  • Create new topics
  • View ACLs
  • Support for Azure Event Hubs

Requirements

  • Java 11 or newer
  • Kafka (version 0.11.0 or newer) or Azure Event Hubs

Optional, additional integration:

  • Schema Registry

Getting Started

You can run the Kafdrop JAR directly, via Docker, or in Kubernetes.

Running from JAR

java --add-opens=java.base/sun.nio.ch=ALL-UNNAMED \
    -jar target/kafdrop-<version>.jar \
    --kafka.brokerConnect=<host:port,host:port>,...

If unspecified, kafka.brokerConnect defaults to localhost:9092.

Note: As of Kafdrop 3.10.0, a ZooKeeper connection is no longer required. All necessary cluster information is retrieved via the Kafka admin API.

Open a browser and navigate to http://localhost:9000. The port can be overridden by adding the following config:

--server.port=<port> --management.server.port=<port>

Optionally, configure a schema registry connection with:

--schemaregistry.connect=http://localhost:8081

and if you also require basic auth for your schema registry connection you should add:

--schemaregistry.auth=username:password

Finally, a default message format (e.g. to deserialize Avro messages) can optionally be configured as follows:

--message.format=AVRO

Valid format values are DEFAULT, AVRO, PROTOBUF. This can also be configured at the topic level via dropdown when viewing messages.

Configure Protobuf message type

Option 1: Using Protobuf Descriptor

In case of protobuf message type, the definition of a message could be compiled and transmitted using a descriptor file. Thus, in order for kafdrop to recognize the message, the application will need to access to the descriptor file(s). Kafdrop will allow user to select descriptor and well as specifying name of one of the message type provided by the descriptor at runtime.

To configure a folder with protobuf descriptor file(s) (.desc), follow:

--protobufdesc.directory=/var/protobuf_desc

Option 2 : Using Schema Registry

In case of no protobuf descriptor file being supplied the implementation will attempt to create the protobuf deserializer using the schema registry instead.

Defaulting to Protobuf

If preferred the message type could be set to default as follows:

--message.format=PROTOBUF

Running with Docker

Images are hosted at hub.docker.com/r/obsidiandynamics/kafdrop.

Launch container in background:

docker run -d --rm -p 9000:9000 \
    -e KAFKA_BROKERCONNECT=<host:port,host:port> \
    -e JVM_OPTS="-Xms32M -Xmx64M" \
    -e SERVER_SERVLET_CONTEXTPATH="/" \
    obsidiandynamics/kafdrop

Launch container in background with protobuff definitions:

docker run -d --rm -v <path_to_protobuff_descriptor_files>:/var/protobuf_desc -p 9000:9000 \
    -e KAFKA_BROKERCONNECT=<host:port,host:port> \
    -e JVM_OPTS="-Xms32M -Xmx64M" \
    -e SERVER_SERVLET_CONTEXTPATH="/" \
    -e CMD_ARGS="--message.format=PROTOBUF --protobufdesc.directory=/var/protobuf_desc" \
    obsidiandynamics/kafdrop

Then access the web UI at http://localhost:9000.

Hey there! We hope you really like Kafdrop! Please take a moment to the repo or Tweet about it.

Running in Kubernetes (using a Helm Chart)

Clone the repository (if necessary):

git clone https://github.com/obsidiandynamics/kafdrop && cd kafdrop

Apply the chart:

helm upgrade -i kafdrop chart --set image.tag=3.x.x \
    --set kafka.brokerConnect=<host:port,host:port> \
    --set server.servlet.contextPath="/" \
    --set cmdArgs="--message.format=AVRO --schemaregistry.connect=http://localhost:8080" \ #optional
    --set jvm.opts="-Xms32M -Xmx64M"

For all Helm configuration options, have a peek into chart/values.yaml.

Replace 3.x.x with the image tag of obsidiandynamics/kafdrop. Services will be bound on port 9000 by default (node port 30900).

Note: The context path must begin with a slash.

Proxy to the Kubernetes cluster:

kubectl proxy

Navigate to http://localhost:8001/api/v1/namespaces/default/services/http:kafdrop:9000/proxy.

Protobuf support via helm chart:

To install with protobuf support, a "facility" option is provided for the deployment, to mount the descriptor files folder, as well as passing the required CMD arguments, via option mountProtoDesc. Example:

helm upgrade -i kafdrop chart --set image.tag=3.x.x \
    --set kafka.brokerConnect=<host:port,host:port> \
    --set server.servlet.contextPath="/" \
    --set mountProtoDesc.enabled=true \
    --set mountProtoDesc.hostPath="<path/to/desc/folder>" \
    --set jvm.opts="-Xms32M -Xmx64M"

Building

After cloning the repository, building is just a matter of running a standard Maven build:

$ mvn clean package

The following command will generate a Docker image:

mvn assembly:single docker:build

Docker Compose

There is a docker-compose.yaml file that bundles a Kafka/ZooKeeper instance with Kafdrop:

cd docker-compose/kafka-kafdrop
docker-compose up

APIs

JSON endpoints

Starting with version 2.0.0, Kafdrop offers a set of Kafka APIs that mirror the existing HTML views. Any existing endpoint can be returned as JSON by simply setting the Accept: application/json header. Some endpoints are JSON only:

  • /topic: Returns a list of all topics.

Swagger

To help document the Kafka APIs, Swagger has been included. The Swagger output is available by default at the following Kafdrop URL:

/v2/api-docs

This can be overridden with the following configuration:

springfox.documentation.swagger.v2.path=/new/swagger/path

Currently only the JSON endpoints are included in the Swagger output; the HTML views and Spring Boot debug endpoints are excluded.

You can disable Swagger output with the following configuration:

swagger.enabled=false

CORS Headers

Starting in version 2.0.0, Kafdrop sets CORS headers for all endpoints. You can control the CORS header values with the following configurations:

cors.allowOrigins (default is *)
cors.allowMethods (default is GET,POST,PUT,DELETE)
cors.maxAge (default is 3600)
cors.allowCredentials (default is true)
cors.allowHeaders (default is Origin,Accept,X-Requested-With,Content-Type,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization)

You can also disable CORS entirely with the following configuration:

cors.enabled=false

Topic Configuration

By default, you could delete a topic. If you don't want this feature, you could disable it with:

--topic.deleteEnabled=false

By default, you could create a topic. If you don't want this feature, you could disable it with:

--topic.createEnabled=false

Actuator

Health and info endpoints are available at the following path: /actuator

This can be overridden with the following configuration:

management.endpoints.web.base-path=<path>

Guides

Connecting to a Secure Broker

Kafdrop supports TLS (SSL) and SASL connections for encryption and authentication. This can be configured by providing a combination of the following files (placed into the Kafka root directory):

  • kafka.truststore.jks: specifying the certificate for authenticating brokers, if TLS is enabled.
  • kafka.keystore.jks: specifying the private key to authenticate the client to the broker, if mutual TLS authentication is required.
  • kafka.properties: specifying the necessary configuration, including key/truststore passwords, cipher suites, enabled TLS protocol versions, username/password pairs, etc. When supplying the truststore and/or keystore files, the ssl.truststore.location and ssl.keystore.location properties will be assigned automatically.

Using Docker

The three files above can be supplied to a Docker instance in base-64-encoded form via environment variables:

docker run -d --rm -p 9000:9000 \
    -e KAFKA_BROKERCONNECT=<host:port,host:port> \
    -e KAFKA_PROPERTIES="$(cat kafka.properties | base64)" \
    -e KAFKA_TRUSTSTORE="$(cat kafka.truststore.jks | base64)" \   # optional
    -e KAFKA_KEYSTORE="$(cat kafka.keystore.jks | base64)" \       # optional
    obsidiandynamics/kafdrop

Environment Variables

Basic configuration
Name Description
KAFKA_BROKERCONNECT Bootstrap list of Kafka host/port pairs. Defaults to localhost:9092.
KAFKA_PROPERTIES Additional properties to configure the broker connection (base-64 encoded).
KAFKA_TRUSTSTORE Certificate for broker authentication (base-64 encoded). Required for TLS/SSL.
KAFKA_KEYSTORE Private key for mutual TLS authentication (base-64 encoded).
SERVER_SERVLET_CONTEXTPATH The context path to serve requests on (must end with a /). Defaults to /.
SERVER_PORT The web server port to listen on. Defaults to 9000.
SCHEMAREGISTRY_CONNECT The endpoint of Schema Registry for Avro or Protobuf message
SCHEMAREGISTRY_AUTH Optional basic auth credentials in the form username:password.
CMD_ARGS Command line arguments to Kafdrop, e.g. --message.format or --protobufdesc.directory or --server.port.
Advanced configuration
Name Description
JVM_OPTS JVM options.
JMX_PORT Port to use for JMX. No default; if unspecified, JMX will not be exposed.
HOST The hostname to report for the RMI registry (used for JMX). Defaults to localhost.
KAFKA_PROPERTIES_FILE Internal location where the Kafka properties file will be written to (if KAFKA_PROPERTIES is set). Defaults to kafka.properties.
KAFKA_TRUSTSTORE_FILE Internal location where the truststore file will be written to (if KAFKA_TRUSTSTORE is set). Defaults to kafka.truststore.jks.
KAFKA_KEYSTORE_FILE Internal location where the keystore file will be written to (if KAFKA_KEYSTORE is set). Defaults to kafka.keystore.jks.
SSL_ENABLED Enabling HTTPS (SSL) for Kafdrop server. Default is false
SSL_KEY_STORE_TYPE Type of SSL keystore. Default is PKCS12
SSL_KEY_STORE Path to keystore file
SSL_KEY_STORE_PASSWORD Keystore password
SSL_KEY_ALIAS Key alias

Using Helm

Like in the Docker example, supply the files in base-64 form:

helm upgrade -i kafdrop chart --set image.tag=3.x.x \
    --set kafka.brokerConnect=<host:port,host:port> \
    --set kafka.properties="$(cat kafka.properties | base64)" \
    --set kafka.truststore="$(cat kafka.truststore.jks | base64)" \
    --set kafka.keystore="$(cat kafka.keystore.jks | base64)"

Updating the Bootstrap theme

Edit the .scss files in the theme directory, then run theme/install.sh. This will overwrite src/main/resources/static/css/bootstrap.min.css. Then build as usual. (Requires npm.)

Securing the Kafdrop UI

Kafdrop doesn't (yet) natively implement an authentication mechanism to restrict user access. Here's a quick workaround using NGINX using Basic Auth. The instructions below are for macOS and Homebrew.

Requirements

  • NGINX: install using which nginx > /dev/null || brew install nginx
  • Apache HTTP utilities: which htpasswd > /dev/null || brew install httpd

Setup

Set the admin password (you will be prompted):

htpasswd -c /usr/local/etc/nginx/.htpasswd admin

Add a logout page in /usr/local/opt/nginx/html/401.html:

<!DOCTYPE html>
<p>Not authorized. <a href="<!--# echo var="scheme" -->://<!--# echo var="http_host" -->/">Login</a>.</p>

Use the following snippet for /usr/local/etc/nginx/nginx.conf:

worker_processes 4;
  
events {
  worker_connections 1024;
}

http {
  upstream kafdrop {
    server 127.0.0.1:9000;
    keepalive 64;
  }

  server {
    listen *:8080;
    server_name _;
    access_log /usr/local/var/log/nginx/nginx.access.log;
    error_log /usr/local/var/log/nginx/nginx.error.log;
    auth_basic "Restricted Area";
    auth_basic_user_file /usr/local/etc/nginx/.htpasswd;

    location / {
      proxy_pass http://kafdrop;
    }

    location /logout {
      return 401;
    }

    error_page 401 /errors/401.html;

    location /errors {
      auth_basic off;
      ssi        on;
      alias /usr/local/opt/nginx/html;
    }
  }
}

Run NGINX:

nginx

Or reload its configuration if already running:

nginx -s reload

To logout, browse to /logout.

Hey there! We hope you really like Kafdrop! Please take a moment to the repo or Tweet about it.

Contributing Guidelines

All contributions are more than welcomed. Contributions may close an issue, fix a bug (reported or not reported), add new design blocks, improve the existing code, add new feature, and so on. In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone.

Release workflow

To cut an official release, these are the steps:

  1. Commit a new version on master that has the -SNAPSHOT suffix stripped (see pom.xml). Once the commit is merged, the CI will treat it as a release build, and will end up publishing more artifacts than the regular (non-release/snapshot) build. One of those will be a dockerhub push to the specific version and "latest" tags. (The regular build doesn't update "latest").

  2. You can then edit the release description in GitHub to describe what went into the release.

  3. After the release goes through successfully, you need to prepare the repo for the next version, which requires committing the next snapshot version on master again. So we should increment the minor version and add again the -SNAPSHOT suffix.

You might also like...

a proxy for http & https ,write by java,no dependences for other tech

申明 本项目只是作者记录和分享Java网络编程学习心得,请勿用于非法用途,否则后果自负! 原理介绍博客: https://blog.csdn.net/wang382758656/article/details/123098032 https://juejin.cn/post/706921880022

May 3, 2022

🚀 A Motd Virtualization with Minecraft Proxy.

ProxyVirtualMotd プレイヤー別に 仮想 Motd を表示するプラグインです For Minecraft Proxy (BungeeCord / Waterfall) Plugin Waterfall 1.18 v483 動作確認済み Features 実装済みの機能です (今後、新機

Sep 21, 2022

Make the Velocity proxy run commands based on backend input.

Command Sync Server This plugin allows the Velocity proxy to run commands based on backend input. Purpose The purpose of this is to allow easy access

May 23, 2022

A generic proxy server for applying access-control policies for a FHIR-store.

A generic proxy server for applying access-control policies for a FHIR-store.

FHIR Access Proxy This is a simple access-control proxy that sits in front of a FHIR store (e.g., a HAPI FHIR server, GCP FHIR store, etc.) and contro

Jan 5, 2023

This is a Velocity plugin that makes it possible to host a modern forge server behind a Velocity proxy!

Ambassador This is a Velocity plugin that makes it possible to host a modern forge server behind a Velocity proxy! Unlike other solutions, this plugin

Dec 28, 2022

UniFi Proxy makes it possible to integrate third-party hardware into UniFi Protect

UniFi Proxy makes it possible to integrate third-party hardware into UniFi Protect

UniFi Proxy UniFi Proxy makes it possible to integrate third-party hardware into UniFi Protect. For testing purposes only, it is recommended to purcha

Dec 27, 2022

Conformance test suite for OpenShift

Origin Kubernetes This repo was previously the core Kubernetes tracking repo for OKD, and where OpenShift's hyperkube and openshift-test binaries were

Jan 4, 2023

A Velocity proxy plugin for Minecraft server discovery in k8s. All discovered servers are automatically added to the Velocity proxy.

kryo-server-discovery This plugin connects minecraft servers to a velocity proxy within Kubernetes. The service account in the namespace which the pro

Sep 13, 2022

Winfoom is an HTTP(s) proxy server facade that allows applications to authenticate through the proxy without having to deal with the actual handshake.

Winfoom is an HTTP(s) proxy server facade that allows applications to authenticate  through the proxy without having to deal with the actual handshake.

winfoom Basic Proxy Facade for NTLM, Kerberos, SOCKS and Proxy Auto Config file proxies To help this project please give it a star ⭐ Overview Winfoom

Dec 8, 2022

Security engine for Java (authentication, authorization, multi frameworks): OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...

Security engine for Java (authentication, authorization, multi frameworks): OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...

pac4j is an easy and powerful security engine for Java to authenticate users, get their profiles and manage authorizations in order to secure web appl

Dec 30, 2022

基于 Spring Security OAuth 的统一账号管理平台

基于 Spring Security OAuth 的统一账号管理平台

基于 Spring Security OAuth 的统一账号管理平台 前后端演示地址: https://tao.flizi.cn 支持密码模式演示 输入账号 123456, 密码: 123456, 以及验证码后点击登录 支持授权登录演示 输入手机号 123456, 密码: 123456, 以及验证码

Nov 9, 2022

Spring Boot OAuth 2.0 Client Implementation + MySQL Integration

Spring Boot OAuth 2.0 Client Implementation + MySQL Integration

Spring Boot OAuth 2.0 Client + MySQL 1. What is OAuth 2.0 ? The OAuth 2.0 authorization framework enables a third-party application to obtain limited

May 12, 2022

Bridging IOTA's self-sovereign identities to existing "Web 2.0" OAuth solutions

Bridging IOTA's self-sovereign identities to existing

IOTA Identity Provider Bridging IOTA's self-sovereign identities to existing "Web 2.0" OAuth solutions. NOTE: This plugin has NOT been audited or test

Nov 7, 2022

Zero-Dependency RFC 8252 OAuth 2.0 Authorization Flow

Tiny OAuth2 Client This is a minimal zero-dependency implementation of the RFC 8252 OAuth 2.0 for Native Apps, relying on Loopback Interface Redirecti

Jun 17, 2022

The in-game login system for Grasscutter is based on oauth and GCAuth.

GCAuth OAuth The in-game login system for Grasscutter is based on oauth and GCAuth. Current Features: Use Twitter oauth to login Custom pages Importan

Nov 14, 2022

The in-game login system for Grasscutter is based on oauth and GCAuth.

GCAuth OAuth The in-game login system for Grasscutter is based on oauth and GCAuth. Current Features: Use Twitter oauth to login Custom pages Importan

Aug 3, 2022

A fast, light and cloud native OAuth 2.0 authorization microservices based on light-4j

A fast, light weight and cloud native OAuth 2.0 Server based on microservices architecture built on top of light-4j and light-rest-4j frameworks. Stac

Dec 17, 2022

cglib - Byte Code Generation Library is high level API to generate and transform Java byte code. It is used by AOP, testing, data access frameworks to generate dynamic proxy objects and intercept field access.

cglib Byte Code Generation Library is high level API to generate and transform JAVA byte code. It is used by AOP, testing, data access frameworks to g

Jan 8, 2023
Owner
Justin Davis
Architecting the cloud and modern applications that use it.
Justin Davis
A Velocity proxy plugin for Minecraft server discovery in k8s. All discovered servers are automatically added to the Velocity proxy.

kryo-server-discovery This plugin connects minecraft servers to a velocity proxy within Kubernetes. The service account in the namespace which the pro

Kryonite 9 Sep 13, 2022
Winfoom is an HTTP(s) proxy server facade that allows applications to authenticate through the proxy without having to deal with the actual handshake.

winfoom Basic Proxy Facade for NTLM, Kerberos, SOCKS and Proxy Auto Config file proxies To help this project please give it a star ⭐ Overview Winfoom

Eugen Covaci 56 Dec 8, 2022
基于 Spring Security OAuth 的统一账号管理平台

基于 Spring Security OAuth 的统一账号管理平台 前后端演示地址: https://tao.flizi.cn 支持密码模式演示 输入账号 123456, 密码: 123456, 以及验证码后点击登录 支持授权登录演示 输入手机号 123456, 密码: 123456, 以及验证码

知一 132 Nov 9, 2022
Spring Boot OAuth 2.0 Client Implementation + MySQL Integration

Spring Boot OAuth 2.0 Client + MySQL 1. What is OAuth 2.0 ? The OAuth 2.0 authorization framework enables a third-party application to obtain limited

Salah Eddine Zemmouri 8 May 12, 2022
Zero-Dependency RFC 8252 OAuth 2.0 Authorization Flow

Tiny OAuth2 Client This is a minimal zero-dependency implementation of the RFC 8252 OAuth 2.0 for Native Apps, relying on Loopback Interface Redirecti

Coffee Libs ☕️ 4 Jun 17, 2022
The in-game login system for Grasscutter is based on oauth and GCAuth.

GCAuth OAuth The in-game login system for Grasscutter is based on oauth and GCAuth. Current Features: Use Twitter oauth to login Custom pages Importan

Xtao-Team 36 Nov 14, 2022
The in-game login system for Grasscutter is based on oauth and GCAuth.

GCAuth OAuth The in-game login system for Grasscutter is based on oauth and GCAuth. Current Features: Use Twitter oauth to login Custom pages Importan

Xtao-Labs 29 Aug 3, 2022
A fast, light and cloud native OAuth 2.0 authorization microservices based on light-4j

A fast, light weight and cloud native OAuth 2.0 Server based on microservices architecture built on top of light-4j and light-rest-4j frameworks. Stac

null 291 Dec 17, 2022
Generate a dynamic PAC script that will route traffic to your Burp proxy only if it matches the scope defined in your Burp target.

Burp PAC Server This Burp Extension generates a dynamic Proxy Auto-Configuration (PAC) script that will route traffic to your Burp proxy only if it ma

null 30 Jun 13, 2022
LimboAuth - Minecraft Auth System for Velocity proxy built in virtual server (Limbo).

LimboAuth Auth System built in virtual server (Limbo). MC-Market SpigotMC.org Описание и обсуждение на русском языке (spigotmc.ru) Описание и обсужден

Elytrium 89 Jan 4, 2023