From c892af5a1e03a24e474543db5fcbbc369218a578 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 9 May 2025 09:34:19 -0400 Subject: [PATCH] Implement 8 character max for attribute formatting When trying to set a node or group attribute, evaluate length of any potential formatting specification to keep it under 8 characters. This should prevent even temporary expansion over 10MB for an attribute on the way to setting it. --- confluent_server/confluent/config/configmanager.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/confluent_server/confluent/config/configmanager.py b/confluent_server/confluent/config/configmanager.py index 58b1f167..999e9150 100644 --- a/confluent_server/confluent/config/configmanager.py +++ b/confluent_server/confluent/config/configmanager.py @@ -132,6 +132,16 @@ _validroles = ['Administrator', 'Operator', 'Monitor', 'Stub'] membership_callback = None + +class ExpressionChecker(string.Formatter): + def format_field(self, val, format_spec): + if len(format_spec) > 8: + raise Exception(f'Format specification {format_spec} exceeds maximum supported length of 8') + return '1' + + def get_value(self, first, args, kwargs): + return 1 + def attrib_supports_expression(attrib): if not isinstance(attrib, str): attrib = attrib.decode('utf8') @@ -1925,6 +1935,8 @@ class ConfigManager(object): curr[attrib]['value']) if 'value' in curr[attrib]: del curr[attrib]['value'] + if 'expression' in curr[attrib]: + ExpressionChecker().format(curr[attrib]['expression']) if cfgleader: # currently config slave to another return exec_on_leader('_rpc_master_set_group_attributes', self.tenant, attribmap, autocreate) @@ -2374,6 +2386,8 @@ class ConfigManager(object): for node in attribmap: curr = attribmap[node] for attrib in curr: + if 'expression' in curr[attrib]: + ExpressionChecker().format(curr[attrib]['expression']) if attrib.startswith('crypted.'): if not isinstance(curr[attrib], dict): curr[attrib] = {'value': curr[attrib]}