From d4bbce9c5be3e96788f40fde664d50ae8329cfc4 Mon Sep 17 00:00:00 2001 From: droctothorpe Date: Tue, 16 Jul 2024 15:06:33 -0400 Subject: [PATCH] Add namespace tag handling and validation Signed-off-by: droctothorpe Co-authored-by: andreafehrman Co-authored-by: owmasch --- frontend/server/workflow-helper.ts | 32 +++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/frontend/server/workflow-helper.ts b/frontend/server/workflow-helper.ts index a3da670b2ed7..edc6903148d6 100644 --- a/frontend/server/workflow-helper.ts +++ b/frontend/server/workflow-helper.ts @@ -135,22 +135,44 @@ export function createPodLogsMinioRequestConfig( bucket: string, keyFormat: string, ) { - // TODO: support pod log artifacts for diff namespace. - // different bucket/prefix for diff namespace? - return async (podName: string, createdAt: string, _namespace?: string): Promise => { + return async (podName: string, createdAt: string, namespace: string = ''): Promise => { // create a new client each time to ensure session token has not expired const client = await createMinioClient(minioOptions, 's3'); const createdAtArray = createdAt.split("-") + let key: string = keyFormat .replace("{{workflow.name}}", podName.replace(/-system-container-impl-.*/, '')) .replace("{{workflow.creationTimestamp.Y}}", createdAtArray[0]) .replace("{{workflow.creationTimestamp.m}}", createdAtArray[1]) .replace("{{workflow.creationTimestamp.d}}", createdAtArray[2]) .replace("{{pod.name}}", podName) - // TODO: Add namespace tag replacement. - key = key + "/main.log" + .replace("{{workflow.namespace}}", namespace) + + if (!key.endsWith("/")) { + key = key + "/" + } + key = key + "main.log" + console.log("keyFormat: ", keyFormat) console.log("key: ", key) + + // If there are unresolved template tags in the keyFormat, throw an error + // that surfaces in the frontend's console log. + if (key.includes("{") || key.includes("}")) { + throw new Error( + `keyFormat, which is defined in config.ts or through the ARGO_KEYFORMAT env var, appears to include template tags that are not supported. ` + + `The resulting log key, ${key}, includes unresolved template tags and is therefore invalid.` + ) + } + + const regex = /^[a-zA-Z0-9\-._/]+$/; // Allow letters, numbers, -, ., _, / + if (!regex.test(key)) { + throw new Error( + `The log key, ${key}, which is derived from keyFormat in config.ts or through the ARGO_KEYFORMAT env var, is an invalid path. ` + + `Supported characters include: letters, numbers, -, ., _, and /.` + ) + } + return { bucket, client, key }; }; }