Skip to content

Commit

Permalink
Merge pull request #3 from Avanti19/avanti_docker_policies
Browse files Browse the repository at this point in the history
Avanti docker policies for run instruction
  • Loading branch information
Rchanger authored Jul 29, 2021
2 parents 1e9d283 + 3d2fa80 commit 488eeed
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/policies/opa/rego/docker/docker_from/AC_DOCKER_0001.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"resource_type": "from",
"template_args": {
"prefix": "",
"suffix": ""
"suffix": "",
"name": "docFilePlatformFlag"
},
"severity": "MEDIUM",
"description": "Ensure platform flag with FROM command is not used for Docker file",
Expand Down
17 changes: 17 additions & 0 deletions pkg/policies/opa/rego/docker/docker_run/AC_DOCKER_0002.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "runUsingApt",
"file": "runUsingApt.rego",
"policy_type": "docker",
"resource_type": "run",
"template_args": {
"prefix": "",
"suffix": "",
"name": "runUsingApt"
},
"severity": "MEDIUM",
"description": "Ensure apt is not used with RUN command for Docker file",
"reference_id": "AC_DOCKER_0001",
"category": "Infrastructure Security",
"id": "AC_DOCKER_0002",
"version": 1
}
17 changes: 17 additions & 0 deletions pkg/policies/opa/rego/docker/docker_run/AC_DOCKER_0003.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "runUsingDnfUpdate",
"file": "runUsingDnfUpdate.rego",
"policy_type": "docker",
"resource_type": "run",
"template_args": {
"prefix": "",
"suffix": "",
"name": "runUsingDnfUpdate"
},
"severity": "MEDIUM",
"description": "Ensure dnf Update is not used for Docker file",
"reference_id": "AC_DOCKER_0003",
"category": "Infrastructure Security",
"id": "AC_DOCKER_0003",
"version": 1
}
17 changes: 17 additions & 0 deletions pkg/policies/opa/rego/docker/docker_run/AC_DOCKER_0004.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "yumInstallAllowInput",
"file": "yumInstallAllowInput.rego",
"policy_type": "docker",
"resource_type": "run",
"template_args": {
"prefix": "",
"suffix": "",
"name": "yumInstallAllowInput"
},
"severity": "MEDIUM",
"description": "Ensure yum install allow manual input with RUN command for Docker file",
"reference_id": "AC_DOCKER_0004",
"category": "Infrastructure Security",
"id": "AC_DOCKER_0004",
"version": 1
}
17 changes: 17 additions & 0 deletions pkg/policies/opa/rego/docker/docker_run/AC_DOCKER_0005.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "lastUserRoot",
"file": "lastUserRoot.rego",
"policy_type": "docker",
"resource_type": "run",
"template_args": {
"prefix": "",
"suffix": "",
"name": "lastUserRoot"
},
"severity": "MEDIUM",
"description": "Ensure root with RUN command is not used for Docker file",
"reference_id": "AC_DOCKER_0005",
"category": "Infrastructure Security",
"id": "AC_DOCKER_0005",
"version": 1
}
6 changes: 6 additions & 0 deletions pkg/policies/opa/rego/docker/docker_run/lastUserRoot.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package accurics

{{.prefix}}{{.name}}{{.suffix}}[cmd.id]{
cmd := input.user[count(input.user) - 1]
cmd.config == "root"
}
7 changes: 7 additions & 0 deletions pkg/policies/opa/rego/docker/docker_run/runUsingApt.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package accurics

{{.prefix}}{{.name}}{{.suffix}}[cmd.id]{
cmd := input.run[_]
config := cmd.config
contains(config, "apt")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package accurics

{{.prefix}}{{.name}}{{.suffix}}[cmd.id]{
cmd := input.run[_]
config := cmd.config
commands = ["dnf update", "dnf upgrade", "dnf upgrade-minimal"]
contains(config, commands[_])
}
18 changes: 18 additions & 0 deletions pkg/policies/opa/rego/docker/docker_run/yumInstallAllowInput.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package accurics

{{.prefix}}{{.name}}{{.suffix}}[cmd.id]{
cmd := input.run[_]
config := cmd.config
checkYumInstall(config)
not checkManualInput(config)
}

checkYumInstall(config) {
re_match(`yum (-(-)?[a-zA-Z]+ *)*(group|local)?install`, config)
}

checkManualInput(config) {
commands := ["-y", "yes", "--assumeyes"]
checkCmd := commands[_]
contains(config, checkCmd)
}

0 comments on commit 488eeed

Please sign in to comment.