이 제품은 선택한 Datadog 사이트에서 지원되지 않습니다. ().
이 페이지는 아직 한국어로 제공되지 않습니다. 번역 작업 중입니다.
현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우 언제든지 연락주시기 바랍니다.

Metadata

Id: dockerfile-shell-running-a-pipe-without-pipefail-flag

Platform: Dockerfile

Severity: Low

Category: Insecure Defaults

Learn More

Description

Pipeline commands executed by POSIX shells must enable the pipefail option so that a failure in any stage of a pipeline makes the whole command fail. Without pipefail, earlier command failures can be masked and CI/build steps or image contents may be left in an inconsistent or insecure state.

This check targets Dockerfile-style instructions: RUN commands that invoke a shell (bash, zsh, ash, /bin/bash, /bin/zsh, /bin/ash) and contain a pipe character (|) must have pipefail enabled either via a preceding SHELL instruction that includes -o pipefail or by enabling it in the RUN command itself. Resources will be flagged when a RUN with a pipeline is present and there is no prior SHELL instruction with -o pipefail and the RUN does not explicitly enable pipefail. PowerShell-style commands are excluded. Fixes include setting a global shell with pipefail or prefixing pipeline commands with set -o pipefail (see examples below).

Secure configuration with a global SHELL in a Dockerfile:

SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN command1 | command2

Secure inline option for a single RUN:

RUN set -o pipefail; command1 | command2

Compliant Code Examples

FROM node:12
RUN pwsh SOME_CMD | SOME_OTHER_CMD
SHELL [ "zsh", "-o","pipefail" ]
RUN zsh ./some_output | ./some_script
SHELL [ "/bin/bash", "-o","pipefail" ]
RUN [ "/bin/bash", "./some_output", "./some_script" ]

Non-Compliant Code Examples

FROM node:12
RUN zsh ./some_output | ./some_script
RUN [ "/bin/bash", "./some_output", "|", "./some_script" ]