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:Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Enhancing Security
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.
Explanation of Changes
-
Security Context:
The newsecurityContextensures that the container does not run with elevated privileges by settingprivileged: falseand 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 anemptyDirvolume stored in memory. This approach is useful for non-persistent storage needs and enhances the overall configuration flexibility.
Applying the Configuration
After saving the updated configuration in yourdeployment.yaml file, you can apply the changes using the following command: