|
134 | 134 | MAIN_CONTAINER_MAX_SCRIPT_CHARS = 160 |
135 | 135 | MAIN_CONTAINER_MAX_SCRIPT_COMMANDS = 2 |
136 | 136 | CONFIGMAP_DATA_KEY_RE = re.compile(r"^vn-[a-z0-9]+(?:vn-[a-z0-9]+)*$") |
| 137 | +OBJECT_STORAGE_INPUT_TEXT_RE = re.compile( |
| 138 | + r"\b(?:object\s*storage|objectstorage|s3|s3-compatible|bucket|binary\s+data|external\s+storage)\b", |
| 139 | + re.IGNORECASE, |
| 140 | +) |
| 141 | +LICENSE_GATED_TEXT_RE = re.compile( |
| 142 | + r"\b(?:enterprise|paid|commercial|premium|subscription|license|licensed|licence|licenced)\b", |
| 143 | + re.IGNORECASE, |
| 144 | +) |
137 | 145 | OBJECT_STORAGE_BRANCH_MARKER_RE = re.compile( |
138 | 146 | r"\b(?:ObjectStorageBucket|object-storage-key|object\s+storage|s3[_-]|aws_access_key_id|" |
139 | 147 | r"aws_secret_access_key|storage_s3|s3-compatible|bucket|bucket_name|minio)\b", |
|
152 | 160 | "ENABLE_S3_STORAGE", |
153 | 161 | "ENABLE_SEALOS_OBJECT_STORAGE", |
154 | 162 | "ENABLE_SEALOS_OBJECTSTORAGE", |
| 163 | + "ENABLE_S3", |
155 | 164 | "USE_OBJECT_STORAGE", |
| 165 | + "USE_MANAGED_OBJECT_STORAGE", |
| 166 | + "USE_MANAGED_S3", |
156 | 167 | "USE_SEALOS_OBJECT_STORAGE", |
157 | 168 | "USE_SEALOS_OBJECTSTORAGE", |
| 169 | + "USE_SEALOS_S3", |
158 | 170 | } |
159 | 171 | TEMPLATE_IF_RE = re.compile(r"\$\{\{\s*if\s*\((.*?)\)\s*\}\}") |
160 | 172 | TEMPLATE_ENDIF_RE = re.compile(r"\$\{\{\s*endif\(\)\s*\}\}") |
@@ -2295,6 +2307,105 @@ def _external_object_storage_source(doc: YamlDocument) -> str: |
2295 | 2307 | return value.strip() if isinstance(value, str) else "" |
2296 | 2308 |
|
2297 | 2309 |
|
| 2310 | +def _iter_template_inputs(spec: Dict[str, Any]) -> Iterable[Tuple[str, Any]]: |
| 2311 | + inputs = spec.get("inputs") |
| 2312 | + if isinstance(inputs, dict): |
| 2313 | + for name, input_spec in inputs.items(): |
| 2314 | + if isinstance(name, str): |
| 2315 | + yield name, input_spec |
| 2316 | + return |
| 2317 | + if isinstance(inputs, list): |
| 2318 | + for item in inputs: |
| 2319 | + if not isinstance(item, dict): |
| 2320 | + continue |
| 2321 | + name = item.get("name") |
| 2322 | + if isinstance(name, str): |
| 2323 | + yield name, item |
| 2324 | + |
| 2325 | + |
| 2326 | +def _template_input_text(name: str, input_spec: Any) -> str: |
| 2327 | + parts = [name] |
| 2328 | + if isinstance(input_spec, dict): |
| 2329 | + for key in ("label", "title", "description", "default", "value"): |
| 2330 | + value = input_spec.get(key) |
| 2331 | + if isinstance(value, str): |
| 2332 | + parts.append(value) |
| 2333 | + elif isinstance(input_spec, str): |
| 2334 | + parts.append(input_spec) |
| 2335 | + return "\n".join(parts) |
| 2336 | + |
| 2337 | + |
| 2338 | +def _object_storage_branch_inputs_by_path(context: ScanContext) -> Dict[Path, set[str]]: |
| 2339 | + inputs_by_path: Dict[Path, set[str]] = {} |
| 2340 | + for path in _iter_template_artifact_paths(context): |
| 2341 | + text = context.file_texts.get(path, "") |
| 2342 | + lines = text.splitlines() |
| 2343 | + for index, line in enumerate(lines): |
| 2344 | + match = TEMPLATE_IF_RE.search(line) |
| 2345 | + if match is None: |
| 2346 | + continue |
| 2347 | + input_names = _condition_input_refs(match.group(1)) |
| 2348 | + if not input_names: |
| 2349 | + continue |
| 2350 | + branch_end = _find_branch_end(lines, index) |
| 2351 | + branch_text = "\n".join(lines[index: branch_end + 1]) |
| 2352 | + if not _branch_uses_object_storage(branch_text): |
| 2353 | + continue |
| 2354 | + inputs_by_path.setdefault(path, set()).update(input_names) |
| 2355 | + return inputs_by_path |
| 2356 | + |
| 2357 | + |
| 2358 | +def _input_declaration_line(doc: YamlDocument, input_name: str) -> int: |
| 2359 | + escaped = re.escape(input_name) |
| 2360 | + inputs_line = doc.line_locator.find(r"^\s*inputs\s*:", default=doc.start_line) |
| 2361 | + list_name_line = doc.line_locator.find( |
| 2362 | + rf"^\s*name\s*:\s*['\"]?{escaped}['\"]?\s*$", |
| 2363 | + default=inputs_line, |
| 2364 | + ) |
| 2365 | + return doc.line_locator.find(rf"^\s*{escaped}\s*:", default=list_name_line) |
| 2366 | + |
| 2367 | + |
| 2368 | +def check_license_gated_object_storage_options(context: ScanContext) -> List[Violation]: |
| 2369 | + violations: List[Violation] = [] |
| 2370 | + object_storage_branch_inputs = _object_storage_branch_inputs_by_path(context) |
| 2371 | + |
| 2372 | + for doc in _iter_template_artifact_documents(context): |
| 2373 | + spec = doc.data.get("spec") if isinstance(doc.data, dict) else None |
| 2374 | + if not isinstance(spec, dict): |
| 2375 | + continue |
| 2376 | + branch_inputs = object_storage_branch_inputs.get(doc.path, set()) |
| 2377 | + |
| 2378 | + for input_name, input_spec in _iter_template_inputs(spec): |
| 2379 | + input_text = _template_input_text(input_name, input_spec) |
| 2380 | + if LICENSE_GATED_TEXT_RE.search(input_text) is None: |
| 2381 | + continue |
| 2382 | + |
| 2383 | + normalized_name = _normalize_template_input_name(input_name) |
| 2384 | + is_object_storage_input = ( |
| 2385 | + input_name in branch_inputs |
| 2386 | + or normalized_name in MANAGED_OBJECT_STORAGE_TOGGLE_NAMES |
| 2387 | + or EXTERNAL_OBJECT_STORAGE_INPUT_RE.search(normalized_name) is not None |
| 2388 | + or OBJECT_STORAGE_INPUT_TEXT_RE.search(input_text) is not None |
| 2389 | + ) |
| 2390 | + if not is_object_storage_input: |
| 2391 | + continue |
| 2392 | + |
| 2393 | + violations.append( |
| 2394 | + Violation( |
| 2395 | + rule_id="R049", |
| 2396 | + path=doc.path, |
| 2397 | + line=_input_declaration_line(doc, input_name), |
| 2398 | + message=( |
| 2399 | + "license-gated object storage/S3 features must not be exposed as standard " |
| 2400 | + "public-template inputs; use the community-supported filesystem/PVC mode " |
| 2401 | + "or create a dedicated enterprise template only when explicitly requested" |
| 2402 | + ), |
| 2403 | + ) |
| 2404 | + ) |
| 2405 | + |
| 2406 | + return violations |
| 2407 | + |
| 2408 | + |
2298 | 2409 | def check_external_object_storage_inputs(context: ScanContext) -> List[Violation]: |
2299 | 2410 | violations: List[Violation] = [] |
2300 | 2411 | object_storage_paths = { |
@@ -3095,6 +3206,7 @@ def _container_requires_image_pull_secret(container: Dict[str, Any]) -> bool: |
3095 | 3206 | "R044": Rule("R044", check_optional_object_storage_uses_boolean_input), |
3096 | 3207 | "R045": Rule("R045", check_template_input_references_declared), |
3097 | 3208 | "R047": Rule("R047", check_external_object_storage_inputs), |
| 3209 | + "R049": Rule("R049", check_license_gated_object_storage_options), |
3098 | 3210 | "R031": Rule("R031", check_ingress_name_matches_backends), |
3099 | 3211 | "R026": Rule("R026", check_http_ingress_annotations), |
3100 | 3212 | "R048": Rule("R048", check_websocket_ingress_annotations), |
|
0 commit comments