Skip to content
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

Kazoo auth for ch_keeper and keeper-monitoring #234

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ch_tools/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
},
"zookeeper": {
"randomize_hosts": True,
"username": None,
"password": None,
},
"chadmin": {
"wait": {
Expand Down
31 changes: 23 additions & 8 deletions ch_tools/monrun_checks_keeper/keeper_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from click import command, option, pass_context
from kazoo.client import KazooClient
from kazoo.security import make_digest_acl

from ch_tools.common.clickhouse.config import ClickhouseKeeperConfig
from ch_tools.common.result import CRIT, OK, WARNING, Result
Expand All @@ -27,14 +28,28 @@ def alive_command(ctx):
"""Check (Zoo)Keeper service is alive"""
try:
keeper_port, use_ssl = get_keeper_port_pair()
client = KazooClient(
f"127.0.0.1:{keeper_port}",
connection_retry=ctx.obj.get("retries"),
command_retry=ctx.obj.get("retries"),
timeout=ctx.obj.get("timeout"),
use_ssl=use_ssl,
verify_certs=not ctx.obj.get("no_verify_ssl_certs"),
)
username = ctx.obj["config"]["zookeeper"]["username"]
password = ctx.obj["config"]["zookeeper"]["password"]
args = {
"hosts": f"127.0.0.1:{keeper_port}",
"connection_retry": ctx.obj.get("retries"),
"command_retry": ctx.obj.get("retries"),
"timeout": ctx.obj.get("timeout"),
"use_ssl": use_ssl,
"verify_certs": not ctx.obj.get("no_verify_ssl_certs"),
}
if username is not None and password is not None:
auth_data = [
(
"digest",
f"{username}:{password}",
)
]
acls = [make_digest_acl(username, password, all=True)]
args["auth_data"] = auth_data
args["default_acl"] = acls

client = KazooClient(**args)
client.start()
client.get("/")
client.create(path="/{0}_alive".format(socket.getfqdn()), ephemeral=True)
Expand Down
Loading