Skip to content
SP StackPractices
intermediate By StackPractices

Container Security Baseline Template

A baseline template for hardening container images, runtimes, and orchestration configurations across environments.

Note: This guide follows English-language naming conventions and terminology standards common in international development teams. Examples use English identifiers and comments to maximize compatibility across codebases and tooling.

Overview

A Container Security Baseline defines the minimum security configuration required for every container image, runtime, and orchestration environment. It covers image provenance, vulnerability scanning, runtime restrictions, access control, and network policies. This baseline helps teams ship containers that meet security and compliance requirements without blocking delivery.

When to Use

  • Setting up a new container platform or Kubernetes cluster.
  • Onboarding a new service or development team.
  • Preparing for a security audit or compliance review.
  • Responding to a container escape or image compromise.
  • Standardizing security controls across CI/CD and production.

Prerequisites

  • A container registry with access control and audit logging.
  • A vulnerability scanner integrated with CI/CD or registry.
  • A Kubernetes cluster with NetworkPolicy and RBAC enabled.
  • Ownership from platform, security, and development teams.

Solution

Template

1. Image Build Requirements

RequirementBaselineVerification
Base imageUse minimal, vendor-supported, or distroless imagesScan registry tags
Image sizeRemove dev tools and package managersBuild inspect
VulnerabilitiesNo critical or high CVEs in production imagesScanner gate in CI
SecretsNo credentials embedded in image layersSecret scanning
ProvenanceBuild signed with SBOM attachedSigstore / cosign
UpdatesImages rebuilt at least monthlyCI cron job

2. Runtime Security Baseline

ControlBaselineEnforcement
Non-root userContainers run as user with UID > 10000Pod security policy
Read-only root filesystemRoot filesystem is read-onlySecurity context
No privileged modePrivileged flag is not allowedAdmission controller
Resource limitsCPU and memory limits set per podResourceQuota / LimitRange
Seccomp profileRuntime default or custom profileSecurity context
AppArmor / SELinuxEnforcing profile appliedNode configuration
CapabilitiesOnly required capabilities added; default set droppedSecurity context

3. Orchestration Baseline

AreaBaselineTool / Resource
RBACLeast-privilege roles per namespaceKubernetes RBAC
Network policyDefault-deny and explicitly allow flowsNetworkPolicy
Admission controlPolicy engine rejects non-compliant podsOPA / Kyverno
SecretsSecrets stored in external vault or KMSVault / External Secrets
Audit loggingAPI server and container audit logs enabledKubernetes audit
Node isolationSensitive workloads on dedicated node poolsTaints / tolerations

4. Deployment Checklist

  • Image scanned with no critical or high vulnerabilities.
  • SBOM generated and signed at build time.
  • Container runs as non-root with read-only root filesystem.
  • Privileged mode and host namespaces are disabled.
  • CPU and memory limits configured.
  • Security context with dropped capabilities and seccomp profile.
  • Network policy restricts ingress and egress.
  • Secrets are mounted from external vault, not environment variables.
  • RBAC role is least-privilege and scoped to namespace.
  • Pod security admission policy enforced.

5. Exception and Risk Acceptance

Exception IDDescriptionRiskApproved ByExpirationCompensating Control
CS-001Legacy image needs package managerMediumPlatform lead2026-09-30Scanner runs weekly
CS-002Sidecar requires privileged modeHighCISO2026-08-15Dedicated node pool

Explanation

Containers share the host kernel, so a misconfigured container can compromise the entire node. The baseline layers controls: image security prevents shipping vulnerable code, runtime hardening limits what a container can do, and orchestration policies enforce these rules at scale. Together they reduce attack surface and simplify compliance.

Variants

  • Docker-only baseline: Simpler template for teams running Docker without Kubernetes.
  • Kubernetes hardening checklist: Focused on pod security, admission, and RBAC.
  • Serverless container baseline: For platforms like AWS Fargate or Google Cloud Run.
  • High-compliance baseline: Adds requirements for FIPS, FedRAMP, or PCI-DSS environments.
  • Developer laptop baseline: Hardening for Docker Desktop and local container builds.

Best Practices

  • Make the baseline mandatory via CI/CD gates and admission controllers.
  • Use distroless or scratch-based images when possible.
  • Scan images continuously, not just at build time.
  • Rotate registry credentials and signing keys regularly.
  • Monitor runtime behavior with container security tools.
  • Keep admission policies version-controlled and reviewed.
  • Document exceptions and require expiration dates.

Common Mistakes

  • Running containers as root by default.
  • Embedding secrets in Docker layers or environment variables.
  • Pulling images from unverified public registries.
  • Skipping vulnerability scanning for transitive dependencies.
  • Allowing all egress traffic from pods.
  • Not isolating production and staging workloads.
  • Relying only on image scanning without runtime controls.

FAQs

What is the difference between an image scanner and a runtime security tool?

An image scanner finds known vulnerabilities in static image layers. A runtime security tool detects suspicious behavior while the container runs, such as unexpected process execution or network connections.

Should we use a privileged init container?

Avoid privileged containers. If a one-time setup task requires elevated privileges, use a dedicated job with restricted RBAC, audit logging, and approval from the security team.

How do we enforce the baseline automatically?

Use CI/CD gates for image scanning and admission controllers like Kyverno or OPA Gatekeeper in Kubernetes. Pod Security Admission can also enforce common security contexts.