Skip to content
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(query): dockerfile unpinned_package_version_in_pip_install #6637

Merged
merged 7 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package Cx

import data.generic.dockerfile as dockerLib

flags = ["-r", "-c"]

CxPolicy[result] {
resource := input.document[i].command[name][_]
resource.Cmd == "run"
Expand All @@ -13,10 +15,13 @@ CxPolicy[result] {
yum != null

packages = dockerLib.getPackages(commands, yum)
length := count(packages)
refactorPackages = [ x | x := packages[_]; x != ""]
length := count(refactorPackages)

count({x | x := refactorPackages[_]; x == flags[_]}) == 0

some j
analyzePackages(j, packages[j], packages, length)
analyzePackages(j, refactorPackages[j], packages, length)

result := {
"documentId": input.document[i].id,
Expand Down Expand Up @@ -57,7 +62,7 @@ isPip(command) {
contains(command[j], "install")
}

analyzePackages(j, currentPackage, packages, length) {
analyzePackages(j, currentPackage, _, length) {
j == length - 1
regex.match("^[a-zA-Z]", currentPackage) == true
not dockerLib.withVersion(currentPackage)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM alpine:3.4
RUN apk add --update py-pip=7.1.2-r0
RUN pip3 install -r pip_requirements.txt
COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt
COPY app.py /usr/src/app/
COPY templates/index.html /usr/src/app/templates/
EXPOSE 5000
CMD ["python", "/usr/src/app/app.py"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM alpine:3.4
RUN apk add --update py-pip=7.1.2-r0
RUN pip3 install -c constraints.txt
COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt
COPY app.py /usr/src/app/
COPY templates/index.html /usr/src/app/templates/
EXPOSE 5000
CMD ["python", "/usr/src/app/app.py"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
{
"queryName": "Unpinned Package Version in Pip Install",
"severity": "MEDIUM",
"line": 3
"line": 3,
"filename": "positive1.dockerfile"
},
{
"queryName": "Unpinned Package Version in Pip Install",
"severity": "MEDIUM",
"line": 4
"line": 4,
"filename": "positive1.dockerfile"
},
{
"queryName": "Unpinned Package Version in Pip Install",
"severity": "MEDIUM",
"line": 15
"line": 15,
"filename": "positive1.dockerfile"
},
{
"queryName": "Unpinned Package Version in Pip Install",
"severity": "MEDIUM",
"line": 18
"line": 18,
"filename": "positive1.dockerfile"
}
]
Loading