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(checks): handle file: and multi: in AVD-DS-0011 #56

Merged
merged 1 commit into from
Feb 7, 2024
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 @@ -25,6 +25,9 @@ get_copy_arg[output] {
cnt := count(copy.Value)
cnt > 2

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

arg := copy.Value[cnt - 1]
not endswith(arg, "/")
output := {
Expand All @@ -33,6 +36,12 @@ get_copy_arg[output] {
}
}

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

deny[res] {
output := get_copy_arg[_]
msg := sprintf("Slash is expected at the end of COPY command argument '%s'", [output.arg])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,36 @@ test_two_args_allowed {
count(r) == 0
}

test_three_args_with_file_colon_in_allowed {
r := deny with input as {"Stages": [{"Name": "alpine:3.3", "Commands": [
{
"Cmd": "from",
"Value": ["node:carbon2"],
},
{
"Cmd": "copy",
"Value": ["file:8b8864b3e02a33a579dc216fd51b28a6047bc8eeaa03045b258980fe0cf7fcb3", "in", "myfile"],
},
]}]}

count(r) == 0
}

test_three_args_with_multi_colon_in_allowed {
r := deny with input as {"Stages": [{"Name": "alpine:3.3", "Commands": [
{
"Cmd": "from",
"Value": ["node:carbon2"],
},
{
"Cmd": "copy",
"Value": ["multi:8b8864b3e02a33a579dc216fd51b28a6047bc8eeaa03045b258980fe0cf7fcb3", "in", "myfile"],
},
]}]}

count(r) == 0
}

test_three_arg_allowed {
r := deny with input as {"Stages": [{"Name": "alpine:3.3", "Commands": [
{
Expand Down