|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +VECTOR_KAFKA_USER="${VECTOR_KAFKA_USER}" |
| 5 | +VECTOR_KAFKA_PASSWORD="${VECTOR_KAFKA_PASSWORD}" |
| 6 | +REDPANDA_USER="${REDPANDA_USER}" |
| 7 | +REDPANDA_PASSWORD="${REDPANDA_PASSWORD}" |
| 8 | + |
| 9 | +echo "Setting up Redpanda SASL users and ACLs..." |
| 10 | + |
| 11 | +echo "Step 1: Creating admin superuser (without SASL)..." |
| 12 | +OUTPUT=$(rpk security user create "${REDPANDA_USER}" -p "${REDPANDA_PASSWORD}" --mechanism SCRAM-SHA-256 2>&1 || true) |
| 13 | +if echo "${OUTPUT}" | grep -q "already exists"; then |
| 14 | + echo "Admin user already exists, skipping..." |
| 15 | +elif echo "${OUTPUT}" | grep -q "Created user"; then |
| 16 | + echo "Admin user created successfully" |
| 17 | +else |
| 18 | + echo "Warning: Failed to create admin user" |
| 19 | + echo "${OUTPUT}" |
| 20 | +fi |
| 21 | + |
| 22 | +echo "Step 2: Setting admin as superuser..." |
| 23 | +OUTPUT=$(rpk cluster config set superusers "[\"${REDPANDA_USER}\"]" 2>&1 || true) |
| 24 | +if echo "${OUTPUT}" | grep -q "Set\|Successfully"; then |
| 25 | + echo "Admin set as superuser successfully" |
| 26 | +elif echo "${OUTPUT}" | grep -q "already"; then |
| 27 | + echo "Admin is already configured as superuser" |
| 28 | +else |
| 29 | + echo "Warning: Failed to set superuser" |
| 30 | + echo "${OUTPUT}" |
| 31 | +fi |
| 32 | + |
| 33 | +echo "Step 3: Ensuring enterprise features are disabled (before enabling SASL)..." |
| 34 | +# Disable audit logging (enterprise feature) |
| 35 | +OUTPUT=$(rpk cluster config set audit_enabled false 2>&1 || true) |
| 36 | +if echo "${OUTPUT}" | grep -q "Set\|already\|Successfully"; then |
| 37 | + echo "Audit logging disabled" |
| 38 | +fi |
| 39 | + |
| 40 | +# Disable continuous data balancing (enterprise feature) |
| 41 | +OUTPUT=$(rpk cluster config set partition_autobalancing_mode node_add 2>&1 || true) |
| 42 | +if echo "${OUTPUT}" | grep -q "Set\|already\|Successfully"; then |
| 43 | + echo "Continuous data balancing disabled" |
| 44 | +fi |
| 45 | + |
| 46 | +# Disable continuous intra-broker partition balancing (enterprise feature) |
| 47 | +OUTPUT=$(rpk cluster config set core_balancing_continuous false 2>&1 || true) |
| 48 | +if echo "${OUTPUT}" | grep -q "Set\|already\|Successfully"; then |
| 49 | + echo "Continuous intra-broker balancing disabled" |
| 50 | +fi |
| 51 | + |
| 52 | +# Disable tiered storage (enterprise feature) |
| 53 | +OUTPUT=$(rpk cluster config set cloud_storage_enabled false 2>&1 || true) |
| 54 | +if echo "${OUTPUT}" | grep -q "Set\|already\|Successfully"; then |
| 55 | + echo "Tiered storage disabled" |
| 56 | +fi |
| 57 | + |
| 58 | +# Disable remote read replicas (enterprise feature) |
| 59 | +OUTPUT=$(rpk cluster config set cloud_storage_enable_remote_read false 2>&1 || true) |
| 60 | +if echo "${OUTPUT}" | grep -q "Set\|already\|Successfully"; then |
| 61 | + echo "Remote read replicas disabled" |
| 62 | +fi |
| 63 | + |
| 64 | +# Disable leader pinning (enterprise feature) |
| 65 | +OUTPUT=$(rpk cluster config set default_leaders_preference none 2>&1 || true) |
| 66 | +if echo "${OUTPUT}" | grep -q "Set\|already\|Successfully"; then |
| 67 | + echo "Leader pinning disabled" |
| 68 | +fi |
| 69 | + |
| 70 | +# Disable server-side schema ID validation (enterprise feature) |
| 71 | +OUTPUT=$(rpk cluster config set enable_schema_id_validation none 2>&1 || true) |
| 72 | +if echo "${OUTPUT}" | grep -q "Set\|already\|Successfully"; then |
| 73 | + echo "Server-side schema ID validation disabled" |
| 74 | +fi |
| 75 | + |
| 76 | +# Ensure we're only using SCRAM (not OIDC/OAUTHBEARER which are enterprise) |
| 77 | +OUTPUT=$(rpk cluster config set sasl_mechanisms '["SCRAM"]' 2>&1 || true) |
| 78 | +if echo "${OUTPUT}" | grep -q "Set\|already\|Successfully"; then |
| 79 | + echo "SASL mechanisms set to SCRAM only" |
| 80 | +fi |
| 81 | + |
| 82 | +echo "Step 4: Enabling auto-create topics..." |
| 83 | +OUTPUT=$(rpk cluster config set auto_create_topics_enabled true 2>&1 || true) |
| 84 | +if echo "${OUTPUT}" | grep -q "Set\|Successfully"; then |
| 85 | + echo "Auto-create topics enabled successfully" |
| 86 | +elif echo "${OUTPUT}" | grep -q "already"; then |
| 87 | + echo "Auto-create topics is already enabled" |
| 88 | +else |
| 89 | + echo "Warning: Failed to enable auto-create topics" |
| 90 | + echo "${OUTPUT}" |
| 91 | +fi |
| 92 | + |
| 93 | +echo "Step 5: Enabling SASL authentication..." |
| 94 | +OUTPUT=$(rpk cluster config set enable_sasl true 2>&1 || true) |
| 95 | +if echo "${OUTPUT}" | grep -q "Set\|Successfully"; then |
| 96 | + echo "SASL enabled successfully" |
| 97 | +elif echo "${OUTPUT}" | grep -q "already"; then |
| 98 | + echo "SASL is already enabled" |
| 99 | +else |
| 100 | + echo "Warning: Failed to enable SASL (might already be enabled via config)" |
| 101 | + echo "${OUTPUT}" |
| 102 | +fi |
| 103 | + |
| 104 | +echo "Step 6: Waiting for SASL to be fully ready..." |
| 105 | +sleep 3 |
| 106 | + |
| 107 | +SASL_CONFIG="-X user=${REDPANDA_USER} -X pass=${REDPANDA_PASSWORD} -X sasl.mechanism=SCRAM-SHA-256" |
| 108 | + |
| 109 | +echo "Step 7: Creating vector-agent user (with SASL)..." |
| 110 | +OUTPUT=$(rpk security user create "${VECTOR_KAFKA_USER}" -p "${VECTOR_KAFKA_PASSWORD}" --mechanism SCRAM-SHA-256 ${SASL_CONFIG} 2>&1 || true) |
| 111 | +if echo "${OUTPUT}" | grep -q "already exists"; then |
| 112 | + echo "vector-agent user already exists, skipping..." |
| 113 | +elif echo "${OUTPUT}" | grep -q "Created user"; then |
| 114 | + echo "vector-agent user created successfully" |
| 115 | +else |
| 116 | + echo "Error: Failed to create vector-agent user" |
| 117 | + echo "${OUTPUT}" |
| 118 | + exit 1 |
| 119 | +fi |
| 120 | + |
| 121 | +echo "Step 8: Setting ACL permissions for vector-agent..." |
| 122 | +OUTPUT=$(rpk security acl create \ |
| 123 | + --allow-principal "User:${VECTOR_KAFKA_USER}" \ |
| 124 | + --operation read,write,create \ |
| 125 | + --topic '*' \ |
| 126 | + --group '*' \ |
| 127 | + ${SASL_CONFIG} 2>&1 || true) |
| 128 | +if echo "${OUTPUT}" | grep -q "already exists"; then |
| 129 | + echo "ACL permissions already exist, skipping..." |
| 130 | +elif echo "${OUTPUT}" | grep -q "Created ACL"; then |
| 131 | + echo "ACL permissions created successfully" |
| 132 | +else |
| 133 | + echo "Warning: Failed to create ACLs (might already exist)" |
| 134 | + echo "${OUTPUT}" |
| 135 | +fi |
| 136 | + |
| 137 | +echo "Redpanda initialization completed successfully!" |
| 138 | + |
0 commit comments