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

add check if there is actually a package manager in the run command #1385

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 8 additions & 8 deletions rules/docker/policies/update_instruction_alone.rego
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ deny[res] {

command = concat(" ", run.Value)

is_package_manager(command)
is_valid_update(command)
not update_followed_by_install(command)

msg := "The instruction 'RUN <package-manager> update' should always be followed by '<package-manager> install' in the same RUN statement."
res := result.new(msg, run)
}

is_valid_update(command) {
chained_parts := regex.split(`\s*&&\s*`, command)

array_split := split(chained_parts[_], " ")

len = count(array_split)
package_manager_regex := `(apk)|(apt-get)|(yum)`

update := {"update", "--update"}
is_package_manager(command) {
regex.match(package_manager_regex, command)
}

array_split[len - 1] == update[_]
update_regex := `( update)|( check-update)`
is_valid_update(command) {
regex.match(update_regex, command)
}

update_followed_by_install(command) {
Expand Down
8 changes: 6 additions & 2 deletions rules/docker/policies/update_instruction_alone_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,20 @@ test_allowed {
},
{
"Cmd": "run",
"Value": ["apt-get update && apt-get install -y --no-install-recommends mysql-client && rm -rf /var/lib/apt/lists/*"],
"Value": ["apt-get update && apt-get install -y --no-install-recommends mysql-client && rm -rf /var/lib/apt/lists/*"],
},
{
"Cmd": "run",
"Value": ["apk update && apk add --no-cache git ca-certificates"],
"Value": ["apk update && apk add --no-cache git ca-certificates"],
},
{
"Cmd": "run",
"Value": ["apk --update add easy-rsa"],
},
{
"Cmd": "run",
"Value": ["/bin/sh /scripts/someScript.sh update"],
},
{
"Cmd": "entrypoint",
"Value": ["mysql"],
Expand Down