Containerization

From RedHatProductSecurity/prodsec-skills · View interactive version

Containerization is an AI agent skill from the GitHub repository RedHatProductSecurity/prodsec-skills. Enforce container security best practices for MCP servers, including OpenShift integration. Use when containerizing MCP servers or reviewing container security configurations for MCP deployments.

How to use this skill

Skill file

Containerization and OpenShift Integration for MCP Servers

Security Recommendation

MCP servers SHOULD run in containers, leveraging container orchestration platform security features (e.g., OpenShift SCCs) for a hardened-by-default posture.

Container Security Requirements

Run as Non-Root

The container MUST run as a non-root user. OpenShift's default Security Context Constraints (SCCs) enforce this automatically.

securityContext:
  runAsNonRoot: true
  runAsUser: 1000

Drop All Capabilities

Remove all Linux capabilities and add back only what is strictly needed:

securityContext:
  capabilities:
    drop: ["ALL"]

Read-Only Root Filesystem

Use a read-only root filesystem. Mount a tmpfs only for directories that require temporary writes:

securityContext:
  readOnlyRootFilesystem: true
volumeMounts:
  - name: tmp
    mountPath: /tmp
volumes:
  - name: tmp
    emptyDir:
      medium: Memory

Kernel Hardening

| Mechanism | Details |

|---|---|

| SELinux | Enabled by default in OpenShift; confines container processes |

| seccomp | Apply seccomp profiles to restrict available system calls |

securityContext:
  seccompProfile:
    type: RuntimeDefault
  seLinuxOptions:
    type: container_t

Network Policies

Use Kubernetes NetworkPolicies as a pod-level firewall to control all ingress and egress traffic:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: mcp-server-policy
spec:
  podSelector:
    matchLabels:
      app: mcp-server
  policyTypes: ["Ingress", "Egress"]
  ingress:
    - from:
        - podSelector:
            matchLabels:
              app: mcp-client
      ports:
        - port: 8080
  egress:
    - to:
        - podSelector:
            matchLabels:
              app: auth-server
      ports:
        - port: 443

Base Image Selection

RUN microdnf upgrade -y && microdnf install -y <required> && microdnf remove -y <unnecessary> && microdnf clean all

Containerfile Linting

Use Hadolint to lint Containerfiles for best-practice violations. Run it in CI but verify findings manually -- do not trust it blindly.

Implementation Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.