-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* secure: secured the kafka cluster
- Loading branch information
Showing
11 changed files
with
152 additions
and
22 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
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
remote_user: vagrant | ||
serial: 33% | ||
roles: | ||
- secure | ||
- zookeeper | ||
|
||
- hosts: kafka | ||
|
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,6 +1,13 @@ | ||
download: /vagrant/download | ||
exchange: /vagrant/exchange | ||
ssl_ca_dir: "{{ exchange }}/ssl" | ||
ssl_client_dir: "{{ exchange }}/ssl-client" | ||
usr_local: /usr/local | ||
etc_profiles: /etc/profile.d | ||
system_units: /etc/systemd/system | ||
jmxtrans_dest: /usr/local/jmxtrans | ||
prometheus_jmx_dest: /usr/local/prometheus_jmx | ||
keystore_pwd: keystore-secret | ||
key_pwd: key-secret | ||
truststore_pwd: truststore-secret | ||
ca_pwd: ca-secret |
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,7 @@ | ||
security.protocol=SSL | ||
ssl.truststore.location={{ ssl_client_dir }}/client.truststore.jks | ||
ssl.truststore.password={{ truststore_pwd }} | ||
ssl.keystore.location={{ ssl_client_dir }}/client.keystore.jks | ||
ssl.keystore.password={{ keystore_pwd }} | ||
ssl.key.password={{ key_pwd }} | ||
ssl.enabled.protocols=TLSv1.2 |
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,2 @@ | ||
--- | ||
validity: 365 |
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,76 @@ | ||
--- | ||
- name: generate client folders | ||
file: | ||
path: "{{ item }}" | ||
state: directory | ||
mode: 0755 | ||
with_items: | ||
- "{{ ssl_client_dir }}" | ||
- "{{ ssl_ca_dir }}" | ||
|
||
- name: generate keystores | ||
become: true | ||
shell: "keytool -keystore {{ item.keystore }} -alias localhost -validity {{ validity }} -genkey -storepass {{ keystore_pwd }} -keypass {{ key_pwd }} -keyalg RSA -dname \"CN=kafka,OU=org,O=org,L=home,ST=Bavaria,C=DE\" -ext SAN=DNS:{{ inventory_hostname }}" | ||
args: | ||
creates: "{{ item.keystore }}" | ||
with_items: | ||
- { keystore: /usr/local/server.keystore.jks } | ||
- { keystore: "{{ ssl_client_dir }}/client.keystore.jks" } | ||
|
||
- name: create CA | ||
become: true | ||
shell: "openssl req -new -x509 -keyout {{ ssl_ca_dir }}/ca-key -out {{ ssl_ca_dir }}/ca-cert -passout pass:{{ ca_pwd }} -days {{ validity }} -subj \"/C=DE/ST=Bavaria/L=home/O=org/OU=org/CN=kafka\"" | ||
args: | ||
creates: "{{ ssl_ca_dir }}/ca-cert" | ||
#creates: "{{ ssl_ca_dir }}/ca-key" | ||
run_once: true | ||
|
||
- name: import CA into truststores | ||
become: true | ||
java_cert: | ||
cert_path: "{{ ssl_ca_dir }}/ca-cert" | ||
cert_alias: CARoot | ||
keystore_path: "{{ item }}" | ||
keystore_pass: "{{ truststore_pwd }}" | ||
keystore_create: true | ||
state: present | ||
with_items: | ||
- "/usr/local/server.truststore.jks" | ||
- "{{ ssl_client_dir }}/client.truststore.jks" | ||
|
||
- name: create CSR | ||
become: true | ||
shell: "keytool -keystore {{ item.keystore }} -alias localhost -certreq -file {{ item.cert_csr }} -storepass {{ keystore_pwd }} -keypass {{ key_pwd }} -ext SAN=DNS:{{ inventory_hostname }}" | ||
args: | ||
creates: "{{ item.cert_csr }}" | ||
with_items: | ||
- { keystore: "/usr/local/server.keystore.jks", cert_csr: "/tmp/cert-csr" } | ||
- { keystore: "{{ ssl_client_dir }}/client.keystore.jks", cert_csr: "{{ ssl_client_dir }}/cert-csr" } | ||
|
||
- name: create SAN conf for signing | ||
lineinfile: | ||
create: yes | ||
path: /tmp/san.conf | ||
line: 'subjectAltName=DNS:{{ inventory_hostname }}' | ||
state: present | ||
|
||
- name: sign certificates | ||
become: true | ||
shell: "openssl x509 -req -CAkey {{ ssl_ca_dir }}/ca-key -CA {{ ssl_ca_dir }}/ca-cert -days {{ validity }} -CAcreateserial -in {{ item.cert_csr }} -passin pass:{{ ca_pwd }} -out {{ item.cert_file_signed }} -extfile /tmp/san.conf" | ||
args: | ||
creates: "{{ item.cert_file_signed }}" | ||
with_items: | ||
- { cert_csr: /tmp/cert-csr, cert_file_signed: /tmp/cert-signed} | ||
- { cert_csr: "{{ ssl_client_dir }}/cert-csr" , cert_file_signed: "{{ ssl_client_dir }}/cert-signed" } | ||
register: signed | ||
|
||
- name: import signed certificates into keystores | ||
become: true | ||
shell: "keytool -keystore {{ item.keystore }} -alias {{ item.alias }} -import -file {{ item.path }} -noprompt -storepass {{ keystore_pwd }} -keypass {{ key_pwd }}" | ||
with_items: | ||
- { alias: CARoot, path: "{{ ssl_ca_dir }}/ca-cert", keystore: "/usr/local/server.keystore.jks" } | ||
- { alias: localhost, path: "/tmp/cert-signed", keystore: "/usr/local/server.keystore.jks" } | ||
- { alias: CARoot, path: "{{ ssl_ca_dir }}/ca-cert", keystore: "{{ ssl_client_dir }}/client.keystore.jks" } | ||
- { alias: localhost, path: "{{ ssl_client_dir }}/cert-signed", keystore: "{{ ssl_client_dir }}/client.keystore.jks" } | ||
when: signed.changed | ||
ignore_errors: true #client store already done with first host |