-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
139 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
export VAULT_ADDR=http://localhost:8200 | ||
PLUGIN_NAME="vault-plugin-secrets-kafka" | ||
MNT_PATH="kafka" | ||
|
||
echo "---> Building" | ||
GOOS=linux GOARCH=amd64 go build -o "docker/plugins/$PLUGIN_NAME" | ||
SHASUM=$(shasum -a 256 "docker/plugins/$PLUGIN_NAME" | cut -d " " -f1) | ||
|
||
echo "---->Registering plugin" | ||
vault write sys/plugins/catalog/$PLUGIN_NAME \ | ||
sha_256="$SHASUM" \ | ||
command="$PLUGIN_NAME" | ||
|
||
echo " Mouting plugin" | ||
vault secrets enable -path=$MNT_PATH -plugin-name=$PLUGIN_NAME plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
version: '2' | ||
services: | ||
vault: | ||
image: vault:1.3.0 | ||
ports: | ||
- "8200:8200" | ||
command: vault server -dev -config="/vault/vault.hcl" | ||
volumes: | ||
- ./docker:/vault | ||
environment: | ||
VAULT_DEV_ROOT_TOKEN_ID: "root" | ||
VAULT_DEV_LISTEN_ADDRESS: "0.0.0.0:8200" | ||
|
||
zookeeper: | ||
image: confluentinc/cp-zookeeper:latest | ||
ports: | ||
- "2181:2181" | ||
environment: | ||
ZOOKEEPER_CLIENT_PORT: 2181 | ||
ZOOKEEPER_TICK_TIME: 2000 | ||
extra_hosts: | ||
- "moby:127.0.0.1" | ||
|
||
kafka: | ||
image: confluentinc/cp-kafka:5.0.1 | ||
ports: | ||
- "9092:9092" | ||
depends_on: | ||
- zookeeper | ||
environment: | ||
KAFKA_BROKER_ID: 1 | ||
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 | ||
KAFKA_ADVERTISED_LISTENERS: SSL://localhost:9092 | ||
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 | ||
|
||
KAFKA_SSL_KEYSTORE_FILENAME: kafka.broker0.keystore.jks | ||
KAFKA_SSL_TRUSTSTORE_FILENAME: kafka.broker0.truststore.jks | ||
|
||
KAFKA_SSL_KEY_CREDENTIALS: broker0_sslkey_creds | ||
|
||
KAFKA_SSL_KEYSTORE_CREDENTIALS: broker0_keystore_creds | ||
KAFKA_SSL_TRUSTSTORE_CREDENTIALS: broker0_truststore_creds | ||
|
||
KAFKA_SECURITY_INTER_BROKER_PROTOCOL: SSL | ||
KAFKA_SSL_CLIENT_AUTH: required | ||
KAFKA_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM: "" | ||
KAFKA_LISTENER_NAME_INTERNAL_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM: | ||
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "false" | ||
KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.auth.SimpleAclAuthorizer | ||
volumes: | ||
- ./tmp/secrets:/etc/kafka/secrets | ||
extra_hosts: | ||
- "moby:127.0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
plugin_directory = "/vault/plugins" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
export VAULT_ADDR=http://localhost:8200 | ||
|
||
echo "PKI Enable" | ||
vault secrets enable pki | ||
vault write pki/root/generate/internal common_name=kafka-cluster | ||
echo "Kafka role" | ||
vault write pki/roles/kafka-clients allow_any_name=true | ||
echo "==> Ready!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
|
||
"github.com/Mongey/terraform-provider-kafka/kafka" | ||
"github.com/Shopify/sarama" | ||
) | ||
|
||
const topic = "my-topic" | ||
|
||
func main() { | ||
bootstrapServers := []string{"localhost:9092"} | ||
cfg, err := newTLSConfig("client.cert", "private.key", "ca.cert") | ||
_client, err := client("localhost:9092", "client.cert", "private.key", "ca.cert") | ||
if err != nil { | ||
log.Fatalf("%s", err) | ||
} | ||
kafkaConfig := sarama.NewConfig() | ||
kafkaConfig.Version = sarama.V2_0_0_0 | ||
kafkaConfig.ClientID = "terraform-provider-kafka" | ||
kafkaConfig.Net.TLS.Enable = true | ||
kafkaConfig.Net.TLS.Config = cfg | ||
sarama.Logger = log.New(os.Stderr, "", log.LstdFlags) | ||
|
||
consumeAllMessages(topic, bootstrapServers, kafkaConfig) | ||
produce(topic, bootstrapServers, kafkaConfig) | ||
} | ||
|
||
func client(broker, caLocation, clientCertLocation, clientKeyLocation string) (*sarama.Client, error) { | ||
brokers := []string{broker} | ||
caCert, err := ioutil.ReadFile(caLocation) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
clientCert, err := ioutil.ReadFile(clientCertLocation) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
clientKey, err := ioutil.ReadFile(clientKeyLocation) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
config := &kafka.Config{ | ||
BootstrapServers: &brokers, | ||
CACert: string(caCert), | ||
ClientCert: string(clientCert), | ||
ClientCertKey: string(clientKey), | ||
SkipTLSVerify: false, | ||
TLSEnabled: true, | ||
Timeout: 100, | ||
} | ||
|
||
client, err := kafka.NewClient(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
c := client.SaramaClient() | ||
|
||
return &c, nil | ||
} |