2016-01-08 12:04:24 +08:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2021-05-20 01:32:56 +08:00
|
|
|
import time
|
2016-01-08 12:04:24 +08:00
|
|
|
|
2020-10-09 22:34:53 +08:00
|
|
|
class ACLs:
|
2016-05-07 02:10:27 +08:00
|
|
|
def __init__(self, context):
|
|
|
|
self.context = context
|
2016-01-08 12:04:24 +08:00
|
|
|
|
2025-07-09 17:07:56 +08:00
|
|
|
def add_cluster_acl(self, kafka, principal, additional_cluster_operations_to_grant = [], security_protocol=None):
|
2020-09-15 06:56:21 +08:00
|
|
|
"""
|
|
|
|
:param kafka: Kafka cluster upon which ClusterAction ACL is created
|
|
|
|
:param principal: principal for which ClusterAction ACL is created
|
|
|
|
:param node: Node to use when determining connection settings
|
2020-10-09 22:34:53 +08:00
|
|
|
:param additional_cluster_operations_to_grant may be set to ['Alter', 'Create'] if the cluster is secured since these are required
|
|
|
|
to create SCRAM credentials and topics, respectively
|
2021-05-20 01:32:56 +08:00
|
|
|
:param security_protocol set it to explicitly determine whether we use client or broker credentials, otherwise
|
2025-07-24 19:05:07 +08:00
|
|
|
we use the client security protocol unless inter-broker security protocol is PLAINTEXT, in which case we use PLAINTEXT.
|
2021-05-20 01:32:56 +08:00
|
|
|
Then we use the broker's credentials if the selected security protocol matches the inter-broker security protocol,
|
|
|
|
otherwise we use the client's credentials.
|
2020-09-15 06:56:21 +08:00
|
|
|
"""
|
|
|
|
node = kafka.nodes[0]
|
|
|
|
|
2020-10-09 22:34:53 +08:00
|
|
|
for operation in ['ClusterAction'] + additional_cluster_operations_to_grant:
|
|
|
|
cmd = "%(cmd_prefix)s --add --cluster --operation=%(operation)s --allow-principal=%(principal)s" % {
|
2025-07-09 17:07:56 +08:00
|
|
|
'cmd_prefix': kafka.kafka_acls_cmd_with_optional_security_settings(node, security_protocol),
|
2020-10-09 22:34:53 +08:00
|
|
|
'operation': operation,
|
|
|
|
'principal': principal
|
|
|
|
}
|
|
|
|
kafka.run_cli_tool(node, cmd)
|
2016-01-08 12:04:24 +08:00
|
|
|
|
2021-05-20 01:32:56 +08:00
|
|
|
def remove_cluster_acl(self, kafka, principal, additional_cluster_operations_to_remove = [], security_protocol=None):
|
|
|
|
"""
|
|
|
|
:param kafka: Kafka cluster upon which ClusterAction ACL is deleted
|
|
|
|
:param principal: principal for which ClusterAction ACL is deleted
|
|
|
|
:param node: Node to use when determining connection settings
|
|
|
|
:param additional_cluster_operations_to_remove may be set to ['Alter', 'Create'] if the cluster is secured since these are required
|
|
|
|
to create SCRAM credentials and topics, respectively
|
|
|
|
:param security_protocol set it to explicitly determine whether we use client or broker credentials, otherwise
|
2025-07-24 19:05:07 +08:00
|
|
|
we use the client security protocol unless inter-broker security protocol is PLAINTEXT, in which case we use PLAINTEXT.
|
2021-05-20 01:32:56 +08:00
|
|
|
Then we use the broker's credentials if the selected security protocol matches the inter-broker security protocol,
|
|
|
|
otherwise we use the client's credentials.
|
|
|
|
"""
|
|
|
|
node = kafka.nodes[0]
|
|
|
|
|
|
|
|
for operation in ['ClusterAction'] + additional_cluster_operations_to_remove:
|
|
|
|
cmd = "%(cmd_prefix)s --remove --force --cluster --operation=%(operation)s --allow-principal=%(principal)s" % {
|
2025-07-09 17:07:56 +08:00
|
|
|
'cmd_prefix': kafka.kafka_acls_cmd_with_optional_security_settings(node, security_protocol),
|
2021-05-20 01:32:56 +08:00
|
|
|
'operation': operation,
|
|
|
|
'principal': principal
|
|
|
|
}
|
|
|
|
kafka.logger.info(cmd)
|
|
|
|
kafka.run_cli_tool(node, cmd)
|