Issue
A Kubernetes pod running the MCP server crashed with a PermissionError when attempting to write audit logs to /var/log/mcp-server. The error occurred because the container ran as a non-root user (UID 1000) without write permissions to the host’s /var/log directory, despite the existence of a writable emptyDir volume at /app/logs.
Culprit
The issue stemmed from:
- Hardcoded log path: The application targeted
/var/log/mcp-server, a directory owned byroot:rootwith755permissions, which is inaccessible to non-root users. - Unused volume: While an
emptyDirvolume was mounted at/app/logswith read-write permissions, the application was not configured to use this volume for logging. - Missing ConfigMap: There was no environment variable override in the ConfigMap to redirect the log path to the writable volume.
Solution
Redirect Log Path
Updated the ConfigMap to include an environment variable redirecting the log path to the writable emptyDir volume:
- Log Path: Changed from
/var/log/mcp-serverto/app/logs/audit.logto leverage the writable volume. - Permissions: Utilized the
emptyDirvolume (defaultrwpermissions) to ensure the non-root user could write logs. - Security: Maintained the non-root security context (UID 1000) without privilege escalation.
This solution resolved the permission-related crashes, ensuring audit logs were written successfully and the pod remained stable while adhering to least-privilege security practices.