Skip to content

Commit

Permalink
Merge pull request #60 from candrews/ds005-file-multi-in
Browse files Browse the repository at this point in the history
fix(checks): handle `file:` and `multi:` in AVD-DS-005
  • Loading branch information
simar7 authored Feb 7, 2024
2 parents 43c0ea6 + be21df0 commit ecc1ecd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions checks/docker/add_instead_of_copy.rego
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,22 @@ get_add[output] {
args := concat(" ", add.Value)

not contains(args, ".tar")

not is_command_with_hash(add.Value, "file:")
not is_command_with_hash(add.Value, "multi:")

output := {
"args": args,
"cmd": add,
}
}

is_command_with_hash(cmd, prefix) {
count(cmd) == 3
startswith(cmd[0], prefix)
cmd[1] == "in"
}

deny[res] {
output := get_add[_]
msg := sprintf("Consider using 'COPY %s' command instead of 'ADD %s'", [output.args, output.args])
Expand Down
18 changes: 18 additions & 0 deletions checks/docker/add_instead_of_copy_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ test_copy_allowed {
count(r) == 0
}

test_add_file_colon_in_allowed {
r := deny with input as {"Stages": [{
"Name": "alpine:3.13",
"Commands": [{"Cmd": "add", "Value": ["file:8b8864b3e02a33a579dc216fd51b28a6047bc8eeaa03045b258980fe0cf7fcb3", "in", "/xyz"]}],
}]}

count(r) == 0
}

test_add_multi_colon_in_allowed {
r := deny with input as {"Stages": [{
"Name": "alpine:3.13",
"Commands": [{"Cmd": "add", "Value": ["multi:8b8864b3e02a33a579dc216fd51b28a6047bc8eeaa03045b258980fe0cf7fcb3", "in", "/xyz"]}],
}]}

count(r) == 0
}

test_add_tar_allowed {
r := deny with input as {"Stages": [{
"Name": "alpine:3.13",
Expand Down

0 comments on commit ecc1ecd

Please sign in to comment.