noqt commited on
Commit
ebdcf01
·
1 Parent(s): 24cd813

fix: validate legacy run records safely

Browse files
Files changed (1) hide show
  1. src/lumi_eggcracker/records.py +5 -4
src/lumi_eggcracker/records.py CHANGED
@@ -134,10 +134,11 @@ def validate_run(value: dict[str, Any]) -> dict[str, Any]:
134
  raise JsonInputError("run record executable is invalid")
135
  if not isinstance(value["argv_sha256"], str) or not re.fullmatch(r"[0-9a-f]{64}", value["argv_sha256"]):
136
  raise JsonInputError("run record command hash is invalid")
137
- if not isinstance(value["exec_policy_id"], str) or not value["exec_policy_id"]:
138
- raise JsonInputError("run record execution policy identity is invalid")
139
- if not isinstance(value["exec_policy_digest"], str) or not re.fullmatch(r"[0-9a-f]{64}", value["exec_policy_digest"]):
140
- raise JsonInputError("run record execution policy digest is invalid")
 
141
  keys = ("cgroup_device", "cgroup_inode", "created_monotonic_ns", "cpu_quota_percent", "max_memory_mib", "operator_uid", "workload_gid", "workload_uid", "max_pids", "argv_count")
142
  if any(isinstance(value[key], bool) or not isinstance(value[key], int) or value[key] < 0 for key in keys):
143
  raise JsonInputError("run record integer field is invalid")
 
134
  raise JsonInputError("run record executable is invalid")
135
  if not isinstance(value["argv_sha256"], str) or not re.fullmatch(r"[0-9a-f]{64}", value["argv_sha256"]):
136
  raise JsonInputError("run record command hash is invalid")
137
+ if set(value) == expected:
138
+ if not isinstance(value["exec_policy_id"], str) or not value["exec_policy_id"]:
139
+ raise JsonInputError("run record execution policy identity is invalid")
140
+ if not isinstance(value["exec_policy_digest"], str) or not re.fullmatch(r"[0-9a-f]{64}", value["exec_policy_digest"]):
141
+ raise JsonInputError("run record execution policy digest is invalid")
142
  keys = ("cgroup_device", "cgroup_inode", "created_monotonic_ns", "cpu_quota_percent", "max_memory_mib", "operator_uid", "workload_gid", "workload_uid", "max_pids", "argv_count")
143
  if any(isinstance(value[key], bool) or not isinstance(value[key], int) or value[key] < 0 for key in keys):
144
  raise JsonInputError("run record integer field is invalid")