def add_acls(self, user: str, kafka_server: dict, topic_name: str): service = KafkaService(kafka_server) # TODO: If zookeeper has Kerberos enabled, then the environment should be changed environment = None topics.add_acls(user, self.id, topic_name, service.get_zookeeper_endpoint(), environment)
def test_authz_acls_required(kafka_client, kafka_server, kerberos): client_id = kafka_client["id"] sdk_cmd.resolve_hosts(kafka_client["id"], kafka_client["brokers"]) topic_name = "authz.test" sdk_cmd.svc_cli(kafka_server["package_name"], kafka_server["service"]["name"], "topic create {}".format(topic_name), json=True) test_utils.wait_for_topic(kafka_server["package_name"], kafka_server["service"]["name"], topic_name) message = str(uuid.uuid4()) log.info("Writing and reading: Writing to the topic, but not super user") assert not write_to_topic("authorized", client_id, topic_name, message, kerberos) log.info("Writing and reading: Writing to the topic, as super user") assert write_to_topic("super", client_id, topic_name, message, kerberos) log.info("Writing and reading: Reading from the topic, but not super user") assert auth.is_not_authorized(read_from_topic("authorized", client_id, topic_name, 1, kerberos)) log.info("Writing and reading: Reading from the topic, as super user") assert message in read_from_topic("super", client_id, topic_name, 1, kerberos) zookeeper_endpoint = sdk_cmd.svc_cli( kafka_server["package_name"], kafka_server["service"]["name"], "endpoint zookeeper").strip() # TODO: If zookeeper has Kerberos enabled, then the environment should be changed topics.add_acls("authorized", client_id, topic_name, zookeeper_endpoint, env_str=None) # Send a second message which should not be authorized second_message = str(uuid.uuid4()) log.info("Writing and reading: Writing to the topic, but not super user") assert write_to_topic("authorized", client_id, topic_name, second_message, kerberos) log.info("Writing and reading: Writing to the topic, as super user") assert write_to_topic("super", client_id, topic_name, second_message, kerberos) log.info("Writing and reading: Reading from the topic, but not super user") topic_output = read_from_topic("authorized", client_id, topic_name, 3, kerberos) assert message in topic_output assert second_message in topic_output log.info("Writing and reading: Reading from the topic, as super user") topic_output = read_from_topic("super", client_id, topic_name, 3, kerberos) assert message in topic_output assert second_message in topic_output # Check that the unauthorized client can still not read or write from the topic. log.info("Writing and reading: Writing to the topic, but not super user") assert not write_to_topic("unauthorized", client_id, topic_name, second_message, kerberos) log.info("Writing and reading: Reading from the topic, but not super user") assert auth.is_not_authorized(read_from_topic("unauthorized", client_id, topic_name, 1, kerberos))
def test_authz_acls_not_required(kafka_client, service_account, setup_principals): client_id = kafka_client["id"] try: sdk_install.uninstall(config.PACKAGE_NAME, config.SERVICE_NAME) config.install(config.PACKAGE_NAME, config.SERVICE_NAME, config.DEFAULT_BROKER_COUNT, additional_options={ "brokers": { "port_tls": 1030 }, "service": { "service_account": service_account["name"], "service_account_secret": service_account["secret"], "security": { "transport_encryption": { "enabled": True }, "ssl_authentication": { "enabled": True }, "authorization": { "enabled": True, "super_users": "User:{}".format("super"), "allow_everyone_if_no_acl_found": True } } } }) auth.wait_for_brokers(client_id, kafka_client["brokers"]) # Create the topic sdk_cmd.svc_cli(config.PACKAGE_NAME, config.SERVICE_NAME, "topic create authz.test", json=True) test_utils.wait_for_topic(config.PACKAGE_NAME, config.SERVICE_NAME, "authz.test") super_message = str(uuid.uuid4()) authorized_message = str(uuid.uuid4()) unauthorized_message = str(uuid.uuid4()) log.info( "Writing and reading: Writing to the topic, as authorized user") assert write_to_topic("authorized", client_id, "authz.test", authorized_message) log.info( "Writing and reading: Writing to the topic, as unauthorized user") assert write_to_topic("unauthorized", client_id, "authz.test", unauthorized_message) log.info("Writing and reading: Writing to the topic, as super user") assert write_to_topic("super", client_id, "authz.test", super_message) log.info( "Writing and reading: Reading from the topic, as authorized user") assert authorized_message in read_from_topic("authorized", client_id, "authz.test", 3) log.info( "Writing and reading: Reading from the topic, as unauthorized user" ) assert unauthorized_message in read_from_topic("unauthorized", client_id, "authz.test", 3) log.info("Writing and reading: Reading from the topic, as super user") assert super_message in read_from_topic("super", client_id, "authz.test", 3) log.info("Writing and reading: Adding acl for authorized user") zookeeper_endpoint = str( sdk_cmd.svc_cli(config.PACKAGE_NAME, config.SERVICE_NAME, "endpoint zookeeper")).strip() topics.add_acls("authorized", client_id, "authz.test", zookeeper_endpoint, env_str=None) # Re-roll the messages so we really prove auth is in place. super_message = str(uuid.uuid4()) authorized_message = str(uuid.uuid4()) unauthorized_message = str(uuid.uuid4()) log.info( "Writing and reading: Writing to the topic, as authorized user") assert write_to_topic("authorized", client_id, "authz.test", authorized_message) log.info( "Writing and reading: Writing to the topic, as unauthorized user") assert not write_to_topic("unauthorized", client_id, "authz.test", unauthorized_message) log.info("Writing and reading: Writing to the topic, as super user") assert write_to_topic("super", client_id, "authz.test", super_message) log.info( "Writing and reading: Reading from the topic, as authorized user") read_result = read_from_topic("authorized", client_id, "authz.test", 5) assert authorized_message in read_result and unauthorized_message not in read_result log.info( "Writing and reading: Reading from the topic, as unauthorized user" ) assert auth.is_not_authorized( read_from_topic("unauthorized", client_id, "authz.test", 1)) log.info("Writing and reading: Reading from the topic, as super user") read_result = read_from_topic("super", client_id, "authz.test", 5) assert super_message in read_result and unauthorized_message not in read_result finally: sdk_install.uninstall(config.PACKAGE_NAME, config.SERVICE_NAME)
def test_authz_acls_not_required(kafka_client, service_account, setup_principals): client_id = kafka_client["id"] try: sdk_install.uninstall(config.PACKAGE_NAME, config.SERVICE_NAME) config.install( config.PACKAGE_NAME, config.SERVICE_NAME, config.DEFAULT_BROKER_COUNT, additional_options={ "brokers": { "port_tls": 1030 }, "service": { "service_account": service_account["name"], "service_account_secret": service_account["secret"], "security": { "transport_encryption": { "enabled": True }, "ssl_authentication": { "enabled": True }, "authorization": { "enabled": True, "super_users": "User:{}".format("super"), "allow_everyone_if_no_acl_found": True } } } }) sdk_cmd.resolve_hosts(client_id, kafka_client["brokers"]) # Create the topic sdk_cmd.svc_cli(config.PACKAGE_NAME, config.SERVICE_NAME, "topic create authz.test", json=True) test_utils.wait_for_topic(config.PACKAGE_NAME, config.SERVICE_NAME, "authz.test") super_message = str(uuid.uuid4()) authorized_message = str(uuid.uuid4()) unauthorized_message = str(uuid.uuid4()) log.info("Writing and reading: Writing to the topic, as authorized user") assert write_to_topic("authorized", client_id, "authz.test", authorized_message) log.info("Writing and reading: Writing to the topic, as unauthorized user") assert write_to_topic("unauthorized", client_id, "authz.test", unauthorized_message) log.info("Writing and reading: Writing to the topic, as super user") assert write_to_topic("super", client_id, "authz.test", super_message) log.info("Writing and reading: Reading from the topic, as authorized user") assert authorized_message in read_from_topic("authorized", client_id, "authz.test", 3) log.info("Writing and reading: Reading from the topic, as unauthorized user") assert unauthorized_message in read_from_topic("unauthorized", client_id, "authz.test", 3) log.info("Writing and reading: Reading from the topic, as super user") assert super_message in read_from_topic("super", client_id, "authz.test", 3) log.info("Writing and reading: Adding acl for authorized user") zookeeper_endpoint = str(sdk_cmd.svc_cli( config.PACKAGE_NAME, config.SERVICE_NAME, "endpoint zookeeper")).strip() topics.add_acls("authorized", client_id, "authz.test", zookeeper_endpoint, env_str=None) # Re-roll the messages so we really prove auth is in place. super_message = str(uuid.uuid4()) authorized_message = str(uuid.uuid4()) unauthorized_message = str(uuid.uuid4()) log.info("Writing and reading: Writing to the topic, as authorized user") assert write_to_topic("authorized", client_id, "authz.test", authorized_message) log.info("Writing and reading: Writing to the topic, as unauthorized user") assert not write_to_topic("unauthorized", client_id, "authz.test", unauthorized_message) log.info("Writing and reading: Writing to the topic, as super user") assert write_to_topic("super", client_id, "authz.test", super_message) log.info("Writing and reading: Reading from the topic, as authorized user") read_result = read_from_topic("authorized", client_id, "authz.test", 5) assert authorized_message in read_result and unauthorized_message not in read_result log.info("Writing and reading: Reading from the topic, as unauthorized user") assert auth.is_not_authorized(read_from_topic("unauthorized", client_id, "authz.test", 1)) log.info("Writing and reading: Reading from the topic, as super user") read_result = read_from_topic("super", client_id, "authz.test", 5) assert super_message in read_result and unauthorized_message not in read_result finally: sdk_install.uninstall(config.PACKAGE_NAME, config.SERVICE_NAME)
def test_authz_acls_required(kafka_client, kafka_server): client_id = kafka_client["id"] auth.wait_for_brokers(kafka_client["id"], kafka_client["brokers"]) topic_name = "authz.test" sdk_cmd.svc_cli(kafka_server["package_name"], kafka_server["service"]["name"], "topic create {}".format(topic_name), json=True) test_utils.wait_for_topic(kafka_server["package_name"], kafka_server["service"]["name"], topic_name) message = str(uuid.uuid4()) log.info("Writing and reading: Writing to the topic, but not super user") assert not auth.write_to_topic("authorized", client_id, topic_name, message) log.info("Writing and reading: Writing to the topic, as super user") assert auth.write_to_topic("super", client_id, topic_name, message) log.info("Writing and reading: Reading from the topic, but not super user") assert auth.is_not_authorized( auth.read_from_topic("authorized", client_id, topic_name, 1)) log.info("Writing and reading: Reading from the topic, as super user") assert message in auth.read_from_topic("super", client_id, topic_name, 1) zookeeper_endpoint = sdk_cmd.svc_cli(kafka_server["package_name"], kafka_server["service"]["name"], "endpoint zookeeper").strip() # TODO: If zookeeper has Kerberos enabled, then the environment should be changed topics.add_acls("authorized", client_id, topic_name, zookeeper_endpoint, env_str=None) # Send a second message which should not be authorized second_message = str(uuid.uuid4()) log.info("Writing and reading: Writing to the topic, but not super user") assert auth.write_to_topic("authorized", client_id, topic_name, second_message) log.info("Writing and reading: Writing to the topic, as super user") assert auth.write_to_topic("super", client_id, topic_name, second_message) log.info("Writing and reading: Reading from the topic, but not super user") topic_output = auth.read_from_topic("authorized", client_id, topic_name, 3) assert message in topic_output assert second_message in topic_output log.info("Writing and reading: Reading from the topic, as super user") topic_output = auth.read_from_topic("super", client_id, topic_name, 3) assert message in topic_output assert second_message in topic_output # Check that the unauthorized client can still not read or write from the topic. log.info("Writing and reading: Writing to the topic, but not super user") assert not auth.write_to_topic("unauthorized", client_id, topic_name, second_message) log.info("Writing and reading: Reading from the topic, but not super user") assert auth.is_not_authorized( auth.read_from_topic("unauthorized", client_id, topic_name, 1))
def add_acls(self, user: str, topic_name: str): service = self.kafka_service # TODO: If zookeeper has Kerberos enabled, then the environment should be changed environment = None topics.add_acls(user, self.id, topic_name, service.get_zookeeper_connect(), environment)