Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Replace hostPath volumes with ephemeral volumes #343

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

PNarode
Copy link
Contributor

@PNarode PNarode commented Feb 11, 2025

Summary by CodeRabbit

  • Chores
    • Updated the operator release version from 0.26.4 to 0.26.5.
  • New Features
    • Enhanced deployment security by enforcing non-root execution with secure defaults.
    • Improved management of logs and container data by optimizing volume handling.

Copy link

coderabbitai bot commented Feb 11, 2025

Walkthrough

This pull request updates two configuration files. The Chart.yaml file for the operator-wandb Helm chart now reflects a version change from 0.26.4 to 0.26.5. Additionally, the deamonset.yaml file has been modified to incorporate a security context enforcing non-root execution and to update volume mounts and definitions—shifting from host-based mounts to ephemeral emptyDir volumes.

Changes

File(s) Summary
charts/operator-wandb/Chart.yaml Updated chart version from 0.26.4 to 0.26.5.
charts/operator-wandb/charts/otel/charts/agent/templates/deamonset.yaml Added a securityContext (non-root with default seccomp), removed host mounts, and updated volume mounts/definitions to use emptyDir volumes for logs and data.

Possibly related PRs

Suggested reviewers

  • vanpelt
  • jsbroks
  • danielpanzella

Poem

Hopping through the lines of code with glee,
I found new security for you and me.
Versions updated, volumes remade,
In config fields my hops displayed.
A bunny's cheer in every byte,
CodeRabbit Inc. makes it right!
🐰✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@PNarode PNarode changed the title Pnarode/host path changes feat: Replace hostPath volumes with ephemeral volumes Feb 11, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
charts/operator-wandb/charts/otel/charts/agent/templates/deamonset.yaml (1)

125-128: Consider impact of emptyDir on log persistence.

The switch from hostPath to emptyDir volumes improves security but introduces some considerations:

  1. emptyDir volumes are ephemeral and cleared when the pod is removed
  2. This might affect log persistence and collection if the agent pod restarts
  3. Ensure your log collection pipeline can handle potential gaps in log data

Consider documenting the trade-offs of this security improvement in your runbook.

Would you like me to help draft documentation explaining the impact of this change on log collection?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a57e957 and a8a3864.

📒 Files selected for processing (2)
  • charts/operator-wandb/Chart.yaml (1 hunks)
  • charts/operator-wandb/charts/otel/charts/agent/templates/deamonset.yaml (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • charts/operator-wandb/Chart.yaml
🔇 Additional comments (2)
charts/operator-wandb/charts/otel/charts/agent/templates/deamonset.yaml (2)

39-42: Security enhancement looks good but needs verification.

The addition of security context with runAsNonRoot and default seccomp profile is a great security improvement. However, please verify that the OpenTelemetry agent can function correctly without root privileges, especially for its monitoring capabilities.

✅ Verification successful

🌐 Web query:

Can OpenTelemetry agent run as non-root user?

💡 Result:

Yes, OpenTelemetry agents can generally run as non-root users, but configuration adjustments may be required depending on the deployment environment and specific components used. Here are key considerations:

Core Capabilities

  • Non-root operation is explicitly recommended by OpenTelemetry security guidelines[4][5] and supported by major distributions like Splunk[3][5].
  • Linux capabilities like cap_dac_read_search (bypass file/directory permission checks) and cap_sys_ptrace (process tracing) allow operation without full root privileges[3].

Implementation Requirements

Environment Requirements
Linux/macOS Use setcap to grant minimal capabilities[3]:
setcap CAP_SYS_PTRACE,CAP_DAC_READ_SEARCH=+eip /path/to/otelcol
Docker/K8s - Avoid --privileged flag
- Set user in Dockerfile (USER 1001)
- Use securityContext in Kubernetes[6][8]
Host Metrics Some metrics collection may require elevated privileges[1]

Security Best Practices

  1. Never run as root/admin - Explicitly prohibited in production environments[4][5]
  2. Use dedicated service accounts with least-privilege access[5][8]
  3. For auto-instrumentation requiring elevated privileges (e.g., Go), isolate using:
    securityContext:
      privileged: true
      runAsUser: 0  # Only when absolutely necessary[8]

Configuration Examples

Docker non-root setup[9]:

FROM otel/opentelemetry-collector-contrib:0.118.0
USER 1001:1001

Kubernetes Security Context[8]:

securityContext:
  capabilities:
    add: ["CAP_DAC_READ_SEARCH", "CAP_SYS_PTRACE"]
  runAsUser: 1001
  allowPrivilegeEscalation: false

While most components work without root access, verify receiver/exporter requirements and test functionality under reduced privileges[3][5]. Proper capability management allows secure operation while maintaining observability pipeline integrity.

Citations:


Security Context Verified – Non-Root Operation is Supported

The web query confirms that OpenTelemetry agents can operate as non-root users. The security context addition using runAsNonRoot: true and the default seccomp profile is aligned with best practices for safer container deployments. Please ensure that any specific capability requirements are met if your setup collects host metrics or requires additional Linux capabilities.


115-117: Verify metrics collection with new volume mounts.

The switch to mounting /var/lib/containers suggests a move to support CRI-O/containerd instead of Docker. Please verify:

  1. The OpenTelemetry agent can still collect all required container metrics
  2. The read-only mount is sufficient for metrics collection
  3. This change supports your container runtime (Docker/containerd/CRI-O)
✅ Verification successful

🌐 Web query:

What container log paths does OpenTelemetry agent support for different container runtimes (Docker, containerd, CRI-O)?

💡 Result:

The OpenTelemetry Collector supports different log paths depending on the container runtime and environment configuration:

Container Runtime Log Paths

Docker (Standalone)

  • Default path: /var/lib/docker/containers/<container_id>/<container_id>-json.log
    Supports JSON-formatted Docker logs through Filelog receiver configuration[6][10]

Kubernetes Environments (All Runtimes)

  • Unified collection path: /var/log/pods/*/*/*.log
    Captures logs from Docker/containerd/CRI-O through Kubernetes pod logging architecture[1][9]

CRI-O Specific

  • Uses CRI logging format stored in Kubernetes pod paths
    Example log line format:
    2024-04-13T07:59:37.505201169-05:00 stdout F This is a cri-o log line![1][4]

Containerd

  • Follows CRI format similar to CRI-O
    Example path in non-Kubernetes environments:
    ~/Library/Containers/com.docker.docker/Data/log/vm/containerd.log (macOS)[10]

Configuration Examples

For Kubernetes environments:

receivers:
  filelog:
    include: [/var/log/pods/*/*/*.log]
    operators:
      - type: container

For standalone Docker:

receivers:
  filelog:
    include: [/var/lib/docker/containers/*/*.log]

The new container parser operator automatically detects formats (Docker JSON vs CRI) and handles partial log recombination[1][9]. Metadata extraction from file paths includes Kubernetes attributes like pod name, namespace, and container restart count when using Kubernetes paths[1].

For system-level runtime logging (dockerd/containerd daemons), OpenTelemetry can collect from:

  • /var/log/dockerd.log (Linux)
  • %LOCALAPPDATA%\Docker\log\vm\dockerd.log (Windows)[10]

Citations:


Ensure OpenTelemetry Agent Collects Logs Correctly with the New Mount

Based on the web query, the OpenTelemetry Collector supports different log paths depending on the container runtime. The new mount (/var/lib/containers) is consistent with setups using containerd or CRI-O—runtimes that typically use different logging locations than Docker. In this configuration:

  • The read-only mount is generally sufficient, as the agent only needs to read the log files.
  • If your environment relies on containerd or CRI-O, this change should maintain proper metrics collection.
  • However, if using Docker, note that Docker’s default log location is usually /var/lib/docker/containers, so you may need additional configuration adjustments for docker-based log collection.

Please verify that your OpenTelemetry agent configuration (e.g., filelog receiver paths) aligns with the intended log location for your specific runtime.

Copy link

coderabbitai bot commented Feb 11, 2025

✅ Actions performed

Full review triggered.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
charts/operator-wandb/charts/otel/charts/agent/templates/deamonset.yaml (1)

125-128: Consider log persistence requirements with emptyDir volumes.

The switch to emptyDir volumes improves security by removing host filesystem access. However, be aware that:

  1. Data in emptyDir volumes is ephemeral and will be lost when the pod is deleted
  2. This could affect log collection if the pod restarts frequently

Please verify that this aligns with your log retention and collection requirements.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8a3864 and 069ef0d.

📒 Files selected for processing (2)
  • charts/operator-wandb/Chart.yaml (1 hunks)
  • charts/operator-wandb/charts/otel/charts/agent/templates/deamonset.yaml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • charts/operator-wandb/Chart.yaml
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test Chart (v1.30.8, default)
  • GitHub Check: Test Chart (v1.31.4, default)
  • GitHub Check: Test Chart (v1.32.1, default)
🔇 Additional comments (2)
charts/operator-wandb/charts/otel/charts/agent/templates/deamonset.yaml (2)

39-42: Great security enhancement!

Adding pod-level security context with runAsNonRoot and RuntimeDefault seccomp profile is a solid security improvement that aligns with Kubernetes best practices.


115-117:

❓ Verification inconclusive

Verify OpenTelemetry collector's access to container logs.

While the change to use /var/lib/containers is appropriate, please verify that the OpenTelemetry collector can still access all required container logs with this path when using emptyDir volumes.


🌐 Web query:

What paths does OpenTelemetry collector use to access container logs in Kubernetes?

💡 Result:

The OpenTelemetry Collector primarily accesses Kubernetes container logs through these paths:

Standard Kubernetes Log Paths

  • Primary path:
    /var/log/pods/*/*/*.log
    This captures logs from all pods and containers in the cluster[1][4][5][7][8]

  • Docker container path:
    /var/lib/docker/containers/*/*-json.log
    Used when working with Docker runtime[8]

Key Configuration Details

  • Path mounting requires these hostPath volumes in the Collector DaemonSet:

    volumes:
      - name: varlogpods
        hostPath:
          path: /var/log/pods
      - name: varlibdockercontainers 
        hostPath:
          path: /var/lib/docker/containers

    These are mounted to the Collector container[8]

  • Exclusion example (for Collector's own logs):

    exclude:
      - /var/log/pods/*/otel-collector/*.log
    ```[8]
    

Container Runtime Considerations

The Collector handles different log formats through operators that automatically detect:

  • CRI-O format
  • Containerd format
  • Docker JSON format[7][9]

This path structure works across container runtimes (Docker, containerd, CRI-O) due to Kubernetes' standardized logging pattern where:

  1. Each pod gets a directory under /var/log/pods
  2. Each container restart creates a new log file with incremental numbering[1][4][8]

Citations:


Confirm OpenTelemetry Collector Log Access

The updated configuration mounts /var/lib/containers as readOnly, replacing the previous hostPath mounts (hostfs and /var/lib/docker/containers). Since the OpenTelemetry Collector typically accesses logs via /var/log/pods and /var/lib/docker/containers, please ensure that the collector’s configuration is updated accordingly or that your environment (e.g., using containerd/CRI-O) supports log access via /var/lib/containers when emptyDir volumes are used.

  • Verify the collector configuration matches the new volume mount path.
  • Ensure that the new mount does not hinder access to Docker container logs, should they be required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace hostPath volumes with ephemeral volumes (emptydir, pvc or other)
1 participant