All Projects → anderseknert → opa-kafka-plugin

anderseknert / opa-kafka-plugin

Licence: Apache-2.0 license
Open Policy Agent (OPA) plug-in for Kafka authorization

Programming Languages

scala
5932 projects
Open Policy Agent
39 projects
shell
77523 projects

Projects that are alternatives of or similar to opa-kafka-plugin

k8s-opa-boilerplate
Boilerplate example of managing OPA with kustomize
Stars: ✭ 14 (-69.57%)
Mutual labels:  opa, open-policy-agent, rego
pre-commit-opa
Pre-commit git hooks for Open Policy Agent (OPA) and Rego development
Stars: ✭ 53 (+15.22%)
Mutual labels:  opa, openpolicyagent, rego
opa-spring-security
Open Policy Agent for Spring Security
Stars: ✭ 19 (-58.7%)
Mutual labels:  authorization, opa, openpolicyagent
Conftest
Write tests against structured configuration data using the Open Policy Agent Rego query language
Stars: ✭ 2,047 (+4350%)
Mutual labels:  open-policy-agent, openpolicyagent, rego
awesome-opa
A curated list of OPA related tools, frameworks and articles
Stars: ✭ 316 (+586.96%)
Mutual labels:  opa, open-policy-agent, openpolicyagent
opal
Policy and data administration, distribution, and real-time updates on top of Open Policy Agent
Stars: ✭ 459 (+897.83%)
Mutual labels:  authorization, opa, open-policy-agent
Opa
An open source, general-purpose policy engine.
Stars: ✭ 5,939 (+12810.87%)
Mutual labels:  authorization, opa, open-policy-agent
opa-java-client
No description or website provided.
Stars: ✭ 25 (-45.65%)
Mutual labels:  opa, openpolicyagent
postee
Simple message routing system that receives input messages through a webhook interface and can enforce actions using predefined outputs via integrations.
Stars: ✭ 160 (+247.83%)
Mutual labels:  opa, rego
dotnet-opa-wasm
Call Open Policy Agent (OPA) policies in WASM (Web Assembly) from .NET Core
Stars: ✭ 36 (-21.74%)
Mutual labels:  opa, open-policy-agent
ccheck
A command line tool for validating Kubernetes configs with rego
Stars: ✭ 63 (+36.96%)
Mutual labels:  opa, rego
prancer-compliance-test
This repository includes cloud security policies for IaC and live resources.
Stars: ✭ 32 (-30.43%)
Mutual labels:  opa, rego
OPA-python-client
Python client for Open Policy Agent
Stars: ✭ 24 (-47.83%)
Mutual labels:  opa, open-policy-agent
container-image-sign-and-verify-with-cosign-and-opa
This is just a proof-of-concept project that aims to sign and verify container images using cosign and OPA (Open Policy Agent)
Stars: ✭ 54 (+17.39%)
Mutual labels:  opa, open-policy-agent
opa-docker-authz
A policy-enabled authorization plugin for Docker.
Stars: ✭ 67 (+45.65%)
Mutual labels:  authorization, opa
opa-java-spring-client
Simple Spring client for working with the Open Policy Agent
Stars: ✭ 19 (-58.7%)
Mutual labels:  authorization, opa
token-cli
Command line utility for interacting with OAuth2 infrastructure to generate tokens
Stars: ✭ 19 (-58.7%)
Mutual labels:  authorization
Sphinx
Authorization library for Phoenix web framework
Stars: ✭ 19 (-58.7%)
Mutual labels:  authorization
spicedb
Open Source, Google Zanzibar-inspired fine-grained permissions database
Stars: ✭ 3,358 (+7200%)
Mutual labels:  authorization
ts-ucan
Auth tokens for a distributed, user-controlled world
Stars: ✭ 66 (+43.48%)
Mutual labels:  authorization

Open Policy Agent plugin for Kafka authorization

Maven Central codecov

Open Policy Agent (OPA) plugin for Kafka authorization.

Prerequisites

  • Kafka 2.7.0+
  • Java 11 or above
  • OPA installed and running on the brokers

Installation

Download the latest OPA authorizer plugin jar from Releases (or Maven Central) and put the file (opa-authorizer-{$VERSION}.jar) somewhere Kafka recognizes it - this could be directly in Kafka's libs directory or in a separate plugin directory pointed out to Kafka at startup, e.g:

CLASSPATH=/usr/local/share/kafka/plugins/*

To activate the opa-kafka-plugin add the authorizer.class.name to server.properties
authorizer.class.name=org.openpolicyagent.kafka.OpaAuthorizer


The plugin supports the following properties:
Property Key Example Default Description
opa.authorizer.url http://opa:8181/v1/data/kafka/authz/allow Name of the OPA policy to query. [required]
opa.authorizer.allow.on.error false false Fail-closed or fail-open if OPA call fails.
opa.authorizer.cache.initial.capacity 5000 5000 Initial decision cache size.
opa.authorizer.cache.maximum.size 50000 50000 Max decision cache size.
opa.authorizer.cache.expire.after.seconds 3600 3600 Decision cache expiry in seconds.
opa.authorizer.metrics.enabled true false Whether or not expose JMX metrics for monitoring.
super.users User:alice;User:bob Super users which are always allowed.
opa.authorizer.truststore.path /path/to/mytruststore.p12 Path to the PKCS12 truststore for HTTPS requests to OPA.
opa.authorizer.truststore.password ichangedit changeit Password for the truststore.
opa.authorizer.truststore.type PKCS12, JKS or whatever your JVM supports PKCS12 Type of the truststore.

Usage

Example structure of input data provided from opa-kafka-plugin to Open Policy Agent.

{
    "action": {
        "logIfAllowed": true,
        "logIfDenied": true,
        "operation": "DESCRIBE",
        "resourcePattern": {
            "name": "alice-topic",
            "patternType": "LITERAL",
            "resourceType": "TOPIC",
            "unknown": false
        },
        "resourceReferenceCount": 1
    },
    "requestContext": {
        "clientAddress": "192.168.64.1",
        "clientInformation": {
            "softwareName": "unknown",
            "softwareVersion": "unknown"
        },
        "connectionId": "192.168.64.4:9092-192.168.64.1:58864-0",
        "header": {
            "data": {
                "clientId": "rdkafka",
                "correlationId": 5,
                "requestApiKey": 3,
                "requestApiVersion": 2
            },
            "headerVersion": 1
        },
        "listenerName": "SASL_PLAINTEXT",
        "principal": {
            "name": "alice-consumer",
            "principalType": "User"
        },
        "securityProtocol": "SASL_PLAINTEXT"
    }
}

The following table summarizes the supported resource types and operation names.

input.action.resourcePattern.resourceType input.action.operation
CLUSTER CLUSTER_ACTION
CLUSTER CREATE
CLUSTER DESCRIBE
GROUP READ
GROUP DESCRIPTION
TOPIC CREATE
TOPIC ALTER
TOPIC DELETE
TOPIC DESCRIBE
TOPIC READ
TOPIC WRITE
TRANSACTIONAL_ID DESCRIBE
TRANSACTIONAL_ID WRITE

These are handled by the method authorizeAction, and passed to OPA with an action, that identifies the accessed resource and the performed operation. patternType is always LITERAL.

Creation of a topic checks for CLUSTER + CREATE. If this is denied, it will check for TOPIC with its name + CREATE.

When doing idepotent write to a topic, and the first request for operation=IDEMPOTENT_WRITE on the resourceType=CLUSTER is denied, the method authorizeByResourceType to check, if the user has the right to write to any topic. If yes, the idempotent write is granted by Kafka's ACL-implementation. To allow for a similar check, it is mapped to OPA with patternType=PREFIXED, resourceType=TOPIC, and name="".

{
  "action": {
    "logIfAllowed": true,
    "logIfDenied": true,
    "operation": "DESCRIBE",
    "resourcePattern": {
      "name": "",
      "patternType": "PREFIXED",
      "resourceType": "TOPIC",
      "unknown": false
    },
    "resourceReferenceCount": 1
  },
  ...
}

It's likely possible to use all different resource types and operations described in the Kafka API docs: https://kafka.apache.org/24/javadoc/org/apache/kafka/common/acl/AclOperation.html https://kafka.apache.org/24/javadoc/org/apache/kafka/common/resource/ResourceType.html

Security protocols:

Protocol Description
PLAINTEXT Un-authenticated, non-encrypted channel
SASL_PLAINTEXT authenticated, non-encrypted channel
SASL authenticated, SSL channel
SSL SSL channel

More info:

https://kafka.apache.org/24/javadoc/org/apache/kafka/common/security/auth/SecurityProtocol.html

Policy sample

With the sample policy rego you will out of the box get a structure where an "owner" can one user per type (consumer, producer, mgmt). The owner and user type is separated by -.

  • Username structure: <owner>-<type>
  • Topic name structure: <owner->.*


Example:
User alice-consumer will be...

  • allowed to consume on topic alice-topic1
  • allowed to consume on topic alice-topic-test
  • denied to produce on any topic
  • denied to consume on topic bob-topic

See sample rego

Build from source

Using gradle wrapper: ./gradlew clean test shadowJar

The resulting jar (with dependencies embedded) will be named opa-authorizer-{$VERSION}-all.jar and stored in build/libs.

Logging

Set log level log4j.logger.org.openpolicyagent=INFO in config/log4j.properties Use DEBUG or TRACE for debugging.

In a busy Kafka cluster it might be good to tweak the cache since it may produce a lot of log entries in Open Policy Agent, especially if decision logs are turned on. If the policy isn't dynamically updated very often it's recommended to cache a lot to improve performance and reduce the amount of log entries.

Monitoring

The plugin exposes some metrics that can be useful in operation.

  • opa.authorizer:type=authorization-result
    • authorized-request-count: number of allowed requests
    • unauthorized-request-count: number of denied requests
  • opa.authorizer:type=request-handle
    • request-to-opa-count: number of HTTP request sent to OPA to get authorization result
    • cache-hit-rate: Cache hit rate. Cache miss rate should be 1 - cache-hit-rate
    • cache-usage-percentage: the ratio of cache size over maximum cache capacity
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].