Skip to content

Docker image runs as root and lacks basic container hardening #1406

Description

@Akalanka1337

Summary

The provided Dockerfile currently runs the container as the root user and does not apply several common container hardening practices.

While this is not necessarily a direct vulnerability on its own, it increases the impact of future vulnerabilities and weakens defense-in-depth for production deployments.

Current Dockerfile

ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION}-slim as base
WORKDIR /magika
RUN pip install magika
ENTRYPOINT ["magika"]

Observed Issues

1. Container runs as root

No USER directive is defined, so the container executes as uid=0.

Example:

docker run --rm magika id
uid=0(root) gid=0(root) groups=0(root)

Running as root increases the blast radius of:

  • future RCE vulnerabilities
  • arbitrary file read/write bugs
  • unsafe mounted-volume access
  • container breakout scenarios when combined with kernel/runtime flaws

2. Package version not pinned

RUN pip install magika

This always installs the latest package version and may reduce build reproducibility.

Pinning versions is generally recommended:

RUN pip install --no-cache-dir magika==1.0.3

3. Missing basic container hardening guidance

The image does not document or encourage:

  • non-root execution
  • resource limits
  • read-only filesystem usage
  • allowPrivilegeEscalation=false
  • Kubernetes runAsNonRoot

These are normally deployment/runtime concerns, but adding guidance would improve operational security.

Suggested Improvement

Example hardened Dockerfile:

ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION}-slim as base

RUN groupadd -r magika && useradd -r -g magika magika

WORKDIR /magika

RUN pip install --no-cache-dir magika==1.0.3

USER magika

ENTRYPOINT ["magika"]

Optional:

  • add HEALTHCHECK
  • document recommended K8s/Docker runtime security settings
  • recommend read-only filesystem usage where possible

Why This Matters

This issue is primarily about reducing attack surface and improving defense-in-depth for users deploying Magika in:

  • CI/CD systems
  • malware analysis pipelines
  • multi-tenant environments
  • Kubernetes clusters
  • automated file processing services

Even if no direct exploit currently exists, non-root execution significantly reduces the impact of future vulnerabilities.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions