-
Notifications
You must be signed in to change notification settings - Fork 419
Ansieng 4748 jolokia ep #2194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ansieng 4748 jolokia ep #2194
Changes from 6 commits
8503cf4
c2bd017
39e203a
3f8ab2a
aca2561
c0fe247
6275979
efe2789
2be628e
12b0318
a5eaa68
9438256
9cacc08
49b2ad1
c7c395d
5adf206
175cb37
e247a01
f0c38e9
2faea62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -201,5 +201,11 @@ provisioner: | |||||
| jolokia_user: user1 | ||||||
| jolokia_password: pass | ||||||
|
|
||||||
| # Enable Jolokia access control for security | ||||||
| jolokia_access_control_enabled: true | ||||||
| kafka_controller_jolokia_access_control_enabled: true | ||||||
| kafka_controller_jolokia_access_control_custom_file_enabled: true | ||||||
| kafka_controller_jolokia_access_control_file_src_path: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/roles/kafka_controller/templates/jolokia_migration_temp.xml.j2" | ||||||
|
||||||
| kafka_controller_jolokia_access_control_file_src_path: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/roles/kafka_controller/templates/jolokia_migration_temp.xml.j2" | |
| kafka_controller_jolokia_access_control_file_src_path: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/roles/kafka_controller/templates/jolokia_access_control.xml.j2" |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -125,3 +125,14 @@ provisioner: | |||||
| sasl_protocol: plain | ||||||
|
|
||||||
| zookeeper_chroot: "/kafka" | ||||||
| # Add these to the group_vars/all section: | ||||||
| jolokia_enabled: true | ||||||
| jolokia_auth_mode: basic | ||||||
| jolokia_user: user1 | ||||||
| jolokia_password: pass | ||||||
|
|
||||||
| # Configure Jolokia access control | ||||||
| kafka_controller_jolokia_enabled: true | ||||||
| kafka_controller_jolokia_access_control_enabled: true | ||||||
| kafka_controller_jolokia_access_control_custom_file_enabled: true | ||||||
| kafka_controller_jolokia_access_control_file_src_path: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/roles/kafka_controller/templates/jolokia_migration_temp.xml.j2" | ||||||
|
||||||
| kafka_controller_jolokia_access_control_file_src_path: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/roles/kafka_controller/templates/jolokia_migration_temp.xml.j2" | |
| # kafka_controller_jolokia_access_control_file_src_path: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/roles/kafka_controller/templates/jolokia_migration_temp.xml.j2" |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,11 +5,114 @@ | |||||
| - import_playbook: kafka_controller.yml | ||||||
| tags: migrate_to_dual_write | ||||||
|
|
||||||
| #todo:should check if we can hit the jolokia endppint or not, if no the fail and print the error message, continue on yes | ||||||
|
||||||
| #todo:should check if we can hit the jolokia endppint or not, if no the fail and print the error message, continue on yes | |
| #todo:should check if we can hit the jolokia endpoint or not, if no then fail and print the error message, continue on yes |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should combine this and no auth into a single task
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please attach the result of curl request to jolokia endpoint when the access control.xml file doesnt have the mbean for allowing this request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"json": {"error": "java.lang.Exception : Reading attribute Verbose is forbidden for MBean kafka.controller:name=ZkMigrationState,type=KafkaController", "redirected": false, "status": 403, "transfer_encoding": "chunked", "url": "http://127.0.0.1:7777/jolokia/read/kafka.controller:name=ZkMigrationState,type=KafkaController"}
Outdated
Copilot
AI
Aug 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable 'kafka_controller_jolokia_access_control_dest_path' is used but not defined in the visible code. This will cause the task to fail.
Outdated
Copilot
AI
Aug 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The template 'jolokia_migration_temp.xml.j2' is referenced but this file is not included in the PR changes, which will cause the template task to fail.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -334,3 +334,80 @@ | |
| - not (control_center_next_gen_dependency_alertmanager_ssl_enabled | bool and control_center_next_gen_dependency_alertmanager_mtls_enabled | bool and control_center_next_gen_dependency_alertmanager_basic_auth_enabled | bool) | ||
| fail_msg: "Alertmanager SSL, mTLS, and Basic Auth cannot all be enabled simultaneously." | ||
| tags: validate | ||
|
|
||
| # Jolokia Access Control Validations | ||
| - name: Validate Jolokia Access Control Configuration - Kafka Controller | ||
| fail: | ||
| msg: | | ||
| Security requirement: When Jolokia is enabled and access control is enabled, | ||
| you must set kafka_controller_jolokia_access_control_custom_file_enabled to either: | ||
| - true (provide your own secure XML file via kafka_controller_jolokia_access_control_file_src_path) | ||
| - false (use our secure default XML) | ||
| This prevents lateral movement attacks via exposed Jolokia endpoints. | ||
| when: | ||
| - "'kafka_controller' in group_names" | ||
| - kafka_controller_jolokia_enabled|bool | ||
| - kafka_controller_jolokia_access_control_enabled|bool | ||
| - kafka_controller_jolokia_access_control_custom_file_enabled is not defined or kafka_controller_jolokia_access_control_custom_file_enabled is none | ||
|
||
| tags: | ||
| - validate | ||
| - validate_jolokia | ||
|
|
||
| - name: Validate Custom Jolokia Access Control File Path - Kafka Controller | ||
| fail: | ||
| msg: | | ||
| When kafka_controller_jolokia_access_control_custom_file_enabled is true, | ||
| you must provide kafka_controller_jolokia_access_control_file_src_path with a valid file path. | ||
| when: | ||
| - "'kafka_controller' in group_names" | ||
| - kafka_controller_jolokia_enabled|bool | ||
| - kafka_controller_jolokia_access_control_enabled|bool | ||
| - kafka_controller_jolokia_access_control_custom_file_enabled|bool | ||
| - kafka_controller_jolokia_access_control_file_src_path == "" | ||
| tags: | ||
| - validate | ||
| - validate_jolokia | ||
|
|
||
| - name: Validate Custom Jolokia Access Control File Exists - Kafka Controller | ||
| stat: | ||
| path: "{{ kafka_controller_jolokia_access_control_file_src_path }}" | ||
| delegate_to: localhost | ||
| register: kafka_controller_custom_jolokia_file_check | ||
| when: | ||
| - "'kafka_controller' in group_names" | ||
| - kafka_controller_jolokia_enabled|bool | ||
| - kafka_controller_jolokia_access_control_enabled|bool | ||
| - kafka_controller_jolokia_access_control_custom_file_enabled|bool | ||
| - kafka_controller_jolokia_access_control_file_src_path != "" | ||
| tags: | ||
| - validate | ||
| - validate_jolokia | ||
|
|
||
| - name: Fail if Custom Jolokia Access Control File Does Not Exist - Kafka Controller | ||
| fail: | ||
| msg: | | ||
| Custom Jolokia access control file not found at: {{ kafka_controller_jolokia_access_control_file_src_path }} | ||
| Please ensure the file exists on the Ansible controller. | ||
| when: | ||
| - "'kafka_controller' in group_names" | ||
| - kafka_controller_jolokia_enabled|bool | ||
| - kafka_controller_jolokia_access_control_enabled|bool | ||
| - kafka_controller_jolokia_access_control_custom_file_enabled|bool | ||
| - kafka_controller_jolokia_access_control_file_src_path != "" | ||
| - not kafka_controller_custom_jolokia_file_check.stat.exists | ||
| tags: | ||
| - validate | ||
| - validate_jolokia | ||
|
|
||
| - name: Set Default Jolokia Access Control File Path - Kafka Controller | ||
| set_fact: | ||
| kafka_controller_jolokia_access_control_file_src_path: "roles/kafka_controller/templates/jolokia_access_control_default.xml" | ||
|
||
| when: | ||
| - "'kafka_controller' in group_names" | ||
| - kafka_controller_jolokia_enabled|bool | ||
| - kafka_controller_jolokia_access_control_enabled|bool | ||
| - not kafka_controller_jolokia_access_control_custom_file_enabled|bool | ||
| tags: | ||
| - validate | ||
| - validate_jolokia | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- | ||
| Default Jolokia Access Control Policy | ||
| This policy allows access only to the endpoint required for "Wait for Metadata Migration" task | ||
| and should be replaced with a more restrictive policy after migration completes | ||
| --> | ||
| <restrict> | ||
| <!-- Allow access to migration state endpoint - Required for "Wait for Metadata Migration" task --> | ||
| <mbean> | ||
| <n>kafka.controller:type=KafkaController,name=ZkMigrationState</n> | ||
| <operation>read</operation> | ||
| </mbean> | ||
|
|
||
| <!-- Allow jolokia read operations --> | ||
| <command>read</command> | ||
|
|
||
| <!-- Default deny for everything else --> | ||
| <default>deny</default> | ||
| </restrict> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -12,3 +12,6 @@ authMode=basic | |||||
| user={{kafka_controller_jolokia_user}} | ||||||
| password={{kafka_controller_jolokia_password}} | ||||||
| {% endif %} | ||||||
| {% if kafka_controller_jolokia_access_control_enabled|bool %} | ||||||
| policy={{ lookup('file', kafka_controller_jolokia_access_control_file_src_path) | replace('\n', '') | replace(' ', '') }} | ||||||
|
||||||
| policy={{ lookup('file', kafka_controller_jolokia_access_control_file_src_path) | replace('\n', '') | replace(' ', '') }} | |
| policy={{ lookup('file', kafka_controller_jolokia_access_control_file_src_path) }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,15 @@ jolokia_user: admin | |
| ### Password for Jolokia Agent when using Basic Auth | ||
| jolokia_password: password | ||
|
|
||
| ### Boolean to enable Jolokia Access Control for security. Defaults to same as jolokia_enabled | ||
| jolokia_access_control_enabled: "{{ jolokia_enabled }}" | ||
|
|
||
| ### Boolean to use custom Jolokia access control file. Must be set to true or false when Jolokia access control is enabled. Set to null to enforce explicit choice. | ||
| jolokia_access_control_custom_file_enabled: null | ||
|
|
||
| ### Full path on Ansible Controller to custom Jolokia access control XML file. Required when jolokia_access_control_custom_file_enabled is true | ||
| jolokia_access_control_file_src_path: "" | ||
|
|
||
| ### To copy from Ansible control host or download | ||
| jmxexporter_url_remote: true | ||
|
|
||
|
|
@@ -549,6 +558,17 @@ kafka_controller_jolokia_user: "{{jolokia_user}}" | |
| ### Password for Kafka's Jolokia Agent when using Basic Auth | ||
| kafka_controller_jolokia_password: "{{jolokia_password}}" | ||
|
|
||
| ### Boolean to enable Jolokia Access Control for Kafka Controller. Inherits from global setting | ||
| kafka_controller_jolokia_access_control_enabled: "{{ jolokia_access_control_enabled }}" | ||
|
|
||
| ### Boolean to use custom Jolokia access control file for Kafka Controller. Inherits from global setting | ||
| kafka_controller_jolokia_access_control_custom_file_enabled: "{{ jolokia_access_control_custom_file_enabled }}" | ||
|
||
|
|
||
| ### Full path on Ansible Controller to custom Jolokia access control XML file for Kafka Controller. Inherits from global setting | ||
| kafka_controller_jolokia_access_control_file_src_path: "{{ jolokia_access_control_file_src_path }}" | ||
|
||
|
|
||
|
|
||
|
|
||
| # TODO move these to vars, should not be customizable, do they even belong w the shared vars | ||
| kafka_controller_jolokia_java_arg_ssl_addon: ",keystore={{kafka_controller_keystore_path}},keystorePassword={{kafka_controller_keystore_storepass}},protocol=https" | ||
| kafka_controller_jolokia_urp_url: "{{ 'https' if kafka_controller_jolokia_ssl_enabled|bool else 'http' }}://{{ hostvars[inventory_hostname]|confluent.platform.resolve_and_format_hostname}}:{{kafka_controller_jolokia_port}}/jolokia/read/kafka.server:type=ReplicaManager,name=UnderReplicatedPartitions" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this and above test both are validating same case but we dont have any case for access control enabled false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's by default false only, so we need to check for jolokia_access_control_custom_file_enabled true and false, which i have added tc in pr - https://github.com/confluentinc/cp-ansible/pull/2197/files