This article reviews the CartsDB deployment, focusing on enhancing security by configuring a non-privileged mode and a read-only root filesystem.
In this article, we review our trusted CartsDB deployment—a deployment favored for its frequent use in our environment. Initially, when inspecting the containers section of the deployment, you may notice that no security context is configured. This is expected for the initial setup.Below is the original YAML snippet for the CartsDB container configuration:
One potential issue with the current configuration is that the container could run with elevated privileges. In Kubernetes, running a container in privileged mode gives it enhanced access to system resources, which could expose your system to vulnerabilities. For enhanced security, containers that do not require root-level permissions should run in a non-privileged mode.
The updated configuration below includes a security context that explicitly disables privileged access and sets the root filesystem as read-only. This additional safeguard minimizes the risk of unauthorized changes if the container is compromised.
To address these security concerns, update the deployment with the following enhanced YAML configuration:
Security Context:
The new securityContext ensures that the container does not run with elevated privileges by setting privileged: false and by enforcing a read-only root filesystem (readOnlyRootFilesystem: true). This reduces the risk of security breaches by limiting unnecessary access to the system.
Additional Environment Variables and Volume Mounts:
An extra environment variable (MONGODB_ADMIN_PASSWORD) is added for administrative operations. Additionally, a volume mount is configured to use a temporary directory (/tmp) backed by an emptyDir volume stored in memory. This approach is useful for non-persistent storage needs and enhances the overall configuration flexibility.
Once applied, verify that the CartsDB deployment is running with the enhanced security context by checking the OpenShift UI under Workloads > Deployments.By following these steps, you have successfully implemented a more secure deployment for CartsDB, ensuring that the containers run with non-privileged settings and a read-only root filesystem. For further reading on Kubernetes security best practices, consider visiting the Kubernetes Documentation.