Skip to content

Add container run wrapper script#104

Open
narmaku wants to merge 1 commit intomainfrom
add-container-run-wrapper
Open

Add container run wrapper script#104
narmaku wants to merge 1 commit intomainfrom
add-container-run-wrapper

Conversation

@narmaku
Copy link
Copy Markdown
Contributor

@narmaku narmaku commented Dec 15, 2025

It can be used for easy integration with AI agents.
It is also useful for local execution or testing purposes.

Summary by CodeRabbit

  • Chores
    • Introduced a containerized deployment wrapper script that simplifies executing the service within Podman containers. The script automatically manages SSH key mounting, container image configuration, log directory initialization, and environment variable passthrough, enabling consistent and reproducible deployments with sensible configuration defaults across different runtime environments.

✏️ Tip: You can customize this high-level summary in your review settings.

It can be used for easy integration with AI agents.
It is also useful for local execution or testing purposes.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 15, 2025

📝 Walkthrough

Walkthrough

Introduces a new shell wrapper script that orchestrates running linux-mcp-server inside a Podman container. The script configures defaults for SSH keys, container image, and logs directory, creates necessary directories, constructs a Podman command with volume mounts and environment variable passthrough, then executes the container.

Changes

Cohort / File(s) Summary
Container wrapper script
scripts/linux-mcp-container.sh
New shell script that wraps linux-mcp-server execution in a Podman container with SSH key mounting, logs directory setup, and LINUX_MCP_* environment variable passthrough

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Security considerations: Review shell variable expansion and quoting around SSH key paths, environment variables, and Podman argument construction to prevent injection attacks
  • Race condition: Check if directory creation (mkdir -p for logs) handles concurrent invocations safely
  • Error handling: Verify the script validates that SSH key path exists and handles Podman command failures appropriately

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main change: introducing a new container run wrapper script for executing linux-mcp-server in Podman.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-container-run-wrapper

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 93.54% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@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: 3

🧹 Nitpick comments (1)
scripts/linux-mcp-container.sh (1)

46-48: Consider wildcard passthrough for all LINUX_MCP_* environment variables.

Currently, only three specific LINUX_MCP_* variables are passed through (USER, KEY_PASSPHRASE, LOG_LEVEL). If future configuration options are added to the server, they will be silently ignored unless the script is updated. Consider a more flexible approach.

Instead of selectively passing through env vars, iterate over all LINUX_MCP_* prefixed variables:

-# Pass through all linux-mcp-server environment variables
-[[ -n "$LINUX_MCP_USER" ]] && PODMAN_ARGS+=(-e "LINUX_MCP_USER=$LINUX_MCP_USER")
-[[ -n "$LINUX_MCP_KEY_PASSPHRASE" ]] && PODMAN_ARGS+=(-e "LINUX_MCP_KEY_PASSPHRASE=$LINUX_MCP_KEY_PASSPHRASE")
-[[ -n "$LINUX_MCP_LOG_LEVEL" ]] && PODMAN_ARGS+=(-e "LINUX_MCP_LOG_LEVEL=$LINUX_MCP_LOG_LEVEL")
+# Pass through all LINUX_MCP_* environment variables
+while IFS='=' read -r name value; do
+  if [[ "$name" =~ ^LINUX_MCP_ ]]; then
+    PODMAN_ARGS+=(-e "$name=$value")
+  fi
+done < <(compgen -e)
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb8888d and c9aa96e.

📒 Files selected for processing (1)
  • scripts/linux-mcp-container.sh (1 hunks)

set -e

# Defaults
SSH_KEY="${LINUX_MCP_SSH_KEY_PATH:-$HOME/.ssh/id_rsa}"
Copy link
Copy Markdown

@coderabbitai coderabbitai bot Dec 15, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Validate SSH key existence before mounting.

The script defaults to $HOME/.ssh/id_rsa but never checks if it exists. Podman's mount error will be cryptic and may not make the root cause obvious to users. Adding a simple existence check improves debuggability.

Apply this diff to validate the SSH key before attempting to mount:

 # Ensure logs directory exists
 mkdir -p "$LOGS_DIR"
+
+# Validate SSH key exists
+if [[ ! -f "$SSH_KEY" ]]; then
+  echo "Error: SSH key not found at $SSH_KEY" >&2
+  exit 1
+fi

Also applies to: 41-41

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with this comment. Adding a check for the SSH key is a good idea.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@subpop, thank you for confirming! The SSH key validation will help users quickly identify configuration issues before the container attempts to start, making the error messages much clearer. Let me know if you need any clarification on the implementation.


🧠 Learnings used
Learnt from: CR
Repo: rhel-lightspeed/linux-mcp-server PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T22:00:25.960Z
Learning: Applies to src/linux_mcp_server/tools/*.py : Use `mcp.tool()`, `log_tool_call`, and `disallow_local_execution_in_containers` decorators when creating tools

LOGS_DIR="$HOME/.local/share/linux-mcp-server/logs"

# Ensure logs directory exists
mkdir -p "$LOGS_DIR"
Copy link
Copy Markdown

@coderabbitai coderabbitai bot Dec 15, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Logs directory permissions may restrict container write access.

The mkdir -p "$LOGS_DIR" command creates the directory with the current user's umask. If the container runs as UID 1001 (as configured), it may lack write permissions to a directory created by a different user, causing log failures.

Apply this diff to ensure the container user can write to the logs directory:

-# Ensure logs directory exists
-mkdir -p "$LOGS_DIR"
+# Ensure logs directory exists and is writable by container user
+mkdir -p "$LOGS_DIR"
+chmod 755 "$LOGS_DIR"

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In scripts/linux-mcp-container.sh around line 35, the mkdir -p "$LOGS_DIR" call
can create the directory with umask-restricted permissions that prevent the
container running as UID 1001 from writing logs; after creating the directory,
change ownership to the container UID/GID and set permissive write permissions
(for example chown -R 1001:1001 "$LOGS_DIR" and chmod -R 0755 "$LOGS_DIR") so
the container user can write to the logs directory reliably.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a reasonable precaution to take.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@subpop Thank you for acknowledging the concern! Let me know if you need any help implementing the permission changes or have questions about the approach.


🧠 Learnings used
Learnt from: CR
Repo: rhel-lightspeed/linux-mcp-server PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T22:00:25.960Z
Learning: Applies to src/linux_mcp_server/tools/*.py : Use `mcp.tool()`, `log_tool_call`, and `disallow_local_execution_in_containers` decorators when creating tools

# Build podman command
PODMAN_ARGS=(
run --rm -i
--userns "keep-id:uid=1001,gid=0"
Copy link
Copy Markdown

@coderabbitai coderabbitai bot Dec 15, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's find and examine the script file
find . -name "linux-mcp-container.sh" -type f

Repository: rhel-lightspeed/linux-mcp-server

Length of output: 108


🏁 Script executed:

# List the repo structure to understand the project layout
git ls-files | head -30

Repository: rhel-lightspeed/linux-mcp-server

Length of output: 768


🏁 Script executed:

# Search for Dockerfile or podman-related files
fd -e Dockerfile -e containerfile -o -name "*container*" -o -name "*podman*" 2>/dev/null | head -20

Repository: rhel-lightspeed/linux-mcp-server

Length of output: 58


🏁 Script executed:

# Examine the main script
cat -n ./scripts/linux-mcp-container.sh

Repository: rhel-lightspeed/linux-mcp-server

Length of output: 2078


🏁 Script executed:

# Check the main Containerfile
cat -n Containerfile | head -80

Repository: rhel-lightspeed/linux-mcp-server

Length of output: 3188


🏁 Script executed:

# Check the devcontainer Containerfile
cat -n .devcontainer/Containerfile

Repository: rhel-lightspeed/linux-mcp-server

Length of output: 697


🏁 Script executed:

# Get more of the Containerfile to see user setup
cat -n Containerfile | tail -40

Repository: rhel-lightspeed/linux-mcp-server

Length of output: 1557


🏁 Script executed:

# Search for useradd or RUN commands that set up the mcp user
rg "useradd|groupadd|chown" Containerfile -A 2 -B 2

Repository: rhel-lightspeed/linux-mcp-server

Length of output: 225


🏁 Script executed:

# Look for any documentation about container setup or user requirements
cat -n README.md | head -100

Repository: rhel-lightspeed/linux-mcp-server

Length of output: 4156


Consider making UID/GID configurable to match Containerfile's flexibility.

The hard-coded uid=1001,gid=0 matches the default ARG UID=1001 in the Containerfile and is documented in the README. However, the Containerfile allows UID to be overridden at build time. If someone rebuilds the image with a different UID, the script will silently fail with permission errors. Make these configurable via environment variables (e.g., MCP_UID and MCP_GID) with sensible defaults and document in script comments.

🤖 Prompt for AI Agents
In scripts/linux-mcp-container.sh around line 40, the --userns option hardcodes
uid=1001,gid=0 which can mismatch a rebuilt image; make UID/GID configurable by
reading MCP_UID and MCP_GID environment variables (defaults MCP_UID=1001 and
MCP_GID=0), validate or fallback to the defaults if empty/non-numeric, and
substitute those variables into the --userns argument; add a short comment above
explaining the env vars and defaults so the behavior is documented.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure this is necessary. I doubt many people will rebuild the container image using a different UID.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@subpop, that's a fair point. If rebuilding with a custom UID is an edge case for your users, the current hardcoded approach keeps things simpler. The defaults match the Containerfile and should work for the typical deployment scenario. I'm good with keeping it as is.


🧠 Learnings used
Learnt from: CR
Repo: rhel-lightspeed/linux-mcp-server PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T22:00:25.960Z
Learning: Applies to src/linux_mcp_server/tools/*.py : Use `mcp.tool()`, `log_tool_call`, and `disallow_local_execution_in_containers` decorators when creating tools

@samdoran samdoran changed the title Add container run wrapper script. Add container run wrapper script Dec 15, 2025
@samdoran
Copy link
Copy Markdown
Member

Rather than an external wrapper script that only works with podman, if this functionality is desired it should be integrated into the program directly. We could add another entry point or subcommand to do this. That would make the interface much better and we could then test the code that is running the container instead of having an external shell script.

@narmaku
Copy link
Copy Markdown
Contributor Author

narmaku commented Dec 16, 2025

Rather than an external wrapper script that only works with podman, if this functionality is desired it should be integrated into the program directly. We could add another entry point or subcommand to do this. That would make the interface much better and we could then test the code that is running the container instead of having an external shell script.

Thanks @samdoran ! That could be much better yes. The only thing is that the container is not part of this upstream project. It is downstream if I am not mistaken. In that case, does it make sense to modify the upstream software to run the server as a container?

@samdoran
Copy link
Copy Markdown
Member

samdoran commented Jan 5, 2026

I think so. The container image is most definitely part of the upstream project.

set -e

# Defaults
SSH_KEY="${LINUX_MCP_SSH_KEY_PATH:-$HOME/.ssh/id_rsa}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with this comment. Adding a check for the SSH key is a good idea.

# Build podman command
PODMAN_ARGS=(
run --rm -i
--userns "keep-id:uid=1001,gid=0"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure this is necessary. I doubt many people will rebuild the container image using a different UID.

LOGS_DIR="$HOME/.local/share/linux-mcp-server/logs"

# Ensure logs directory exists
mkdir -p "$LOGS_DIR"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a reasonable precaution to take.

Copy link
Copy Markdown
Member

@samdoran samdoran left a comment

Choose a reason for hiding this comment

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

I still think this should not be a wrapper script but should be another entry point or subcommand in the Python program itself.

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.

3 participants