-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(misconf): handle heredocs in dockerfile instructions #8284
Conversation
Signed-off-by: nikpivkin <[email protected]>
name: "with a shebang", | ||
src: `RUN <<EOF | ||
#!/usr/bin/env python | ||
print("hello world") | ||
EOF`, | ||
expected: "/dev/pipes/EOF", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read your description for the case when it starts with a shebang, but I don't understand this test case. Why is the expected value the one it is?
// if heredoc contains shebang, docker creates a file with the contents and runs it | ||
if strings.HasPrefix(node.Heredocs[0].Content, "#!") { | ||
return "/dev/pipes/" + node.Heredocs[0].Name | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the test case expectation now but what's the reasoning behind this logic? I'm a little paranoid about processing shebangs, should we just leave them out for our implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The processing of heredoc is taken from https://github.com/moby/buildkit/blob/9a39e2c112b7c98353c27e64602bc08f31fe356e/frontend/dockerfile/dockerfile2llb/convert.go#L1200 . Maybe we really shouldn't handle this case? Should we only extract commands from heredoc, since we work with them in checks, and otherwise export it as it is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree.
Signed-off-by: nikpivkin <[email protected]>
Description
Heredocs allow redirection of subsequent Dockerfile lines to the input of RUN or COPY commands. Right now, Trivy does not handle heredocs in instructions and only exports the first line as an instruction value:
The following scenarios are taken into account:
Example Dockerfile:
Output:
Trace:
Related issues
Checklist