From dec6a29086ad1ee8ca2bd80b89336e0cbda741f1 Mon Sep 17 00:00:00 2001 From: Prowler Bot Date: Thu, 29 May 2025 08:55:00 +0200 Subject: [PATCH] fix(k8s): UID validation for valid context names (#7880) Co-authored-by: Pepe Fagoaga --- api/CHANGELOG.md | 1 + api/src/backend/api/models.py | 2 +- api/src/backend/api/tests/test_views.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/api/CHANGELOG.md b/api/CHANGELOG.md index 8a5c0149e9..f847a289e9 100644 --- a/api/CHANGELOG.md +++ b/api/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to the **Prowler API** are documented in this file. ### Fixed - Fixed task lookup to use task_kwargs instead of task_args for scan report resolution. [(#7830)](https://github.com/prowler-cloud/prowler/pull/7830) +- Fixed Kubernetes UID validation to allow valid context names [(#7871)](https://github.com/prowler-cloud/prowler/pull/7871) --- diff --git a/api/src/backend/api/models.py b/api/src/backend/api/models.py index a427bcf9c9..63a2cd38e8 100644 --- a/api/src/backend/api/models.py +++ b/api/src/backend/api/models.py @@ -242,7 +242,7 @@ class Provider(RowLevelSecurityProtectedModel): @staticmethod def validate_kubernetes_uid(value): if not re.match( - r"^[a-z0-9][A-Za-z0-9_.:\/-]{1,250}$", + r"^[a-zA-Z0-9][a-zA-Z0-9._@:\/-]{1,250}$", value, ): raise ModelValidationError( diff --git a/api/src/backend/api/tests/test_views.py b/api/src/backend/api/tests/test_views.py index 677f9437a6..d9a8b13835 100644 --- a/api/src/backend/api/tests/test_views.py +++ b/api/src/backend/api/tests/test_views.py @@ -914,6 +914,16 @@ class TestProviderViewSet: "uid": "gke_aaaa-dev_europe-test1_dev-aaaa-test-cluster-long-name-123456789", "alias": "GKE", }, + { + "provider": "kubernetes", + "uid": "gke_project/cluster-name", + "alias": "GKE", + }, + { + "provider": "kubernetes", + "uid": "admin@k8s-demo", + "alias": "test", + }, { "provider": "azure", "uid": "8851db6b-42e5-4533-aa9e-30a32d67e875",