Skip to content

Commit

Permalink
Feat(Query): Privileged Containers Enabled for Docker Compose (Checkm…
Browse files Browse the repository at this point in the history
…arx#5029)

* query privileged containers dCompose

* query privileged containers dCompose

* query privileged containers dCompose 2

* query privileged containers dCompose

* validates samples, changed query to match them
  • Loading branch information
cxAndreFelicidade authored Mar 29, 2022
1 parent 492fe36 commit ee1cd11
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "ae5b6871-7f45-42e0-bb4c-ab300c4d2026",
"queryName": "Privileged Containers Enabled",
"severity": "HIGH",
"category": "Resource Management",
"descriptionText": "Privileged containers should be used with extreme caution, they have all of the capabilities that the linux kernel offers for docker.",
"descriptionUrl": "https://docs.docker.com/compose/compose-file/compose-file-v3/#domainname-hostname-ipc-mac_address-privileged-read_only-shm_size-stdin_open-tty-user-working_dir",
"platform": "DockerCompose",
"descriptionID": "029f6145"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Cx

import data.generic.common as common_lib

CxPolicy[result] {
resource := input.document[i]
service_parameters := resource.services[name]
privileged := service_parameters.privileged
privileged == true

result := {
"documentId": sprintf("%s", [resource.id]),
"searchKey": sprintf("services.%s.privileged",[name]),
"issueType": "IncorrectValue",
"keyExpectedValue": "Docker compose file to have 'privileged' attribute set to false or not set",
"keyActualValue": "Docker compose file has 'privileged' attribute as true",
"searchLine": common_lib.build_search_line(["services", name, "privileged"], []),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "3.9"

services:
webapp:
build:
context: ./dir
dockerfile: Dockerfile-alternate
args:
buildno: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3.9"

services:
webapp:
build:
context: ./dir
dockerfile: Dockerfile-alternate
args:
buildno: 1
ports:
- "8080:8080"
- "3000:3000"
privileged: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.9"

services:
webapp:
build:
context: ./dir
dockerfile: Dockerfile-alternate
args:
buildno: 1
privileged: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.9"

services:
webapp:
build:
context: ./dir
dockerfile: Dockerfile-alternate
args:
buildno: 1
ports:
- "8080:8080"
- "3000:3000"
privileged: true
cap_drop:
- all
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"queryName": "Privileged Containers Enabled",
"severity": "HIGH",
"line": 10,
"filename": "positive1.yaml"
},
{
"queryName": "Privileged Containers Enabled",
"severity": "HIGH",
"line": 13,
"filename": "positive2.yaml"
}
]

0 comments on commit ee1cd11

Please sign in to comment.