Skip to content

Commit 22c5388

Browse files
author
Marco Ronconi
committed
Add molecule scenario to test ZK mTLS
1 parent 1760f28 commit 22c5388

File tree

3 files changed

+162
-0
lines changed

3 files changed

+162
-0
lines changed

molecule/zk-secured/converge.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
- import_playbook: ../../playbooks/setup.yml

molecule/zk-secured/molecule.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
# skip prerun because I am experiencing the issue described here:
3+
# https://github.com/ansible/ansible-lint/issues/2070
4+
prerun: false
5+
dependency:
6+
name: galaxy
7+
driver:
8+
name: docker
9+
lint: |
10+
ansible-lint -v
11+
platforms:
12+
13+
- name: machine1
14+
image: registry.access.redhat.com/ubi8/ubi-init:latest
15+
pre_build_image: true
16+
privileged: true
17+
command: "/usr/sbin/init"
18+
groups:
19+
- kafka
20+
- zookeeper
21+
networks:
22+
- name: molecule
23+
24+
- name: machine2
25+
image: registry.access.redhat.com/ubi8/ubi-init:latest
26+
pre_build_image: true
27+
privileged: true
28+
command: "/usr/sbin/init"
29+
groups:
30+
- kafka
31+
- zookeeper
32+
networks:
33+
- name: molecule
34+
35+
- name: machine3
36+
image: registry.access.redhat.com/ubi8/ubi-init:latest
37+
pre_build_image: true
38+
privileged: true
39+
command: "/usr/sbin/init"
40+
groups:
41+
- kafka
42+
- zookeeper
43+
networks:
44+
- name: molecule
45+
46+
provisioner:
47+
name: ansible
48+
ansible_args:
49+
- --diff
50+
playbooks:
51+
converge: converge.yml
52+
prepare: ../shared/prepare.yml
53+
verify: verify.yml
54+
inventory:
55+
group_vars:
56+
zookeeper:
57+
zookeeper_interface_name: eth0
58+
59+
zookeeper_auth_client_enabled: true
60+
zookeeper_auth_quorum_enabled: true
61+
zookeeper_auth_type: tls
62+
63+
zookeeper_tls_config:
64+
enabled: true
65+
trustedCA:
66+
file: ../../../molecule/shared/certs/ca-root.pem
67+
location: /etc/certs/ca-root.pem
68+
keystore:
69+
file: ../../../molecule/shared/certs/cert-cluster.p12
70+
location: /etc/certs/cert-cluster.p12
71+
password: changeit
72+
type: PKCS12
73+
74+
kafka:
75+
kafka_advertised_interface_name: eth0
76+
kafka_advertised_host: "{{ ansible_hostname }}"
77+
78+
kafka_tls_config:
79+
enabled: true
80+
trustedCA:
81+
file: ../../../molecule/shared/certs/ca-root.pem
82+
location: /etc/certs/ca-root.pem
83+
keystore:
84+
file: ../../../molecule/shared/certs/cert-cluster.p12
85+
location: /etc/certs/cert-cluster.p12
86+
password: changeit
87+
type: PKCS12
88+
89+
kafka_listeners:
90+
91+
- name: plain
92+
port: 9092
93+
tls: false
94+
95+
kafka_inter_broker_listener_name: plain
96+
97+
kafka_admin:
98+
listener_name: plain
99+
100+
host_vars:
101+
machine1:
102+
kafka_broker_id: 1
103+
zookeeper_myid: 1
104+
machine2:
105+
kafka_broker_id: 2
106+
zookeeper_myid: 2
107+
machine3:
108+
kafka_broker_id: 3
109+
zookeeper_myid: 3
110+
localhost:
111+
ansible_python_interpreter: "{{ ansible_playbook_python }}"
112+
verifier:
113+
name: ansible

molecule/zk-secured/verify.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
- name: Verify
3+
hosts: all
4+
gather_facts: true
5+
vars:
6+
kafka_home: /opt/kafka/kafka_2.13-3.7.0
7+
tasks:
8+
9+
- name: Ensure ZK CLI config file exist
10+
ansible.builtin.copy:
11+
content: |
12+
zookeeper.ssl.keystore.location=/etc/certs/cert-cluster.p12
13+
zookeeper.ssl.keystore.password=changeit
14+
zookeeper.ssl.keystore.type=PKCS12
15+
zookeeper.ssl.truststore.location=/etc/certs/ca-root.pem
16+
zookeeper.ssl.truststore.type=PEM
17+
zookeeper.ssl.client.enable=true
18+
zookeeper.clientCnxnSocket=org.apache.zookeeper.ClientCnxnSocketNetty
19+
dest: /tmp/zk-tls-config.properties
20+
21+
- name: Test ZK CLI mTLS connection
22+
ansible.builtin.command: >
23+
{{ kafka_home }}/bin/zookeeper-shell.sh \
24+
{{ ansible_default_ipv4.address }}:2182 \
25+
whoami \
26+
-zk-tls-config-file /tmp/zk-tls-config.properties
27+
changed_when: false
28+
register: zk_cli_res
29+
30+
- name: ZK CLI mTLS connection assertions
31+
ansible.builtin.assert:
32+
that:
33+
- zk_cli_res.stdout_lines is search('SyncConnected')
34+
- zk_cli_res.stdout_lines is search('x509:\ CN=kafka')
35+
36+
- name: Test Kafka to ZK mTLS connection
37+
ansible.builtin.command: >
38+
{{ kafka_home }}/bin/kafka-topics.sh \
39+
--bootstrap-server {{ ansible_default_ipv4.address }}:9092 \
40+
--describe
41+
changed_when: false
42+
run_once: true
43+
register: kafka_zk_res
44+
45+
- name: Kafka to ZK mTLS connection assertions
46+
ansible.builtin.assert:
47+
that: kafka_zk_res.rc == 0

0 commit comments

Comments
 (0)