Merge "Protection from invalid label values."

This commit is contained in:
Zuul 2023-09-08 16:17:32 +00:00 committed by Gerrit Code Review
commit 583c9c5274
2 changed files with 27 additions and 4 deletions

View File

@ -212,6 +212,14 @@ class LabelController(rest.RestController):
LOG.info("patch_data: %s" % body)
host = objects.host.get_by_uuid(pecan.request.context, uuid)
# Probably will never happen, but add an extra guard to be absolutely
# sure no null values make it into the database.
for key, value in body.items():
if value is None:
raise wsme.exc.ClientSideError(
_("Null input detected for Label %s for host %s. Input invalid." % (
key, host.hostname)))
_check_host_locked(host, body.keys())
_semantic_check_worker_labels(body)
@ -247,11 +255,13 @@ class LabelController(rest.RestController):
new_records = []
for key, value in body.items():
values = {
'host_id': host.id,
'label_key': key,
'label_value': value
}
try:
if existing_labels.get(key, None):
# Update the value

View File

@ -472,13 +472,26 @@ class KubernetesPuppet(base.BasePuppet):
}
def _get_host_label_config(self, host):
config = {}
labels = self.dbapi.label_get_by_host(host.uuid)
host_label_keys = []
config = {}
for label in labels:
host_label_keys.append(label.label_key + "=" + label.label_value)
config.update(
{'platform::kubernetes::params::host_labels': host_label_keys})
# Guard against NoneType
if label.label_key and label.label_value:
kv_pair = label.label_key + "=" + label.label_value
host_label_keys.append(kv_pair)
if len(host_label_keys) == 0:
LOG.warning(
"KubernetesPuppet._get_host_label_config: No host labels found. "
)
# Defaults to an empty list if no labels are found.
config = \
{'platform::kubernetes::params::host_labels': host_label_keys}
return config
def _get_host_k8s_certificates_config(self, host):