Container lacks no-new-privileges protection

no-new-privileges restricts acquiring additional privileges by executing a new program.

Description

no-new-privileges:true prevents a Linux process from gaining privileges through setuid, setgid or file capabilities when it executes a new program. It keeps the privileges it already has.

Potential impact

Without this restriction, running a privileged executable may give a compromised process access to additional data or resources.

Remediation

Set no-new-privileges:true in the service’s security_opt. Test startup and normal operations, adjusting any step that relies on gaining privileges. Also review privileged, added capabilities and sensitive mounts.

Examples

Use your build context and service.dockerfile when testing the change.

Before

yaml
version: "3.4"
services:
  app:
    build:
      context: ./
      dockerfile: service.dockerfile
    security_opt:
      - no-new-privileges:false

After

yaml
version: "3.4"
services:
  app:
    build:
      context: ./
      dockerfile: service.dockerfile
    security_opt:
      - no-new-privileges:true

References