Skip to content

Commit bbe245c

Browse files
authored
Merge pull request #18 from onyx-dot-app/kube_rbac
fix: kubernetes exectutor health check uses out-of-scope command
2 parents 212e392 + be36d9c commit bbe245c

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

code-interpreter/app/services/executor_kubernetes.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,33 @@ def __init__(self) -> None:
8181
self.service_account = KUBERNETES_EXECUTOR_SERVICE_ACCOUNT
8282

8383
def check_health(self) -> HealthCheck:
84-
"""Verify Kubernetes API is reachable and the namespace is accessible."""
84+
"""Verify Kubernetes API is reachable and we can create pods in the namespace."""
8585
try:
86-
self.v1.read_namespace(name=self.namespace)
86+
auth_api = client.AuthorizationV1Api()
87+
review = auth_api.create_self_subject_access_review(
88+
body=client.V1SelfSubjectAccessReview(
89+
spec=client.V1SelfSubjectAccessReviewSpec(
90+
resource_attributes=client.V1ResourceAttributes(
91+
namespace=self.namespace,
92+
verb="create",
93+
resource="pods",
94+
)
95+
)
96+
)
97+
)
98+
if not review.status.allowed:
99+
reason = review.status.reason or "no reason provided"
100+
logger.warning(
101+
f"Health check failed: cannot create pods in namespace={self.namespace} "
102+
f"(reason={reason})"
103+
)
104+
return HealthCheck(
105+
status="error",
106+
message=(
107+
"Service account lacks permission to create "
108+
f"pods in namespace={self.namespace}"
109+
),
110+
)
87111
except ApiException as e:
88112
return HealthCheck(
89113
status="error",

0 commit comments

Comments
 (0)