Document K8s worker identity and simplify deploy env guidance - #2
Document K8s worker identity and simplify deploy env guidance#2gummy789j wants to merge 1 commit into
Conversation
- Add SECURITY.md section on Kubernetes worker process identity - Remove redundant backend/.env.production; point gce-setup.sh at .env.example - Replace k8s instancer security TODO with pointers to SECURITY.md - Minor: reorder TYPE_CHECKING imports in MCP API key middleware Made-with: Cursor
Code Review ReportProject: evmbench-mcp-server PR OverviewBranch Information
Commit History
Review SummaryVerdict
Findings at a Glance
SummaryThis is a focused security housekeeping PR with a single commit covering three coherent concerns: (1) transparent documentation of the known root-privilege issue in the Kubernetes instancer, (2) removal of the The overall direction is positive. Deleting Two minor issues and two suggestions are raised below. None are blockers. The most actionable item is ensuring the GCE deployment script provides sufficiently strong guidance when it directs users to copy a file explicitly labelled "local development defaults" onto a production server. Change Summary1. Security Documentation — SECURITY.md
Purpose: Proactively discloses that K8s worker pods currently run as root (because the base image does not define a non-root 2. Production Env Template Removal — backend/.env.production
Purpose: Eliminates a duplicate template file. The surviving 3. K8s Backend Code Cleanup — backend/instancer/backends/k8s.py
Purpose: Removes the confusing 4. Auth Module Import Re-ordering — backend/api/mcp/auth.py
Purpose: Cosmetic import ordering improvement — groups imports before runtime constants, following standard Python convention. No behavioural change. 5. GCE Setup Script Reference Update — deploy/gce-setup.sh
Purpose: Keeps the deployment guide consistent after the deletion of Detailed FindingsMinor[MN-01] GCE deploy script directs users to a file labelled "local development defaults"
Description
Code # deploy/gce-setup.sh line 11
# - backend/.env copied from .env.example and filled with production secrets
# deploy/gce-setup.sh line 101
echo " cp .env.example .env # then edit with real secrets"Recommendation
[MN-02] Pod-level
|
| Property | Value |
|---|---|
| Severity | Minor |
| Category | Correctness |
| File | backend/instancer/backends/k8s.py : Lines 226-228 |
Description
The
specfield ofV1PodSpecexpects itssecurity_contextto be of typeV1PodSecurityContext(pod-level), notV1SecurityContext(container-level). These two types have different fields: e.g.,fsGroupandsupplemental_groupsare pod-level fields only available onV1PodSecurityContext.Although the Kubernetes Python client is dynamically typed and will not raise a runtime
TypeError, the serialised pod manifest may not include anysecurityContextat the pod level (or may emit an unexpected structure), causing silent no-ops when operators later try to add fields likefsGroup.This pre-existed
main, but the PR directly modifies this line by simplifying the instantiation. Since the PR's stated hardening path (SECURITY.md) depends on settingrunAsNonRoot/fsGroupvia this exact context object, using the correct type now prevents a subtle future bug.
Code
# backend/instancer/backends/k8s.py line 226-228 (after PR)
spec=client.V1PodSpec(
automount_service_account_token=False,
# Pod runs as root until the worker image supports a non-root USER; see SECURITY.md
security_context=client.V1SecurityContext(), # ← should be V1PodSecurityContextRecommendation
Switch to the correct pod-level type so that future hardening fields serialise correctly:
security_context=client.V1PodSecurityContext(),When the worker image gains a non-root USER, the fields to add are:
security_context=client.V1PodSecurityContext( run_as_non_root=True, run_as_user=65534, run_as_group=65534, fs_group=65534, ),
Suggestions
[S-01] Workers run as root — consider a tracking issue
File: backend/instancer/backends/k8s.py, SECURITY.md
Description: The SECURITY.md addition transparently documents that worker pods run as root and provides a hardening path. However, there is no corresponding tracking issue or milestone reference in either the SECURITY.md text or the inline comment. This makes it easy for the remediation to slip through future prioritisation.
Suggestion: Add a TODO(#<issue-number>) reference in the inline comment once a tracking issue exists. Example:
# Pod runs as root until the worker image supports a non-root USER; see SECURITY.md
# and TODO(#42). Enable runAsNonRoot/runAsUser/fsGroup when the image does.[S-02] SECRETSVC_TOKEN is injected as a plain environment variable rather than a K8s Secret
File: backend/instancer/backends/k8s.py : Line 197
Description: The read-only secrets-service token is passed to worker pods as a plain env var. This is called out in an existing inline comment (# technically, we should pass the secretsvc token as a secret ref instead). This is not changed by the PR, but the PR's stated goal is security hardening, making it a natural related item.
Suggestion: Follow through on the inline TODO by projecting the token via a K8s Secret mounted as an env var (secretKeyRef) rather than a literal string, so the value is managed by the control plane and does not appear in pod spec manifests or audit logs. Track this alongside S-01.
Positive Observations
| Area | Observation |
|---|---|
| Security transparency | The new SECURITY.md section is candid, well-structured, and actionable — it documents both why the limitation exists and exactly what operators must do to resolve it when the image changes |
| Dead-code removal | Replacing 7 lines of commented-out code with a single explanatory comment and a cross-reference to documentation is the right trade-off; it removes clutter without losing context |
| Import hygiene | Moving TYPE_CHECKING imports above runtime constants follows the conventional Python import order and removes a minor inconsistency |
| Secret surface reduction | Deleting backend/.env.production from version control removes a file that could be mistaken for a live secrets file, reducing the risk of accidental exposure or trust of stale values |
| Existing hardening retained | automount_service_account_token=False, namespace isolation per job, and egress network policies (all unchanged by this PR) remain in place and represent strong baseline isolation |
Checklist Results
| Category | Items Checked | Pass | Fail | N/A | Notes |
|---|---|---|---|---|---|
| Correctness | 4 | 3 | 1 | 4 | MN-02: wrong security context type |
| Security | 8 | 6 | 0 | 2 | Dev template in prod guide (MN-01); root worker documented but unresolved (S-01) |
| Performance | 7 | 0 | 0 | 7 | No performance-relevant changes |
| Code Quality | 6 | 6 | 0 | 0 | Dead-code removal and import ordering are positive |
| Testing | 5 | 0 | 0 | 5 | No test changes; no new logic requiring tests |
| Documentation | 4 | 4 | 0 | 0 | SECURITY.md addition is clear and thorough |
| Compatibility | 5 | 5 | 0 | 0 | No API or schema changes |
| Observability | 4 | 0 | 0 | 4 | No observability changes |
Disclaimer
This is an automated code review. It supplements but does not replace human review. The reviewer analysed only the diff between main and chore/security-k8s-deploy-cleanup. Runtime behaviour, integration testing, and deployment impact are not covered.
Report generated by Code Review Skill v1.0.0
Date: 2026-04-01
Uh oh!
There was an error while loading. Please reload this page.