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

[DPE-5206] Add DIGEST scheme ACL to znode created by zookeeper #97

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
31 changes: 18 additions & 13 deletions src/managers/quorum.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)
from kazoo.exceptions import BadArgumentsError, ConnectionClosedError
from kazoo.handlers.threading import KazooTimeoutError
from kazoo.security import make_acl
from kazoo.security import make_acl, make_digest_acl_credential
from ops.charm import RelationEvent

from core.cluster import ClusterState
Expand Down Expand Up @@ -198,18 +198,23 @@ def update_acls(self, event: RelationEvent | None = None) -> None:
if not client.database:
continue

generated_acl = make_acl(
scheme="sasl",
credential=client.username,
read="r" in client.extra_user_roles,
write="w" in client.extra_user_roles,
create="c" in client.extra_user_roles,
delete="d" in client.extra_user_roles,
admin="a" in client.extra_user_roles,
acls = {
"read": "r" in client.extra_user_roles,
"write": "w" in client.extra_user_roles,
"create": "c" in client.extra_user_roles,
"delete": "d" in client.extra_user_roles,
"admin": "a" in client.extra_user_roles,
}

sasl_acl = make_acl(scheme="sasl", credential=client.username, **acls)
digest_acl = make_acl(
scheme="digest",
credential=make_digest_acl_credential(client.username, client.password),
**acls,
theoctober19th marked this conversation as resolved.
Show resolved Hide resolved
)
logger.info(f"{generated_acl=}")

requested_acls.add(generated_acl)
requested_acls.add(sasl_acl)
requested_acls.add(digest_acl)

# FIXME: data-platform-libs should handle this when it's implemented
if client.database:
Expand All @@ -221,11 +226,11 @@ def update_acls(self, event: RelationEvent | None = None) -> None:
# Looks for newly related applications not in config yet
if client.database not in leader_chroots:
logger.info(f"CREATE CHROOT - {client.database}")
self.client.create_znode_leader(path=client.database, acls=[generated_acl])
self.client.create_znode_leader(path=client.database, acls=[sasl_acl, digest_acl])

# Looks for existing related applications
logger.info(f"UPDATE CHROOT - {client.database}")
self.client.set_acls_znode_leader(path=client.database, acls=[generated_acl])
self.client.set_acls_znode_leader(path=client.database, acls=[sasl_acl, digest_acl])

# Looks for applications no longer in the relation but still in config
for chroot in sorted(leader_chroots - requested_chroots, reverse=True):
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async def test_deploy_ssl_quorum(ops_test: OpsTest):
num_units=1,
config={"ca-common-name": "zookeeper"},
series=TLS_OPERATOR_SERIES,
revision=163, # FIXME: Unpin once the TLS is fixed on edge channel
),
)
await ops_test.model.block_until(lambda: len(ops_test.model.applications[APP_NAME].units) == 3)
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_quorum.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,17 @@ def test_update_acls_correctly_handles_relation_chroots(harness):

for _, kwargs in patched_manager["create_znode_leader"].call_args_list:
assert "/rohan" in kwargs["path"]
acls = kwargs["acls"]
assert len(acls) == 2
assert len([acl for acl in acls if acl.perms == 31 and acl.id.scheme == "sasl"]) != 0
assert len([acl for acl in acls if acl.perms == 31 and acl.id.scheme == "digest"]) != 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question what is the 31 magic number?


for _, kwargs in patched_manager["set_acls_znode_leader"].call_args_list:
assert "/rohan" in kwargs["path"]
acls = kwargs["acls"]
assert len(acls) == 2
assert len([acl for acl in acls if acl.perms == 31 and acl.id.scheme == "sasl"]) != 0
assert len([acl for acl in acls if acl.perms == 31 and acl.id.scheme == "digest"]) != 0

removed_men = False
for counter, call in enumerate(patched_manager["delete_znode_leader"].call_args_list):
Expand Down
Loading