|
| 1 | +--- |
| 2 | +apiVersion: v1 |
| 3 | +kind: ConfigMap |
| 4 | +metadata: |
| 5 | + name: test-rego-kafka |
| 6 | + labels: |
| 7 | + opa.stackable.tech/bundle: "true" |
| 8 | +data: |
| 9 | + kafka.rego: | |
| 10 | + package authz |
| 11 | + |
| 12 | + # FQDNs of the brokers as regular expressions |
| 13 | + brokers_fqdn := [ |
| 14 | + `local`, |
| 15 | + `cluster`, |
| 16 | + `svc`, |
| 17 | + `$NAMESPACE`, |
| 18 | + `test-kafka-broker-default-headless`, |
| 19 | + `test-kafka-broker-default-[0-9]+`, |
| 20 | + ] |
| 21 | + |
| 22 | + domain_components = [concat("", [`DC=`, dc]) | some dc in brokers_fqdn] |
| 23 | + common_name = `CN=generated certificate for pod` |
| 24 | + subject_dn_fields = array.concat(domain_components, [common_name]) |
| 25 | + brokers_subject_dn_pattern := concat(",", subject_dn_fields) |
| 26 | + |
| 27 | + default allow := false |
| 28 | + |
| 29 | + allow if { |
| 30 | + is_internal_request |
| 31 | + |
| 32 | + regex.match( |
| 33 | + brokers_subject_dn_pattern, |
| 34 | + input.requestContext.principal.name, |
| 35 | + ) |
| 36 | + } |
| 37 | + |
| 38 | + allow if { |
| 39 | + is_external_request |
| 40 | + input.requestContext.principal.name == "kafka" |
| 41 | + } |
| 42 | + |
| 43 | + allow if { |
| 44 | + is_external_request |
| 45 | + input.requestContext.principal.name == "developer" |
| 46 | + resource_is_allowed |
| 47 | + } |
| 48 | + |
| 49 | + is_internal_request if input.requestContext.listenerName == "INTERNAL" |
| 50 | + is_external_request if not is_internal_request |
| 51 | + |
| 52 | + # only allow access to a specific topic |
| 53 | + resource_is_allowed if { |
| 54 | + input.action.resourcePattern.resourceType == "TOPIC" |
| 55 | + input.action.resourcePattern.name == "test-topic" |
| 56 | + action_is_allowed |
| 57 | + } |
| 58 | + |
| 59 | + resource_is_allowed if { |
| 60 | + input.action.resourcePattern.resourceType == "GROUP" |
| 61 | + input.action.operation in ["DESCRIBE", "READ"] |
| 62 | + } |
| 63 | + |
| 64 | + action_is_allowed if { |
| 65 | + input.action.operation in ["CREATE", "DESCRIBE", "READ", "WRITE"] |
| 66 | + } |
| 67 | +--- |
| 68 | +apiVersion: opa.stackable.tech/v1alpha1 |
| 69 | +kind: OpaCluster |
| 70 | +metadata: |
| 71 | + name: test-opa |
| 72 | +spec: |
| 73 | + image: |
| 74 | +{% if test_scenario['values']['opa-latest'].find(",") > 0 %} |
| 75 | + custom: "{{ test_scenario['values']['opa-latest'].split(',')[1] }}" |
| 76 | + productVersion: "{{ test_scenario['values']['opa-latest'].split(',')[0] }}" |
| 77 | +{% else %} |
| 78 | + productVersion: "{{ test_scenario['values']['opa-latest'] }}" |
| 79 | +{% endif %} |
| 80 | + pullPolicy: IfNotPresent |
| 81 | + clusterConfig: |
| 82 | +{% if test_scenario['values']['use-opa-tls'] == "true" %} |
| 83 | + tls: |
| 84 | + serverSecretClass: opa-tls-$NAMESPACE |
| 85 | +{% endif %} |
| 86 | + vectorAggregatorConfigMapName: vector-aggregator-discovery |
| 87 | + servers: |
| 88 | + config: |
| 89 | + logging: |
| 90 | + enableVectorAgent: true |
| 91 | + containers: |
| 92 | + opa: |
| 93 | + console: |
| 94 | + level: INFO |
| 95 | + file: |
| 96 | + level: INFO |
| 97 | + loggers: |
| 98 | + decision: |
| 99 | + level: INFO |
| 100 | + roleGroups: |
| 101 | + default: {} |
0 commit comments